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