Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetBoolValue.cpp
index a34a73d6f02bedf6c2250345486d16cff2c3dff3..f1d5f2ba08a1443c15d63d9da31ea051d9bfaae9 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        ModuleBase_Widgets.h
 // Created:     04 June 2014
 // Author:      Vitaly Smetannikov
 #include <Config_WidgetAPI.h>
 
 #include <Events_Loop.h>
-#include <Model_Events.h>
+#include <ModelAPI_Events.h>
 
 #include <QWidget>
 #include <QLayout>
 #include <QCheckBox>
 
-ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData)
-  : ModuleBase_ModelWidget(theParent, theData)
+ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent,
+                                                       const Config_WidgetAPI* theData,
+                                                       const std::string& theParentId)
+    : ModuleBase_ModelWidget(theParent, theData, theParentId)
 {
   QString aText = QString::fromStdString(theData->widgetLabel());
   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
-  QString aDefault = QString::fromStdString(theData->getProperty("default"));
+  bool isChecked = theData->getBooleanAttribute(ATTR_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()));
 }
@@ -35,27 +39,19 @@ ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
 {
 }
 
-QWidget* ModuleBase_WidgetBoolValue::getControl() const 
-{ 
-  return myCheckBox; 
-}
-
-bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const
+bool ModuleBase_WidgetBoolValue::storeValueCustom() const
 {
-  DataPtr aData = theFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
-
-  if (aBool->value() != myCheckBox->isChecked()) {
-    aBool->setValue(myCheckBox->isChecked());
-    Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
-  }
+  DataPtr aData = myFeature->data();
+  std::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(attributeID());
+  DataPtr aData = myFeature->data();
+  std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
 
   bool isBlocked = myCheckBox->blockSignals(true);
   myCheckBox->setChecked(aRef->value());