From 9914f396e78ea9e6523d709b23cb30a34166a1bb Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 8 Jul 2015 20:20:07 +0300 Subject: [PATCH] Fix for editing of double value --- src/ModuleBase/ModuleBase_ParamSpinBox.cpp | 26 ++++++++++++---------- src/ModuleBase/ModuleBase_Tools.cpp | 18 +++++++++------ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp index 4569e2b8f..58cd37d62 100644 --- a/src/ModuleBase/ModuleBase_ParamSpinBox.cpp +++ b/src/ModuleBase/ModuleBase_ParamSpinBox.cpp @@ -135,6 +135,7 @@ void ModuleBase_ParamSpinBox::setValue(const double value) */ void ModuleBase_ParamSpinBox::setText(const QString& value) { + myTextValue = value; lineEdit()->setText(value); } @@ -165,19 +166,20 @@ bool ModuleBase_ParamSpinBox::hasVariable() const bool ModuleBase_ParamSpinBox::hasVariable(const QString& theText) const { - QString aDigitPattern = QString("[-+]?[0-9]*[%1]?[0-9]+([eE][-+]?[0-9]+)?"); - + //const QString aDigitPattern = QString("[-+]?[0-9]*[%1]?[0-9]*([eE][-+]?[0-9]+)?"); + + //bool aHasDigit = false; + //{ + // QRegExp varNameMask(aDigitPattern.arg(".")); + // aHasDigit = varNameMask.exactMatch(theText); + //} + //if (!aHasDigit) + //{ + // QRegExp varNameMask(aDigitPattern.arg(",")); + // aHasDigit = varNameMask.exactMatch(theText); + //} bool aHasDigit = false; - { - QRegExp varNameMask(aDigitPattern.arg(".")); - aHasDigit = varNameMask.exactMatch(theText); - } - if (!aHasDigit) - { - QRegExp varNameMask(aDigitPattern.arg(",")); - aHasDigit = varNameMask.exactMatch(theText); - } - + theText.toDouble(&aHasDigit); return !aHasDigit; } diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index d3739e843..b3cb302ba 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -114,17 +114,19 @@ QPixmap lighter(const QString& theIcon, const int theLighterValue) void setSpinText(ModuleBase_ParamSpinBox* theSpin, const QString& theText) { - if (theSpin->text() != theText) { - // In order to avoid extra text setting because it will - // reset cursor position in control - bool isBlocked = theSpin->blockSignals(true); - theSpin->setText(theText); - theSpin->blockSignals(isBlocked); - } + if (theSpin->text() == theText) + return; + // In order to avoid extra text setting because it will + // reset cursor position in control + bool isBlocked = theSpin->blockSignals(true); + theSpin->setText(theText); + theSpin->blockSignals(isBlocked); } void setSpinValue(QDoubleSpinBox* theSpin, double theValue) { + if (theSpin->value() == theValue) + return; bool isBlocked = theSpin->blockSignals(true); theSpin->setValue(theValue); theSpin->blockSignals(isBlocked); @@ -132,6 +134,8 @@ void setSpinValue(QDoubleSpinBox* theSpin, double theValue) void setSpinValue(ModuleBase_ParamSpinBox* theSpin, double theValue) { + if (theSpin->value() == theValue) + return; bool isBlocked = theSpin->blockSignals(true); theSpin->setValue(theValue); theSpin->blockSignals(isBlocked); -- 2.39.2