Salome HOME
Fix for missed values in DoubleSpinBox on edit
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetDoubleValue.cpp
index 20c798187058c1520d6caee2d67f882da30794d1..20f5224844cb33ea30be3c603640086a5fcd8071 100644 (file)
@@ -5,10 +5,11 @@
 // Author:      Vitaly Smetannikov
 
 #include <ModuleBase_WidgetDoubleValue.h>
-#include <ModuleBase_DoubleSpinBox.h>
+#include <ModuleBase_ParamSpinBox.h>
 #include <ModuleBase_Tools.h>
 
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Data.h>
 
 #include <Config_Keywords.h>
@@ -46,7 +47,7 @@ ModuleBase_WidgetDoubleValue::ModuleBase_WidgetDoubleValue(QWidget* theParent,
   if (!aLabelIcon.isEmpty())
     myLabel->setPixmap(QPixmap(aLabelIcon));
 
-  mySpinBox = new ModuleBase_DoubleSpinBox(this);
+  mySpinBox = new ModuleBase_ParamSpinBox(this);
   QString anObjName = QString::fromStdString(attributeID());
   mySpinBox->setObjectName(anObjName);
 
@@ -104,6 +105,7 @@ void ModuleBase_WidgetDoubleValue::reset()
     bool isOk;
     double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
     ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
+    storeValueCustom();
   }
 }
 
@@ -112,6 +114,11 @@ bool ModuleBase_WidgetDoubleValue::storeValueCustom() const
   DataPtr aData = myFeature->data();
   AttributeDoublePtr aReal = aData->real(attributeID());
   aReal->setValue(mySpinBox->value());
+  std::string aTextRepr;
+  if (mySpinBox->hasVariable()) {
+    aTextRepr = mySpinBox->text().toStdString();
+  }
+  aReal->setText(aTextRepr);
   updateObject(myFeature);
   return true;
 }
@@ -120,9 +127,12 @@ bool ModuleBase_WidgetDoubleValue::restoreValue()
 {
   DataPtr aData = myFeature->data();
   AttributeDoublePtr aRef = aData->real(attributeID());
-
-  ModuleBase_Tools::setSpinValue(mySpinBox, aRef->value());
-
+  std::string aTextRepr = aRef->text();
+  if (!aTextRepr.empty()) {
+    mySpinBox->setText(QString::fromStdString(aTextRepr));
+  } else {
+    ModuleBase_Tools::setSpinValue(mySpinBox, aRef->value());
+  }
   return true;
 }