Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[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 <Model_Events.h>
15
16 #include <QWidget>
17 #include <QLayout>
18 #include <QCheckBox>
19
20 ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent, const Config_WidgetAPI* theData)
21   : ModuleBase_ModelWidget(theParent, theData)
22 {
23   QString aText = QString::fromStdString(theData->widgetLabel());
24   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
25   QString aDefault = QString::fromStdString(theData->getProperty("default"));
26
27   myCheckBox = new QCheckBox(aText, theParent);
28   myCheckBox->setToolTip(aToolTip);
29   myCheckBox->setChecked(aDefault == "true");
30
31   connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
32 }
33
34 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
35 {
36 }
37
38 QWidget* ModuleBase_WidgetBoolValue::getControl() const 
39
40   return myCheckBox; 
41 }
42
43 bool ModuleBase_WidgetBoolValue::storeValue(FeaturePtr theFeature) const
44 {
45   DataPtr aData = theFeature->data();
46   boost::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
47
48   if (aBool->value() != myCheckBox->isChecked()) {
49     aBool->setValue(myCheckBox->isChecked());
50     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED));
51   }
52   return true;
53 }
54
55 bool ModuleBase_WidgetBoolValue::restoreValue(FeaturePtr theFeature)
56 {
57   DataPtr aData = theFeature->data();
58   boost::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
59
60   bool isBlocked = myCheckBox->blockSignals(true);
61   myCheckBox->setChecked(aRef->value());
62   myCheckBox->blockSignals(isBlocked);
63
64   return true;
65 }
66
67 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
68 {
69   QList<QWidget*> aList;
70   aList.append(myCheckBox);
71   return aList;
72 }