Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetBoolValue.cpp
1 // Copyright (C) 2014-2017  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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <ModuleBase_WidgetBoolValue.h>
22 #include <ModuleBase_Tools.h>
23
24 #include <ModelAPI_AttributeBoolean.h>
25 #include <ModelAPI_Data.h>
26
27 #include <Config_Keywords.h>
28 #include <Config_WidgetAPI.h>
29
30 #include <Events_Loop.h>
31 #include <ModelAPI_Events.h>
32
33 #include <QWidget>
34 #include <QLayout>
35 #include <QCheckBox>
36
37 ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent,
38                                                        const Config_WidgetAPI* theData)
39 : ModuleBase_ModelWidget(theParent, theData)
40 {
41   QString aText = translate(theData->widgetLabel());
42   QString aToolTip = translate(theData->widgetTooltip());
43   bool isChecked = theData->getBooleanAttribute(ATTR_DEFAULT, false);
44
45   myCheckBox = new QCheckBox(aText, this);
46   myCheckBox->setToolTip(aToolTip);
47   myCheckBox->setChecked(isChecked);
48
49   QVBoxLayout* aMainLayout = new QVBoxLayout(this);
50   ModuleBase_Tools::adjustMargins(aMainLayout);
51   aMainLayout->addWidget(myCheckBox);
52   setLayout(aMainLayout);
53
54   connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
55 }
56
57 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
58 {
59 }
60
61 bool ModuleBase_WidgetBoolValue::storeValueCustom()
62 {
63   DataPtr aData = myFeature->data();
64   std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
65   aBool->setValue(myCheckBox->isChecked());
66   updateObject(myFeature);
67   return true;
68 }
69
70 bool ModuleBase_WidgetBoolValue::restoreValueCustom()
71 {
72   DataPtr aData = myFeature->data();
73   std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
74
75   bool isBlocked = myCheckBox->blockSignals(true);
76   myCheckBox->setChecked(aRef->value());
77   myCheckBox->blockSignals(isBlocked);
78
79   return true;
80 }
81
82 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
83 {
84   QList<QWidget*> aList;
85   aList.append(myCheckBox);
86   return aList;
87 }
88
89 void ModuleBase_WidgetBoolValue::setHighlighted(bool)
90 {
91   return;
92 }