Salome HOME
Construction elements are auxiliary entities:
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetBoolValue.cpp
index 07a8eb000a427539c9211f89b706e448da4e4f7d..7d5e2855b374980f097d019acf159c0869bb8121 100644 (file)
@@ -1,8 +1,11 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
 // File:        ModuleBase_Widgets.h
 // Created:     04 June 2014
 // Author:      Vitaly Smetannikov
 
 #include <ModuleBase_WidgetBoolValue.h>
+#include <ModuleBase_Tools.h>
 
 #include <ModelAPI_AttributeBoolean.h>
 #include <ModelAPI_Data.h>
 #include <QLayout>
 #include <QCheckBox>
 
-ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, 
-  const Config_WidgetAPI* theData, 
-  const std::string& theParentId)
-  : ModuleBase_ModelWidget(theParent, theData, theParentId)
+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 = new QCheckBox(aText, this);
   myCheckBox->setToolTip(aToolTip);
-  myCheckBox->setChecked(aDefault == "true");
+  myCheckBox->setChecked(isChecked);
+
+  QVBoxLayout* aMainLayout = new QVBoxLayout(this);
+  ModuleBase_Tools::adjustMargins(aMainLayout);
+  aMainLayout->addWidget(myCheckBox);
+  setLayout(aMainLayout);
 
   connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
 }
@@ -37,27 +45,19 @@ ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
 {
 }
 
-QWidget* ModuleBase_WidgetBoolValue::getControl() const 
-{ 
-  return myCheckBox; 
-}
-
-bool ModuleBase_WidgetBoolValue::storeValue() const
+bool ModuleBase_WidgetBoolValue::storeValueCustom() const
 {
   DataPtr aData = myFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
-
-  if (aBool->value() != myCheckBox->isChecked()) {
-    aBool->setValue(myCheckBox->isChecked());
-    updateObject(myFeature);
-  }
+  std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
+  aBool->setValue(myCheckBox->isChecked());
+  updateObject(myFeature);
   return true;
 }
 
 bool ModuleBase_WidgetBoolValue::restoreValue()
 {
   DataPtr aData = myFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
+  std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
 
   bool isBlocked = myCheckBox->blockSignals(true);
   myCheckBox->setChecked(aRef->value());