Salome HOME
Merge branch 'Dev_1.1.0' of newgeom:newgeom into Dev_1.1.0
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetBoolValue.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModuleBase_Widgets.h
4 // Created:     04 June 2014
5 // Author:      Vitaly Smetannikov
6
7 #include <ModuleBase_WidgetBoolValue.h>
8
9 #include <ModelAPI_AttributeBoolean.h>
10 #include <ModelAPI_Data.h>
11
12 #include <Config_Keywords.h>
13 #include <Config_WidgetAPI.h>
14
15 #include <Events_Loop.h>
16 #include <ModelAPI_Events.h>
17
18 #include <QWidget>
19 #include <QLayout>
20 #include <QCheckBox>
21
22 ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent,
23                                                        const Config_WidgetAPI* theData,
24                                                        const std::string& theParentId)
25     : ModuleBase_ModelWidget(theParent, theData, theParentId)
26 {
27   QString aText = QString::fromStdString(theData->widgetLabel());
28   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
29   bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
30
31   myCheckBox = new QCheckBox(aText, theParent);
32   myCheckBox->setToolTip(aToolTip);
33   myCheckBox->setChecked(isChecked);
34
35   connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
36 }
37
38 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
39 {
40 }
41
42 bool ModuleBase_WidgetBoolValue::storeValueCustom() const
43 {
44   DataPtr aData = myFeature->data();
45   std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
46   aBool->setValue(myCheckBox->isChecked());
47   updateObject(myFeature);
48   return true;
49 }
50
51 bool ModuleBase_WidgetBoolValue::restoreValue()
52 {
53   DataPtr aData = myFeature->data();
54   std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
55
56   bool isBlocked = myCheckBox->blockSignals(true);
57   myCheckBox->setChecked(aRef->value());
58   myCheckBox->blockSignals(isBlocked);
59
60   return true;
61 }
62
63 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
64 {
65   QList<QWidget*> aList;
66   aList.append(myCheckBox);
67   return aList;
68 }