Salome HOME
Fix for crash on multi-selection of group-vertices on imported body with Shift-key...
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetDoubleValue.cpp
index e314234a247fed9b6d169a7eac38a2079fb78c9a..a17ea26c9793ee4a8c3acab86dc7f5df40b0646b 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);
 
@@ -103,15 +104,25 @@ void ModuleBase_WidgetDoubleValue::reset()
   else {
     bool isOk;
     double aDefValue = QString::fromStdString(getDefaultValue()).toDouble(&isOk);
-    ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
+    // reset the value just if there is a default value definition in the XML definition
+    // if the double value can not be found by the default value, do nothing
+    if (isOk) {
+      ModuleBase_Tools::setSpinValue(mySpinBox, isOk ? aDefValue : 0.0);
+      storeValueCustom();
+    }
   }
 }
 
-bool ModuleBase_WidgetDoubleValue::storeValue() const
+bool ModuleBase_WidgetDoubleValue::storeValueCustom() const
 {
   DataPtr aData = myFeature->data();
   AttributeDoublePtr aReal = aData->real(attributeID());
   aReal->setValue(mySpinBox->value());
+  std::string aTextRepr = aReal->text();
+  if (mySpinBox->hasVariable()) {
+    aTextRepr = mySpinBox->text().toStdString();
+  }
+  aReal->setText(aTextRepr);
   updateObject(myFeature);
   return true;
 }
@@ -120,9 +131,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;
 }