1 // Copyright (C) 2014-2019 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <ModuleBase_WidgetBoolValue.h>
21 #include <ModuleBase_Tools.h>
23 #include <ModelAPI_AttributeBoolean.h>
24 #include <ModelAPI_Data.h>
26 #include <Config_Keywords.h>
27 #include <Config_WidgetAPI.h>
29 #include <Events_Loop.h>
30 #include <ModelAPI_Events.h>
36 ModuleBase_WidgetBoolValue::ModuleBase_WidgetBoolValue(QWidget* theParent,
37 const Config_WidgetAPI* theData)
38 : ModuleBase_ModelWidget(theParent, theData)
40 QString aText = translate(theData->widgetLabel());
41 QString aToolTip = translate(theData->widgetTooltip());
42 myDefVal = theData->getBooleanAttribute(ATTR_DEFAULT, false);
44 myCheckBox = new QCheckBox(aText, this);
45 myCheckBox->setToolTip(aToolTip);
46 myCheckBox->setChecked(myDefVal);
48 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
49 ModuleBase_Tools::adjustMargins(aMainLayout);
50 aMainLayout->addWidget(myCheckBox);
51 setLayout(aMainLayout);
53 connect(myCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(valuesChanged()));
56 ModuleBase_WidgetBoolValue::~ModuleBase_WidgetBoolValue()
60 bool ModuleBase_WidgetBoolValue::storeValueCustom()
62 DataPtr aData = myFeature->data();
63 std::shared_ptr<ModelAPI_AttributeBoolean> aBool = aData->boolean(attributeID());
64 aBool->setValue(myCheckBox->isChecked());
65 updateObject(myFeature);
69 bool ModuleBase_WidgetBoolValue::restoreValueCustom()
71 DataPtr aData = myFeature->data();
72 std::shared_ptr<ModelAPI_AttributeBoolean> aRef = aData->boolean(attributeID());
74 bool isBlocked = myCheckBox->blockSignals(true);
75 if (aRef->isInitialized()) {
76 myCheckBox->setChecked(aRef->value());
79 myCheckBox->setChecked(myDefVal);
80 aRef->setValue(myDefVal);
82 myCheckBox->blockSignals(isBlocked);
86 QList<QWidget*> ModuleBase_WidgetBoolValue::getControls() const
88 QList<QWidget*> aList;
89 aList.append(myCheckBox);
93 void ModuleBase_WidgetBoolValue::setHighlighted(bool)