Salome HOME
Provide preselection
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetBoolValue.cpp
index d55bd18e05620013e0f3c6abd7c8b3df079ef6c2..cc0197d577d18d90a5876633cfdf4ce348c92262 100644 (file)
@@ -4,7 +4,6 @@
 
 #include <ModuleBase_WidgetBoolValue.h>
 
-#include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_Data.h>
 
 #include <Config_WidgetAPI.h>
 
 #include <Events_Loop.h>
-#include <Model_Events.h>
+#include <ModelAPI_Events.h>
 
 #include <QWidget>
 #include <QLayout>
-#include <QLabel>
-#include <QDoubleSpinBox>
 #include <QCheckBox>
 
-ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData)
-  : ModuleBase_ModelWidget(theParent)
+ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent,
+                                                       const Config_WidgetAPI* theData,
+                                                       const std::string& theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
-  myAttributeID = theData->widgetId();
   QString aText = QString::fromStdString(theData->widgetLabel());
   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
-  QString aDefault = QString::fromStdString(theData->getProperty("default"));
+  bool isChecked = theData->getBooleanAttribute(ANY_WDG_DEFAULT, false);
 
   myCheckBox = new QCheckBox(aText, theParent);
   myCheckBox->setToolTip(aToolTip);
-  myCheckBox->setChecked(aDefault == "true");
+  myCheckBox->setChecked(isChecked);
 
   connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
 }
@@ -39,27 +37,24 @@ ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
 {
 }
 
-QWidget* ModuleBase_WidgetBoolValue::getControl() const 
-{ 
-  return myCheckBox; 
+QWidget* ModuleBase_WidgetBoolValue::getControl() const
+{
+  return myCheckBox;
 }
 
-bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const
+bool ModuleBase_WidgetBoolValue::storeValue() const
 {
-  DataPtr aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(myAttributeID);
-
-  if (aBool->value() != myCheckBox->isChecked()) {
-    aBool->setValue(myCheckBox->isChecked());
-    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
-  }
+  DataPtr aData = myFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
+  aBool->setValue(myCheckBox->isChecked());
+  updateObject(myFeature);
   return true;
 }
 
-bool ModuleBase_WidgetBoolValue::restoreValue(FeaturePtr theFeature)
+bool ModuleBase_WidgetBoolValue::restoreValue()
 {
-  DataPtr aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(myAttributeID);
+  DataPtr aData = myFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
 
   bool isBlocked = myCheckBox->blockSignals(true);
   myCheckBox->setChecked(aRef->value());