Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[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   QString aDefault = QString::fromStdString(theData->getProperty("default"));
28
29   myCheckBox = new QCheckBox(aText, theParent);
30   myCheckBox->setToolTip(aToolTip);
31   myCheckBox->setChecked(aDefault == "true");
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
50   if (aBool->value() != myCheckBox->isChecked()) {
51     aBool->setValue(myCheckBox->isChecked());
52     updateObject(myFeature);
53   }
54   return true;
55 }
56
57 bool ModuleBase_WidgetBoolValue::restoreValue()
58 {
59   DataPtr aData = myFeature->data();
60   boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
61
62   bool isBlocked = myCheckBox->blockSignals(true);
63   myCheckBox->setChecked(aRef->value());
64   myCheckBox->blockSignals(isBlocked);
65
66   return true;
67 }
68
69 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
70 {
71   QList<QWidget*> aList;
72   aList.append(myCheckBox);
73   return aList;
74 }