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()