Salome HOME
updated copyright message
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetBoolValue.cpp
1 // Copyright (C) 2014-2023  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <ModuleBase_WidgetBoolValue.h>
21 #include <ModuleBase_Tools.h>
22
23 #include <ModelAPI_AttributeBoolean.h>
24 #include <ModelAPI_Data.h>
25
26 #include <Config_Keywords.h>
27 #include <Config_WidgetAPI.h>
28
29 #include <Events_Loop.h>
30 #include <ModelAPI_Events.h>
31
32 #include <QWidget>
33 #include <QLayout>
34 #include <QCheckBox>
35
36 ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent,
37                                                        const Config_WidgetAPI* theData)
38 : ModuleBase_ModelWidget(theParent, theData)
39 {
40   QString aText = translate(theData->widgetLabel());
41   QString aToolTip = translate(theData->widgetTooltip());
42   myDefVal = theData->getBooleanAttribute(ATTR_DEFAULT, false);
43
44   myCheckBox = new QCheckBox(aText, this);
45   myCheckBox->setToolTip(aToolTip);
46   myCheckBox->setChecked(myDefVal);
47
48   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
49   ModuleBase_Tools::adjustMargins(aMainLayout);
50   aMainLayout->addWidget(myCheckBox);
51   setLayout(aMainLayout);
52
53   connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
54 }
55
56 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
57 {
58 }
59
60 bool ModuleBase_WidgetBoolValue::storeValueCustom()
61 {
62   DataPtr aData = myFeature->data();
63   std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
64   aBool->setValue(myCheckBox->isChecked());
65   updateObject(myFeature);
66   return true;
67 }
68
69 bool ModuleBase_WidgetBoolValue::restoreValueCustom()
70 {
71   DataPtr aData = myFeature->data();
72   std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
73
74   bool isBlocked = myCheckBox->blockSignals(true);
75   if (aRef->isInitialized()) {
76     myCheckBox->setChecked(aRef->value());
77   }
78   else {
79     myCheckBox->setChecked(myDefVal);
80     aRef->setValue(myDefVal);
81   }
82   myCheckBox->blockSignals(isBlocked);
83   return true;
84 }
85
86 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
87 {
88   QList<QWidget*> aList;
89   aList.append(myCheckBox);
90   return aList;
91 }
92
93 void ModuleBase_WidgetBoolValue::setHighlighted(bool)
94 {
95   return;
96 }