1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_Widgets.h
4 // Created: 04 June 2014
5 // Author: Vitaly Smetannikov
7 #include <ModuleBase_WidgetBoolValue.h>
8 #include <ModuleBase_Tools.h>
10 #include <ModelAPI_AttributeBoolean.h>
11 #include <ModelAPI_Data.h>
13 #include <Config_Keywords.h>
14 #include <Config_WidgetAPI.h>
16 #include <Events_Loop.h>
17 #include <ModelAPI_Events.h>
23 ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent,
24 const Config_WidgetAPI* theData,
25 const std::string& theParentId)
26 : ModuleBase_ModelWidget(theParent, theData, theParentId)
28 QString aText = QString::fromStdString(theData->widgetLabel());
29 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
30 bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
32 myCheckBox = new QCheckBox(aText, this);
33 myCheckBox->setToolTip(aToolTip);
34 myCheckBox->setChecked(isChecked);
36 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
37 ModuleBase_Tools::adjustMargins(aMainLayout);
38 aMainLayout->addWidget(myCheckBox);
39 setLayout(aMainLayout);
41 connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
44 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
48 bool ModuleBase_WidgetBoolValue::storeValueCustom() const
50 DataPtr aData = myFeature->data();
51 std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
52 aBool->setValue(myCheckBox->isChecked());
53 updateObject(myFeature);
57 bool ModuleBase_WidgetBoolValue::restoreValue()
59 DataPtr aData = myFeature->data();
60 std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
62 bool isBlocked = myCheckBox->blockSignals(true);
63 myCheckBox->setChecked(aRef->value());
64 myCheckBox->blockSignals(isBlocked);
69 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
71 QList<QWidget*> aList;
72 aList.append(myCheckBox);