From c80b46cd0d67df6fbb1f9dc1aa43f50f1e8ae9e9 Mon Sep 17 00:00:00 2001 From: spo Date: Wed, 9 Sep 2015 14:33:53 +0300 Subject: [PATCH] Issue #910 - Impossible to set start point , end points for line manually --- src/Model/Model_Expression.cpp | 2 ++ src/ModuleBase/ModuleBase_DoubleSpinBox.cpp | 3 +- src/ModuleBase/ModuleBase_DoubleSpinBox.h | 2 +- src/ModuleBase/ModuleBase_ParamSpinBox.cpp | 29 ++++++++++--------- src/ModuleBase/ModuleBase_ParamSpinBox.h | 2 +- .../ModuleBase_WidgetDoubleValue.cpp | 12 ++++---- src/PartSet/PartSet_WidgetPoint2d.cpp | 2 +- src/XGUI/XGUI_Workshop.cpp | 2 +- 8 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/Model/Model_Expression.cpp b/src/Model/Model_Expression.cpp index d87020b64..27e94d406 100644 --- a/src/Model/Model_Expression.cpp +++ b/src/Model/Model_Expression.cpp @@ -71,6 +71,8 @@ void Model_Expression::setText(const std::string& theValue) { if (text() != theValue) myText->Set(TCollection_ExtendedString(theValue.c_str())); + + setError(text().empty() ? "" : "Not a double value."); } std::string Model_Expression::text() const diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp index a8489408d..59d5c0285 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.cpp @@ -36,7 +36,7 @@ const double PSEUDO_ZERO = 1.e-20; \endcode Another useful feature is possibility to use scientific notation (e.g. 1.234e+18) - for the widegt text. To enable this, negative precision should be specified either + for the widget text. To enable this, negative precision should be specified either through a constructor or using setPrecision() method. Note that "decimals" property of QDoubleSpinBox is almost completely substituted @@ -240,6 +240,7 @@ QValidator::State ModuleBase_DoubleSpinBox::validate(QString& str, int& pos) con // Otherwise, expect myPrecision digits after the decimal point. int decs = myPrecision < 0 ? qAbs(myPrecision) - 1 : myPrecision; + v.setLocale(this->locale()); v.setDecimals(decs); v.setBottom(minimum()); v.setTop(maximum()); diff --git a/src/ModuleBase/ModuleBase_DoubleSpinBox.h b/src/ModuleBase/ModuleBase_DoubleSpinBox.h index 2daa53b95..87cbe6e84 100644 --- a/src/ModuleBase/ModuleBase_DoubleSpinBox.h +++ b/src/ModuleBase/ModuleBase_DoubleSpinBox.h @@ -21,7 +21,7 @@ class MODULEBASE_EXPORT ModuleBase_DoubleSpinBox : public QDoubleSpinBox Q_OBJECT public: - explicit ModuleBase_DoubleSpinBox( QWidget* theParent = 0, int thePrecision = 12 ); + explicit ModuleBase_DoubleSpinBox( QWidget* theParent = 0, int thePrecision = -12 ); virtual ~ModuleBase_DoubleSpinBox(); /// Returns true if the control is clear diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index 55543e80e..febd29bad 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -85,9 +85,9 @@ void ModuleBase_ParamSpinBox::onTextChanged(const QString& text) */ double ModuleBase_ParamSpinBox::valueFromText(const QString& theText) const { - if (!hasVariable(theText)) { + if (!hasVariable(theText)) return ModuleBase_DoubleSpinBox::valueFromText(theText); - } + // small hack: return length of the string to initiate valuesChanged signal return qHash(theText); } @@ -178,18 +178,19 @@ bool ModuleBase_ParamSpinBox::hasVariable(const QString& theText) const // QRegExp varNameMask(aDigitPattern.arg(",")); // aHasDigit = varNameMask.exactMatch(theText); //} - bool aHasDigit = false; - theText.toDouble(&aHasDigit); - if (aHasDigit) { - QLocale aLoc; // create default locale - QChar aDecPnt = aLoc.decimalPoint(); - if (aDecPnt == '.') - aHasDigit = theText.contains(aDecPnt) || (!theText.contains(',')); - else if (aDecPnt == ',') - aHasDigit = theText.contains(aDecPnt) || (!theText.contains('.')); - } - return !aHasDigit; - + bool isDouble = false; + QLocale::c().toDouble(theText, &isDouble); + +// theText.toDouble(&isDouble); +// if (isDouble) { +// QLocale aLoc; // create default locale +// QChar aDecPnt = aLoc.decimalPoint(); +// if (aDecPnt == '.') +// isDouble = theText.contains(aDecPnt) || (!theText.contains(',')); +// else if (aDecPnt == ',') +// isDouble = theText.contains(aDecPnt) || (!theText.contains('.')); +// } + return !isDouble; } /*! diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.h b/src/ModuleBase/ModuleBase_ParamSpinBox.h index 89e99ff7c..7d14e9511 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.h +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.h @@ -15,7 +15,7 @@ class MODULEBASE_EXPORT ModuleBase_ParamSpinBox : public ModuleBase_DoubleSpinBo enum State { Invalid = 0, NoVariable, Incompatible, Acceptable }; public: - explicit ModuleBase_ParamSpinBox( QWidget* theParent = 0, int thePrecision = 12 ); + explicit ModuleBase_ParamSpinBox( QWidget* theParent = 0, int thePrecision = -12 ); virtual ~ModuleBase_ParamSpinBox(); virtual void stepBy(int); diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index a576ad31b..47799fc54 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -115,16 +115,16 @@ bool ModuleBase_WidgetDoubleValue::storeValueCustom() const { DataPtr aData = myFeature->data(); AttributeDoublePtr aReal = aData->real(attributeID()); - if (!mySpinBox->hasVariable()) { + if (mySpinBox->hasVariable()) { + // Here is a text of a real value or an expression. + std::string aText = mySpinBox->text().toStdString(); + aReal->setText(aText); + } else { // it is important to set the empty text value to the attribute before set the value - // because setValue tries to calculate the attrubyte bakye according to the + // because setValue tries to calculate the attribute value according to the // attribute current text aReal->setText(""); aReal->setValue(mySpinBox->value()); - } else { - // Here is a text of a real value or an expression. - std::string aText = mySpinBox->text().toStdString(); - aReal->setText(aText); } updateObject(myFeature); return true; diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 1ffc4f4d2..61749d78f 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -160,7 +160,7 @@ bool PartSet_WidgetPoint2D::storeValueCustom() const return false; std::shared_ptr aPoint = std::dynamic_pointer_cast( aData->attribute(attributeID())); - + PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this; bool isBlocked = that->blockSignals(true); bool isImmutable = aPoint->setImmutable(true); diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index abe349cf2..6dfaa1765 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -431,7 +431,7 @@ void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation) if (aFOperation->getDescription()->hasXmlRepresentation()) { //!< No need for property panel setPropertyPanel(aFOperation); // filling the operation values by the current selection - // if the operation can be commited after the controls filling, the method perform should + // if the operation can be committed after the controls filling, the method perform should // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch) if (!aFOperation->isEditOperation()) { aFOperation->activateByPreselection(); -- 2.39.2