Salome HOME
Copyright update 2022
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetDoubleValue.cpp
index 4b0e41daa5be7e11d1c94dbcd10b85f36eee2b1b..b6dc65443f1cdd964a9ff2dbb9d349aca4a9a351 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -172,7 +172,7 @@ bool ModuleBase_WidgetDoubleValue::storeValueCustom()
       // Nullyfy the parameter reference without deletion of the created
       myParameter = FeaturePtr();
     }
-    aReal->setText(aText.toStdString());
+    aReal->setText(aText.toStdWString());
   } else {
     // it is important to set the empty text value to the attribute before set the value
     // because setValue tries to calculate the attribute value according to the
@@ -181,7 +181,7 @@ bool ModuleBase_WidgetDoubleValue::storeValueCustom()
       aReal->setExpressionError("");
       aReal->setExpressionInvalid(false);
     }
-    aReal->setText("");
+    aReal->setText(L"");
     aReal->setValue(mySpinBox->value());
   }
   updateObject(myFeature);
@@ -192,21 +192,9 @@ bool ModuleBase_WidgetDoubleValue::restoreValueCustom()
 {
   DataPtr aData = myFeature->data();
   AttributeDoublePtr aRef = aData->real(attributeID());
-  std::string aTextRepr = aRef->text();
+  std::wstring aTextRepr = aRef->text();
   if (!aTextRepr.empty()) {
-    QString aText = QString::fromStdString(aTextRepr);
-    //if (aText.endsWith('=')) {
-    //  if (!myParameter.get()) {
-    //    QString aName = aText.left(aText.indexOf('=')).trimmed();
-    //    myParameter = ModuleBase_Tools::findParameter(aName);
-    //  }
-    //  /// If myParameter is empty then it was not created because of an error
-    //  if (!myParameter.get())
-    //    return false;
-
-    //  AttributeStringPtr aExprAttr = myParameter->string("expression");
-    //  aText += aExprAttr->value().c_str();
-    //}
+    QString aText = QString::fromStdWString(aTextRepr);
     ModuleBase_Tools::setSpinText(mySpinBox, aText);
   }
   else {
@@ -242,3 +230,18 @@ bool ModuleBase_WidgetDoubleValue::processEnter()
   }
   return isModified;
 }
+
+bool ModuleBase_WidgetDoubleValue::isModified() const
+{
+  QString aText = mySpinBox->text();
+  if (aText.isEmpty())
+    return false;
+
+  if (myHasDefault) {
+    bool aOk = false;
+    double aVal = aText.toDouble(&aOk);
+    if (!aOk || aVal == myDefaultVal)
+      return false;
+  }
+  return true;
+}
\ No newline at end of file