1 // File: ModuleBase_Widgets.h
2 // Created: 04 June 2014
3 // Author: Vitaly Smetannikov
5 #include <ModuleBase_WidgetBoolValue.h>
7 #include <ModelAPI_AttributeDouble.h>
8 #include <ModelAPI_AttributeBoolean.h>
9 #include <ModelAPI_Data.h>
11 #include <Config_Keywords.h>
12 #include <Config_WidgetAPI.h>
14 #include <Events_Loop.h>
15 #include <Model_Events.h>
20 #include <QDoubleSpinBox>
23 ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData)
24 : ModuleBase_ModelWidget(theParent)
26 myAttributeID = theData->widgetId();
27 QString aText = QString::fromStdString(theData->widgetLabel());
28 QString aToolTip = QString::fromStdString(theData->widgetTooltip());
29 QString aDefault = QString::fromStdString(theData->getProperty("default"));
31 myCheckBox = new QCheckBox(aText, theParent);
32 myCheckBox->setToolTip(aToolTip);
33 myCheckBox->setChecked(aDefault == "true");
35 connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
38 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
42 QWidget* ModuleBase_WidgetBoolValue::getControl() const
47 bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const
49 DataPtr aData = theFeature->data();
50 boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(myAttributeID);
52 if (aBool->value() != myCheckBox->isChecked()) {
53 aBool->setValue(myCheckBox->isChecked());
54 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
59 bool ModuleBase_WidgetBoolValue::restoreValue(FeaturePtr theFeature)
61 DataPtr aData = theFeature->data();
62 boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(myAttributeID);
64 bool isBlocked = myCheckBox->blockSignals(true);
65 myCheckBox->setChecked(aRef->value());
66 myCheckBox->blockSignals(isBlocked);
71 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
73 QList<QWidget*> aList;
74 aList.append(myCheckBox);