Salome HOME
Do no highlight the boolean widget
[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 #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                                                        const std::string& theParentId)
26     : ModuleBase_ModelWidget(theParent, theData, theParentId)
27 {
28   QString aText = QString::fromStdString(theData->widgetLabel());
29   QString aToolTip = QString::fromStdString(theData->widgetTooltip());
30   bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
31
32   myCheckBox = new QCheckBox(aText, this);
33   myCheckBox->setToolTip(aToolTip);
34   myCheckBox->setChecked(isChecked);
35
36   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
37   ModuleBase_Tools::adjustMargins(aMainLayout);
38   aMainLayout->addWidget(myCheckBox);
39   setLayout(aMainLayout);
40
41   connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
42 }
43
44 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
45 {
46 }
47
48 bool ModuleBase_WidgetBoolValue::storeValueCustom() const
49 {
50   DataPtr aData = myFeature->data();
51   std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
52   aBool->setValue(myCheckBox->isChecked());
53   updateObject(myFeature);
54   return true;
55 }
56
57 bool ModuleBase_WidgetBoolValue::restoreValue()
58 {
59   DataPtr aData = myFeature->data();
60   std::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 }
75
76 void ModuleBase_WidgetBoolValue::setHighlighted(bool)
77 {
78   return;
79 }