Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetBoolValue.cpp
1 // File:        ModuleBase_Widgets.h
2 // Created:     04 June 2014
3 // Author:      Vitaly Smetannikov
4
5 #include <ModuleBase_WidgetBoolValue.h>
6
7 #include <ModelAPI_AttributeDouble.h>
8 #include <ModelAPI_AttributeBoolean.h>
9 #include <ModelAPI_Data.h>
10
11 #include <Config_Keywords.h>
12 #include <Config_WidgetAPI.h>
13
14 #include <Events_Loop.h>
15 #include <Model_Events.h>
16
17 #include <QWidget>
18 #include <QLayout>
19 #include <QLabel>
20 #include <QDoubleSpinBox>
21 #include <QCheckBox>
22
23 ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData)
24   : ModuleBase_ModelWidget(theParent)
25 {
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"));
30
31   myCheckBox = new QCheckBox(aText, theParent);
32   myCheckBox->setToolTip(aToolTip);
33   myCheckBox->setChecked(aDefault == "true");
34
35   connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
36 }
37
38 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
39 {
40 }
41
42 QWidget* ModuleBase_WidgetBoolValue::getControl() const 
43
44   return myCheckBox; 
45 }
46
47 bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const
48 {
49   DataPtr aData = theFeature->data();
50   boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(myAttributeID);
51
52   if (aBool->value() != myCheckBox->isChecked()) {
53     aBool->setValue(myCheckBox->isChecked());
54     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
55   }
56   return true;
57 }
58
59 bool ModuleBase_WidgetBoolValue::restoreValue(FeaturePtr theFeature)
60 {
61   DataPtr aData = theFeature->data();
62   boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(myAttributeID);
63
64   bool isBlocked = myCheckBox->blockSignals(true);
65   myCheckBox->setChecked(aRef->value());
66   myCheckBox->blockSignals(isBlocked);
67
68   return true;
69 }
70
71 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
72 {
73   QList<QWidget*> aList;
74   aList.append(myCheckBox);
75   return aList;
76 }