From 2fb6e75899506e5ec936a436ccd7f62b8e0852b4 Mon Sep 17 00:00:00 2001 From: jriegel Date: Tue, 5 Nov 2013 19:00:42 +0100 Subject: [PATCH 1/4] implementing InputField UseCase in Sketcher EditDatumDialog --- src/App/FeatureTest.cpp | 8 +-- src/App/FeatureTest.h | 4 +- src/Base/Quantity.cpp | 13 ++-- src/Gui/InputField.cpp | 88 +++++++++++++++++++----- src/Gui/InputField.h | 27 ++++++-- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 2 + src/Mod/Sketcher/Gui/InsertDatum.ui | 12 +++- 7 files changed, 118 insertions(+), 36 deletions(-) diff --git a/src/App/FeatureTest.cpp b/src/App/FeatureTest.cpp index c98664685..15392cb5e 100644 --- a/src/App/FeatureTest.cpp +++ b/src/App/FeatureTest.cpp @@ -98,10 +98,10 @@ FeatureTest::FeatureTest() ADD_PROPERTY(QuantityLength,(1.0)); QuantityLength.setUnit(Base::Unit::Length); - ADD_PROPERTY(QuantityMass,(1.0)); - QuantityMass.setUnit(Base::Unit::Mass); - ADD_PROPERTY(QuantityAngle,(1.0)); - QuantityAngle.setUnit(Base::Unit::Angle); + //ADD_PROPERTY(QuantityMass,(1.0)); + //QuantityMass.setUnit(Base::Unit::Mass); + //ADD_PROPERTY(QuantityAngle,(1.0)); + //QuantityAngle.setUnit(Base::Unit::Angle); } diff --git a/src/App/FeatureTest.h b/src/App/FeatureTest.h index 8d4676140..886047c39 100644 --- a/src/App/FeatureTest.h +++ b/src/App/FeatureTest.h @@ -94,8 +94,8 @@ public: App::PropertyInteger TypeTransient; App::PropertyQuantity QuantityLength; - App::PropertyQuantity QuantityMass; - App::PropertyQuantity QuantityAngle; + //App::PropertyQuantity QuantityMass; + //App::PropertyQuantity QuantityAngle; /** @name methods overide Feature */ //@{ diff --git a/src/Base/Quantity.cpp b/src/Base/Quantity.cpp index 4ddf5516d..33d5bdf87 100644 --- a/src/Base/Quantity.cpp +++ b/src/Base/Quantity.cpp @@ -38,6 +38,13 @@ # pragma warning(disable : 4335) // disable MAC file format warning on VC #endif +#ifndef DOUBLE_MAX +# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/ +#endif +#ifndef DOUBLE_MIN +# define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/ +#endif + using namespace Base; Quantity::Quantity() @@ -119,12 +126,6 @@ double Quantity::getUserPrefered(QString &unitString)const Quantity QuantResult; -#ifndef DOUBLE_MAX -# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/ -#endif -#ifndef DOUBLE_MIN -# define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/ -#endif // error func diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index 91e305fa8..93b28925d 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -24,49 +24,101 @@ #include "PreCompiled.h" #include +#include +#include +#include #include "InputField.h" using namespace Gui; +using namespace Base; // -------------------------------------------------------------------- InputField::InputField ( QWidget * parent ) : QLineEdit(parent) { + this->setContextMenuPolicy(Qt::DefaultContextMenu); + + QObject::connect(this, SIGNAL(textEdited (QString)), + this, SLOT(newInput(QString))); } InputField::~InputField() { } +void InputField::contextMenuEvent(QContextMenuEvent *event) +{ + QMenu *menu = createStandardContextMenu(); + QAction *saveAction = menu->addAction(tr("My Menu Item")); + //... + QAction *saveAction2 = menu->exec(event->globalPos()); + delete menu; +} +void InputField::newInput(const QString & text) +{ + Quantity res; + try{ + res = Quantity::parse(text.toAscii()); + }catch(Base::Exception &e){ + ErrorText = e.what(); + this->setToolTip(QString::fromAscii(ErrorText.c_str())); + QPalette *palette = new QPalette(); + palette->setColor(QPalette::Base,QColor(255,200,200)); + setPalette(*palette); + return; + } + QPalette *palette = new QPalette(); + palette->setColor(QPalette::Base,QColor(200,255,200)); + setPalette(*palette); + ErrorText = ""; + this->setToolTip(QString::fromAscii(ErrorText.c_str())); + +} + +void InputField::pushToHistory(std::string value) +{ + if(_handle.isValid()){ + _handle->SetASCII("Hist1",_handle->GetASCII("Hist0","").c_str()); + _handle->SetASCII("Hist0",value.c_str()); + } +} + +std::vector InputField::getHistory(void) +{ + std::vector res; + + if(_handle.isValid()){ + std::string tmp; + tmp = _handle->GetASCII("Hist0",""); + if( tmp != ""){ + res.push_back(tmp); + tmp = _handle->GetASCII("Hist1",""); + if( tmp != ""){ + res.push_back(tmp); + //tmp = _handle->GetASCII("Hist2",""); + } + } + } + return res; +} /** Sets the preference path to \a path. */ void InputField::setParamGrpPath( const QByteArray& path ) { -//#ifdef FC_DEBUG -// if (getWindowParameter().isValid()) -// { -// if ( paramGrpPath() != path ) -// Base::Console().Warning("Widget already attached\n"); -// } -//#endif -// -// if ( paramGrpPath() != path ) -// { -// if ( setGroupName( path ) ) -// { -// m_sPrefGrp = path; -// assert(getWindowParameter().isValid()); -// getWindowParameter()->Attach(this); -// } -// } + + _handle = App::GetApplication().GetParameterGroupByPath( path); + if(_handle.isValid()) + sGroupString = path; + } /** Returns the widget's preferences path. */ QByteArray InputField::paramGrpPath() const { - return m_sPrefGrp; + if(_handle.isValid()) + return sGroupString.c_str(); } diff --git a/src/Gui/InputField.h b/src/Gui/InputField.h index 0e7ee8a4d..d698825a0 100644 --- a/src/Gui/InputField.h +++ b/src/Gui/InputField.h @@ -34,7 +34,10 @@ namespace Gui { /** - * The InputField class. + * The InputField class + * The input field widget handles all around user input of Quantities. Thats + * include parsing and checking input. Providing a context menu for common operations + * and managing default and history values. * \author Jürgen Riegel */ class GuiExport InputField : public QLineEdit @@ -47,15 +50,31 @@ public: InputField ( QWidget * parent = 0 ); virtual ~InputField(); - // PROPERTIES - // getters + /** @name history and default management */ + //@{ + /// the param group path where the widget write and read the dafault values QByteArray paramGrpPath () const; - // setters + /// set the param group path where the widget write and read the dafault values void setParamGrpPath ( const QByteArray& name ); + /// push a new value to the history + void pushToHistory(std::string value); + /// get the history of the field, newest first + std::vector getHistory(void); + //@} + +protected Q_SLOTS: + void newInput(const QString & text); + +protected: + virtual void contextMenuEvent ( QContextMenuEvent * event ); private: QByteArray m_sPrefGrp; + std::string ErrorText; + /// handle to the parameter group for defaults and history + ParameterGrp::handle _handle; + std::string sGroupString; }; diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 31a60bced..dfdfa940e 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -93,6 +93,8 @@ void EditDatumDialog::exec(bool atCursor) Ui::InsertDatum ui_ins_datum; ui_ins_datum.setupUi(&dlg); + ui_ins_datum.lineEdit->setParamGrpPath("User parameter:History/Sketcher/SetDatum"); + double init_val; if (Constr->Type == Sketcher::Angle || ((Constr->Type == Sketcher::DistanceX || Constr->Type == Sketcher::DistanceY) && diff --git a/src/Mod/Sketcher/Gui/InsertDatum.ui b/src/Mod/Sketcher/Gui/InsertDatum.ui index 7ffa41be5..39b96cafe 100644 --- a/src/Mod/Sketcher/Gui/InsertDatum.ui +++ b/src/Mod/Sketcher/Gui/InsertDatum.ui @@ -27,7 +27,7 @@ - + @@ -44,7 +44,15 @@ - + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
+ + buttonBox accepted() From 1f96611b76473b93432e01a96f242df0349ce3ca Mon Sep 17 00:00:00 2001 From: jriegel Date: Thu, 7 Nov 2013 16:16:17 +0100 Subject: [PATCH 2/4] Add UnitsCalculator --- src/Gui/CMakeLists.txt | 5 ++ src/Gui/CommandStd.cpp | 24 ++++++ src/Gui/DlgUnitsCalculator.ui | 117 ++++++++++++++++++++++++++++++ src/Gui/DlgUnitsCalculatorImp.cpp | 69 ++++++++++++++++++ src/Gui/DlgUnitsCalculatorImp.h | 54 ++++++++++++++ src/Gui/Workbench.cpp | 2 +- 6 files changed, 270 insertions(+), 1 deletion(-) create mode 100644 src/Gui/DlgUnitsCalculator.ui create mode 100644 src/Gui/DlgUnitsCalculatorImp.cpp create mode 100644 src/Gui/DlgUnitsCalculatorImp.h diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index b9f19393f..947aa0d95 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -129,6 +129,7 @@ set(Gui_MOC_HDRS DownloadManager.h DlgActionsImp.h DlgActivateWindowImp.h + DlgUnitsCalculatorImp.h DlgCommandsImp.h DlgCustomizeImp.h DlgCustomizeSpaceball.h @@ -219,6 +220,7 @@ SET(Gui_UIC_SRCS DemoMode.ui DlgActions.ui DlgActivateWindow.ui + DlgUnitsCalculator.ui DlgAuthorization.ui DlgChooseIcon.ui DlgCommands.ui @@ -295,6 +297,7 @@ SET(Dialog_CPP_SRCS Clipping.cpp DemoMode.cpp DlgActivateWindowImp.cpp + DlgUnitsCalculatorImp.cpp DlgDisplayPropertiesImp.cpp DlgInputDialogImp.cpp DlgMacroExecuteImp.cpp @@ -323,6 +326,7 @@ SET(Dialog_HPP_SRCS Clipping.h DemoMode.h DlgActivateWindowImp.h + DlgUnitsCalculatorImp.h DlgDisplayPropertiesImp.h DlgInputDialogImp.h DlgMacroExecuteImp.h @@ -354,6 +358,7 @@ SET(Dialog_SRCS Clipping.ui DemoMode.ui DlgActivateWindow.ui + DlgUnitsCalculator.ui DlgAuthorization.ui DlgDisplayProperties.ui DlgInputDialog.ui diff --git a/src/Gui/CommandStd.cpp b/src/Gui/CommandStd.cpp index 5ba4beddd..7a04d1df1 100644 --- a/src/Gui/CommandStd.cpp +++ b/src/Gui/CommandStd.cpp @@ -61,6 +61,7 @@ #include "WorkbenchManager.h" #include "Workbench.h" #include "Selection.h" +#include "DlgUnitsCalculatorImp.h" using Base::Console; using Base::Sequencer; @@ -647,6 +648,28 @@ void StdCmdMeasurementSimple::activated(int iMsg) updateActive(); commitCommand(); } +//=========================================================================== +// Std_UnitsCalculater +//=========================================================================== +DEF_STD_CMD(StdCmdUnitsCalculator); + +StdCmdUnitsCalculator::StdCmdUnitsCalculator() + : Command("Std_UnitsCalculater") +{ + sGroup = QT_TR_NOOP("Tools"); + sMenuText = QT_TR_NOOP("&Units calculator..."); + sToolTipText = QT_TR_NOOP("Start the units calculator"); + sWhatsThis = QT_TR_NOOP("Start the units calculator"); + sStatusTip = QT_TR_NOOP("Start the units calculator"); + //sPixmap = ""; + eType = 0; +} + +void StdCmdUnitsCalculator::activated(int iMsg) +{ + Gui::Dialog::DlgUnitsCalculator *dlg = new Gui::Dialog::DlgUnitsCalculator( getMainWindow() ); + dlg->show(); +} namespace Gui { @@ -673,6 +696,7 @@ void CreateStdCommands(void) rcCmdMgr.addCommand(new StdCmdFreeCADForum()); rcCmdMgr.addCommand(new StdCmdFreeCADFAQ()); rcCmdMgr.addCommand(new StdCmdPythonWebsite()); + rcCmdMgr.addCommand(new StdCmdUnitsCalculator()); //rcCmdMgr.addCommand(new StdCmdMeasurementSimple()); //rcCmdMgr.addCommand(new StdCmdDownloadOnlineHelp()); //rcCmdMgr.addCommand(new StdCmdDescription()); diff --git a/src/Gui/DlgUnitsCalculator.ui b/src/Gui/DlgUnitsCalculator.ui new file mode 100644 index 000000000..723b2a82c --- /dev/null +++ b/src/Gui/DlgUnitsCalculator.ui @@ -0,0 +1,117 @@ + + + DlgUnitCalculator + + + + 0 + 0 + 375 + 139 + + + + Units calculater + + + + + + + + + 100 + 0 + + + + + + + + as: + + + + + + + + 100 + 0 + + + + + + + + => + + + + + + + + 100 + 0 + + + + true + + + + + + + + + true + + + + + + + + + Help + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Copy + + + + + + + Close + + + + + + + + + + diff --git a/src/Gui/DlgUnitsCalculatorImp.cpp b/src/Gui/DlgUnitsCalculatorImp.cpp new file mode 100644 index 000000000..d6f892ae3 --- /dev/null +++ b/src/Gui/DlgUnitsCalculatorImp.cpp @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (c) 2013 Jürgen Riegel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +#endif + +#include "DlgUnitsCalculatorImp.h" + +using namespace Gui::Dialog; + +/* TRANSLATOR Gui::Dialog::DlgUnitsCalculator */ + +/** + * Constructs a DlgUnitsCalculator which is a child of 'parent', with the + * name 'name' and widget flags set to 'f' + * + * The dialog will by default be modeless, unless you set 'modal' to + * TRUE to construct a modal dialog. + */ +DlgUnitsCalculator::DlgUnitsCalculator( QWidget* parent, Qt::WFlags fl ) + : QDialog( parent, fl ) +{ + // create widgets + setupUi(this); + +} + +/** Destroys the object and frees any allocated resources */ +DlgUnitsCalculator::~DlgUnitsCalculator() +{ +} + + +void DlgUnitsCalculator::accept() +{ + + QDialog::accept(); + delete this; +} + +void DlgUnitsCalculator::reject() +{ + + QDialog::reject(); + delete this; +} + +#include "moc_DlgUnitsCalculatorImp.cpp" diff --git a/src/Gui/DlgUnitsCalculatorImp.h b/src/Gui/DlgUnitsCalculatorImp.h new file mode 100644 index 000000000..e74309af2 --- /dev/null +++ b/src/Gui/DlgUnitsCalculatorImp.h @@ -0,0 +1,54 @@ +/*************************************************************************** + * Copyright (c) 2013 Jürgen Riegel * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef GUI_DIALOG_DlgActivateWindowImp_H +#define GUI_DIALOG_DlgActivateWindowImp_H + +#include "ui_DlgUnitsCalculator.h" + +namespace Gui { +namespace Dialog { + +/** + * The DlgUnitsCalculator class provides a dialog to activate the MDI window + * of the main window you wish. Since there could be a lot of MDI windows in + * an application you cannot put all of them into the "Windows" popup menu. + * \author Werner Mayer + */ +class DlgUnitsCalculator : public QDialog, public Ui_DlgUnitCalculator +{ + Q_OBJECT + +public: + DlgUnitsCalculator( QWidget* parent = 0, Qt::WFlags fl = 0 ); + ~DlgUnitsCalculator(); + +protected: + void accept(); + void reject(); +}; + +} // namespace Dialog +} // namespace Gui + +#endif // GUI_DIALOG_DlgActivateWindowImp_H diff --git a/src/Gui/Workbench.cpp b/src/Gui/Workbench.cpp index 13ee7d523..8a40656cb 100644 --- a/src/Gui/Workbench.cpp +++ b/src/Gui/Workbench.cpp @@ -492,7 +492,7 @@ MenuItem* StdWorkbench::setupMenuBar() const *tool << "Std_DlgParameter" << "Separator" << "Std_ViewScreenShot" << "Std_SceneInspector" << "Std_ExportGraphviz" << "Std_ProjectUtil" - << "Std_DemoMode" << "Separator" << "Std_DlgCustomize"; + << "Std_DemoMode" << "Std_UnitsCalculater" << "Separator" << "Std_DlgCustomize"; // Macro MenuItem* macro = new MenuItem( menuBar ); From 3d6743a13b901eadf823d2b25188b5910881e9ed Mon Sep 17 00:00:00 2001 From: jriegel Date: Sat, 9 Nov 2013 07:34:56 +0100 Subject: [PATCH 3/4] implementing UnitsCalculator and disable changes in Sketcher --- src/Base/Quantity.cpp | 29 ++++++++++++ src/Base/Quantity.h | 10 ++++ src/Gui/DlgUnitsCalculator.ui | 19 +++++--- src/Gui/DlgUnitsCalculatorImp.cpp | 41 +++++++++++++++++ src/Gui/DlgUnitsCalculatorImp.h | 18 ++++++-- src/Gui/InputField.cpp | 58 +++++++++++++++++++++++- src/Gui/InputField.h | 57 ++++++++++++++++++++++- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 2 +- src/Mod/Sketcher/Gui/InsertDatum.ui | 2 +- 9 files changed, 221 insertions(+), 15 deletions(-) diff --git a/src/Base/Quantity.cpp b/src/Base/Quantity.cpp index 33d5bdf87..315e2c515 100644 --- a/src/Base/Quantity.cpp +++ b/src/Base/Quantity.cpp @@ -120,6 +120,35 @@ double Quantity::getUserPrefered(QString &unitString)const return Base::UnitsApi::schemaPrefUnit(_Unit,unitString).getValue() * _Value; } +std::string Quantity::getUserString(void)const +{ + std::stringstream sstream; + sstream << _Value << _Unit.getString(); + //TODO: implementing + return sstream.str(); +} + +/// true if it has a number without a unit +bool Quantity::isDimensionless(void)const +{ + return _Value != DOUBLE_MIN && _Unit.isEmpty(); +} +// true if it has a number and a valid unit +bool Quantity::isQuantity(void)const +{ + return _Value != DOUBLE_MIN && !_Unit.isEmpty(); +} +// true if it has a number with or without a unit +bool Quantity::isValid(void)const +{ + return _Value != DOUBLE_MIN ; +} + +void Quantity::setInvalid(void) +{ + _Value = DOUBLE_MIN ; +} + // === Parser & Scanner stuff =============================================== // include the Scanner and the Parser for the Quantitys diff --git a/src/Base/Quantity.h b/src/Base/Quantity.h index 724357a4d..c64d2f74b 100644 --- a/src/Base/Quantity.h +++ b/src/Base/Quantity.h @@ -66,6 +66,16 @@ public: double getValue(void) const{return _Value;} void setValue(double val){_Value = val;} + /// true if it has a number without a unit + bool isDimensionless(void)const; + /// true if it has a number and a valid unit + bool isQuantity(void)const; + /// true if it has a number with or without a unit + bool isValid(void)const; + /// sets the quantity invalid + void setInvalid(void); + + protected: double _Value; Unit _Unit; diff --git a/src/Gui/DlgUnitsCalculator.ui b/src/Gui/DlgUnitsCalculator.ui index 723b2a82c..68c87598b 100644 --- a/src/Gui/DlgUnitsCalculator.ui +++ b/src/Gui/DlgUnitsCalculator.ui @@ -17,7 +17,7 @@ - + 100 @@ -34,7 +34,7 @@ - + 100 @@ -51,7 +51,7 @@ - + 100 @@ -75,7 +75,7 @@ - + Help @@ -95,14 +95,14 @@ - + Copy - + Close @@ -112,6 +112,13 @@ + + + Gui::InputField + QLineEdit +
Gui/InputField.h
+
+
diff --git a/src/Gui/DlgUnitsCalculatorImp.cpp b/src/Gui/DlgUnitsCalculatorImp.cpp index d6f892ae3..544b04108 100644 --- a/src/Gui/DlgUnitsCalculatorImp.cpp +++ b/src/Gui/DlgUnitsCalculatorImp.cpp @@ -44,6 +44,14 @@ DlgUnitsCalculator::DlgUnitsCalculator( QWidget* parent, Qt::WFlags fl ) // create widgets setupUi(this); + connect(this->ValueInput, SIGNAL(valueChanged(Base::Quantity)), this, SLOT(valueChanged(Base::Quantity))); + connect(this->UnitInput, SIGNAL(valueChanged(Base::Quantity)), this, SLOT(unitValueChanged(Base::Quantity))); + + connect(this->pushButton_Help, SIGNAL(pressed()), this, SLOT(help())); + connect(this->pushButton_Close, SIGNAL(pressed()), this, SLOT(accept())); + connect(this->pushButton_Copy, SIGNAL(pressed()), this, SLOT(copy())); + + actUnit.setInvalid(); } /** Destroys the object and frees any allocated resources */ @@ -66,4 +74,37 @@ void DlgUnitsCalculator::reject() delete this; } +void DlgUnitsCalculator::unitValueChanged(const Base::Quantity& unit) +{ + actUnit = unit; + valueChanged(actValue); +} + +void DlgUnitsCalculator::valueChanged(const Base::Quantity& quant) +{ + if(actUnit.isValid()){ + this->ValueOutput->setValue(Base::Quantity(quant.getValue()/actUnit.getValue(),actUnit.getUnit())); + }else{ + this->ValueOutput->setValue(quant); + } + actValue = quant; + +} + +void DlgUnitsCalculator::copy(void) +{ + //TODO: copy the value to the clipboard + QDialog::accept(); + delete this; + +} + +void DlgUnitsCalculator::help(void) +{ + //TODO: call help page Std_UnitsCalculator +} + + + + #include "moc_DlgUnitsCalculatorImp.cpp" diff --git a/src/Gui/DlgUnitsCalculatorImp.h b/src/Gui/DlgUnitsCalculatorImp.h index e74309af2..917890cc1 100644 --- a/src/Gui/DlgUnitsCalculatorImp.h +++ b/src/Gui/DlgUnitsCalculatorImp.h @@ -30,10 +30,8 @@ namespace Gui { namespace Dialog { /** - * The DlgUnitsCalculator class provides a dialog to activate the MDI window - * of the main window you wish. Since there could be a lot of MDI windows in - * an application you cannot put all of them into the "Windows" popup menu. - * \author Werner Mayer + * The DlgUnitsCalculator provides a unit conversion dialog + * \author Juergen Riegel */ class DlgUnitsCalculator : public QDialog, public Ui_DlgUnitCalculator { @@ -46,6 +44,18 @@ public: protected: void accept(); void reject(); + +protected Q_SLOTS: + void unitValueChanged(const Base::Quantity&); + void valueChanged(const Base::Quantity&); + + void copy(void); + void help(void); + +private: + Base::Quantity actValue; + Base::Quantity actUnit; + }; } // namespace Dialog diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index 93b28925d..157c2ed60 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -39,7 +39,7 @@ InputField::InputField ( QWidget * parent ) { this->setContextMenuPolicy(Qt::DefaultContextMenu); - QObject::connect(this, SIGNAL(textEdited (QString)), + QObject::connect(this, SIGNAL(textChanged (QString)), this, SLOT(newInput(QString))); } @@ -67,6 +67,7 @@ void InputField::newInput(const QString & text) QPalette *palette = new QPalette(); palette->setColor(QPalette::Base,QColor(255,200,200)); setPalette(*palette); + parseError(QString::fromAscii(ErrorText.c_str())); return; } QPalette *palette = new QPalette(); @@ -74,6 +75,8 @@ void InputField::newInput(const QString & text) setPalette(*palette); ErrorText = ""; this->setToolTip(QString::fromAscii(ErrorText.c_str())); + // signaling + valueChanged(res); } @@ -121,6 +124,59 @@ QByteArray InputField::paramGrpPath() const return sGroupString.c_str(); } +/// sets the field with a quantity +void InputField::setValue(const Base::Quantity& quant) +{ + actQuantity = quant; + if(!quant.getUnit().isEmpty()) + actUnit = quant.getUnit(); + + setText(QString::fromAscii(quant.getUserString().c_str())); +} + +void InputField::setUnit(const Base::Unit& unit) +{ + actUnit = unit; +} + + + +/// get the value of the singleStep property +double InputField::singleStep(void)const +{ + return 0.0; +} + +/// set the value of the singleStep property +void InputField::setSingleStep(double) +{ + +} + +/// get the value of the maximum property +double InputField::maximum(void)const +{ + return 0.0; +} + +/// set the value of the maximum property +void InputField::setMaximum(double) +{ + +} + +/// get the value of the minimum property +double InputField::minimum(void)const +{ + return 0.0; +} + +/// set the value of the minimum property +void InputField::setMinimum(double) +{ + +} + // -------------------------------------------------------------------- diff --git a/src/Gui/InputField.h b/src/Gui/InputField.h index d698825a0..f0274028f 100644 --- a/src/Gui/InputField.h +++ b/src/Gui/InputField.h @@ -25,6 +25,7 @@ #define GUI_INPUTFIELD_H #include +#include #include "Widgets.h" #include "Window.h" #include "SpinBox.h" @@ -37,19 +38,48 @@ namespace Gui { * The InputField class * The input field widget handles all around user input of Quantities. Thats * include parsing and checking input. Providing a context menu for common operations - * and managing default and history values. + * and managing default and history values. + * Although its derived from a QLineEdit widget, its supports most of the properties and signals + * of a * \author Jürgen Riegel */ class GuiExport InputField : public QLineEdit { Q_OBJECT - Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath ) + Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath ) + Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep ) + Q_PROPERTY(double maximum READ maximum WRITE setMaximum ) + Q_PROPERTY(double minimum READ minimum WRITE setMinimum ) + public: InputField ( QWidget * parent = 0 ); virtual ~InputField(); + /// sets the field with a quantity + void setValue(const Base::Quantity&); + /** sets the Unit this field working with. + * After seting the Unit the field will only acceppt + * user input with this unit type. Or if the user input + * a value without unit, this one will be added to the resulting + * Quantity. + */ + void setUnit(const Base::Unit&); + + /// get the value of the singleStep property + double singleStep(void)const; + /// set the value of the singleStep property + void setSingleStep(double); + /// get the value of the maximum property + double maximum(void)const; + /// set the value of the maximum property + void setMaximum(double); + /// get the value of the minimum property + double minimum(void)const; + /// set the value of the minimum property + void setMinimum(double); + /** @name history and default management */ //@{ /// the param group path where the widget write and read the dafault values @@ -62,6 +92,26 @@ public: std::vector getHistory(void); //@} + +Q_SIGNALS: + /** gets emited if the user has entered a VALID input + * Valid means the user inputed string obays all restrictions + * like: minimum, maximum and/or the right Unit (if specified). + * If you want the unfiltered/unvalidated input use valueChanged(const QString&) + * instead: + */ + void valueChanged(const Base::Quantity&); + /** gets emited if the user has entered a VALID input + * Valid means the user inputed string obays all restrictions + * like: minimum, maximum and/or the right Unit (if specified). + * If you want the unfiltered/unvalidated input use valueChanged(const QString&) + * instead: + */ + void valueChanged(double); + + /// signal for an invalid user input (signals a lot while typing!) + void parseError(const QString& errorText); + protected Q_SLOTS: void newInput(const QString & text); @@ -75,6 +125,9 @@ private: /// handle to the parameter group for defaults and history ParameterGrp::handle _handle; std::string sGroupString; + + Base::Quantity actQuantity; + Base::Unit actUnit; }; diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index dfdfa940e..cae9d5c48 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -93,7 +93,7 @@ void EditDatumDialog::exec(bool atCursor) Ui::InsertDatum ui_ins_datum; ui_ins_datum.setupUi(&dlg); - ui_ins_datum.lineEdit->setParamGrpPath("User parameter:History/Sketcher/SetDatum"); + //ui_ins_datum.lineEdit->setParamGrpPath("User parameter:History/Sketcher/SetDatum"); double init_val; if (Constr->Type == Sketcher::Angle || diff --git a/src/Mod/Sketcher/Gui/InsertDatum.ui b/src/Mod/Sketcher/Gui/InsertDatum.ui index 39b96cafe..d27befec3 100644 --- a/src/Mod/Sketcher/Gui/InsertDatum.ui +++ b/src/Mod/Sketcher/Gui/InsertDatum.ui @@ -27,7 +27,7 @@
- +
From 46db0c24e8a0dc18962fe14401e4fd9071ece1cd Mon Sep 17 00:00:00 2001 From: jriegel Date: Sat, 9 Nov 2013 11:02:23 +0100 Subject: [PATCH 4/4] further implementing InputField and UnitsCalculator --- src/Gui/DlgUnitsCalculator.ui | 4 ++-- src/Gui/DlgUnitsCalculatorImp.cpp | 33 ++++++++++++++++++++++++++++--- src/Gui/DlgUnitsCalculatorImp.h | 2 ++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/Gui/DlgUnitsCalculator.ui b/src/Gui/DlgUnitsCalculator.ui index 68c87598b..480c4b102 100644 --- a/src/Gui/DlgUnitsCalculator.ui +++ b/src/Gui/DlgUnitsCalculator.ui @@ -51,10 +51,10 @@ - + - 100 + 150 0 diff --git a/src/Gui/DlgUnitsCalculatorImp.cpp b/src/Gui/DlgUnitsCalculatorImp.cpp index 544b04108..6d6900b5b 100644 --- a/src/Gui/DlgUnitsCalculatorImp.cpp +++ b/src/Gui/DlgUnitsCalculatorImp.cpp @@ -51,6 +51,9 @@ DlgUnitsCalculator::DlgUnitsCalculator( QWidget* parent, Qt::WFlags fl ) connect(this->pushButton_Close, SIGNAL(pressed()), this, SLOT(accept())); connect(this->pushButton_Copy, SIGNAL(pressed()), this, SLOT(copy())); + connect(this->ValueInput, SIGNAL(parseError(QString)), this, SLOT(parseError(QString))); + connect(this->UnitInput, SIGNAL(parseError(QString)), this, SLOT(parseError(QString))); + actUnit.setInvalid(); } @@ -81,16 +84,40 @@ void DlgUnitsCalculator::unitValueChanged(const Base::Quantity& unit) } void DlgUnitsCalculator::valueChanged(const Base::Quantity& quant) -{ +{ + if(actUnit.isValid()){ - this->ValueOutput->setValue(Base::Quantity(quant.getValue()/actUnit.getValue(),actUnit.getUnit())); + + double value = quant.getValue()/actUnit.getValue(); + QString out(QString::fromAscii("%1 %2")); + out = out.arg(value).arg(this->UnitInput->text()); + this->ValueOutput->setText(out); + QPalette *palette = new QPalette(); + palette->setColor(QPalette::Base,QColor(200,255,200)); + this->ValueOutput->setPalette(*palette); + }else{ - this->ValueOutput->setValue(quant); + //this->ValueOutput->setValue(quant); + this->ValueOutput->setText(QString::fromAscii(quant.getUserString().c_str())); + QPalette *palette = new QPalette(); + palette->setColor(QPalette::Base,QColor(200,255,200)); + this->ValueOutput->setPalette(*palette); } actValue = quant; } +void DlgUnitsCalculator::parseError(const QString& errorText) +{ + + + QPalette *palette = new QPalette(); + palette->setColor(QPalette::Base,QColor(255,200,200)); + this->ValueOutput->setPalette(*palette); + + this->ValueOutput->setText(QString()); + +} void DlgUnitsCalculator::copy(void) { //TODO: copy the value to the clipboard diff --git a/src/Gui/DlgUnitsCalculatorImp.h b/src/Gui/DlgUnitsCalculatorImp.h index 917890cc1..fbe3cfe93 100644 --- a/src/Gui/DlgUnitsCalculatorImp.h +++ b/src/Gui/DlgUnitsCalculatorImp.h @@ -52,6 +52,8 @@ protected Q_SLOTS: void copy(void); void help(void); + void parseError(const QString& errorText); + private: Base::Quantity actValue; Base::Quantity actUnit;