Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / ModuleBase / ModuleBase_ParamSpinBox.cpp
index 97b8e3f22123643d4a132e60ecad58a075dd4a52..9990dfd200548ecfbe47a7075ecbbd4223c695f8 100644 (file)
@@ -46,11 +46,10 @@ bool isVariableSymbol(const QChar& theChar) {
 
 ModuleBase_ParamSpinBox::ModuleBase_ParamSpinBox(QWidget* theParent, int thePrecision)
   : QAbstractSpinBox(theParent),
-  myPrecision(thePrecision),
   myIsEquation(false),
   myAcceptVariables(true),
   mySingleStep(1),
-  myMinimum(DBL_MIN),
+  myMinimum(-DBL_MAX),
   myMaximum(DBL_MAX)
 {
   myCompleter = new QCompleter(this);
@@ -75,7 +74,7 @@ ModuleBase_ParamSpinBox::ModuleBase_ParamSpinBox(QWidget* theParent, int thePrec
   myValidator = new QDoubleValidator(this);
   myValidator->setLocale(locale());
   myValidator->setRange(myMinimum, myMaximum);
-  myValidator->setDecimals(myPrecision);
+  myValidator->setDecimals(thePrecision);
 }
 
 void ModuleBase_ParamSpinBox::setCompletionList(QStringList& theList)
@@ -110,7 +109,7 @@ void ModuleBase_ParamSpinBox::stepBy(int steps)
   double aVal = lineEdit()->text().toDouble();
   aVal += steps * mySingleStep;
   setValue(aVal);
-  QAbstractSpinBox::stepBy(steps);
+  //QAbstractSpinBox::stepBy(steps);
 }
 
 void ModuleBase_ParamSpinBox::onTextChanged(const QString& theText)
@@ -153,8 +152,11 @@ void ModuleBase_ParamSpinBox::setValue(double value)
     aVal = myMinimum;
   else if (aVal > myMaximum)
     aVal = myMaximum;
-  QString aText = QString::number(aVal, 'g', decimals());
+  QString aText = (myValidator->decimals() == 0) ? QString::number((int)aVal) :
+    QString::number(aVal, 'g', decimals());
+  lineEdit()->blockSignals(true);
   lineEdit()->setText(aText);
+  lineEdit()->blockSignals(false);
   emit textChanged(aText);
 }
 
@@ -174,6 +176,12 @@ void ModuleBase_ParamSpinBox::setText(const QString& value)
     lineEdit()->setText(value);
     emit textChanged(value);
   }
+  else {
+    bool isConv = false;
+    double aVal = value.toDouble(&isConv);
+    if (isConv)
+      setValue(aVal);
+  }
 }
 
 /*!