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_AttributeBoolean.h>
8 #include <ModelAPI_Data.h>
9
10 #include <Config_Keywords.h>
11 #include <Config_WidgetAPI.h>
12
13 #include <Events_Loop.h>
14 #include <ModelAPI_Events.h>
15
16 #include <QWidget>
17 #include <QLayout>
18 #include <QCheckBox>
19
20 ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent,
21                                                        const Config_WidgetAPI* theData,
22                                                        const std::string& theParentId)
23     : ModuleBase_ModelWidget(theParent, theData, theParentId)
24 {
25   QString aText = QString::fromStdString(theData->widgetLabel());
26   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
27   bool isChecked = theData->getBooleanAttribute(ANY_WDG_DEFAULT, false);
28
29   myCheckBox = new QCheckBox(aText, theParent);
30   myCheckBox->setToolTip(aToolTip);
31   myCheckBox->setChecked(isChecked);
32
33   connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
34 }
35
36 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
37 {
38 }
39
40 QWidget* ModuleBase_WidgetBoolValue::getControl() const
41 {
42   return myCheckBox;
43 }
44
45 bool ModuleBase_WidgetBoolValue::storeValue() const
46 {
47   DataPtr aData = myFeature->data();
48   boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
49   aBool->setValue(myCheckBox->isChecked());
50   updateObject(myFeature);
51   return true;
52 }
53
54 bool ModuleBase_WidgetBoolValue::restoreValue()
55 {
56   DataPtr aData = myFeature->data();
57   boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
58
59   bool isBlocked = myCheckBox->blockSignals(true);
60   myCheckBox->setChecked(aRef->value());
61   myCheckBox->blockSignals(isBlocked);
62
63   return true;
64 }
65
66 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
67 {
68   QList<QWidget*> aList;
69   aList.append(myCheckBox);
70   return aList;
71 }