1 // File: ModuleBase_Widgets.h
2 // Created: 04 June 2014
3 // Author: Vitaly Smetannikov
5 #include <ModuleBase_WidgetBoolValue.h>
7 #include <ModelAPI_AttributeBoolean.h>
8 #include <ModelAPI_Data.h>
10 #include <Config_Keywords.h>
11 #include <Config_WidgetAPI.h>
13 #include <Events_Loop.h>
14 #include <Model_Events.h>
20 ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData)
21 : ModuleBase_ModelWidget(theParent, theData)
23 QString aText = QString::fromStdString(theData->widgetLabel());
24 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
25 QString aDefault = QString::fromStdString(theData->getProperty("default"));
27 myCheckBox = new QCheckBox(aText, theParent);
28 myCheckBox->setToolTip(aToolTip);
29 myCheckBox->setChecked(aDefault == "true");
31 connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
34 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
38 QWidget* ModuleBase_WidgetBoolValue::getControl() const
43 bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const
45 DataPtr aData = theFeature->data();
46 boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
48 if (aBool->value() != myCheckBox->isChecked()) {
49 aBool->setValue(myCheckBox->isChecked());
50 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
55 bool ModuleBase_WidgetBoolValue::restoreValue(FeaturePtr theFeature)
57 DataPtr aData = theFeature->data();
58 boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
60 bool isBlocked = myCheckBox->blockSignals(true);
61 myCheckBox->setChecked(aRef->value());
62 myCheckBox->blockSignals(isBlocked);
67 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
69 QList<QWidget*> aList;
70 aList.append(myCheckBox);