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 <SamplePanelPlugin_ModelWidget.h>
21 #include <SamplePanelPlugin_Feature.h>
23 #include <ModelAPI_AttributeInteger.h>
24 #include <ModelAPI_Events.h>
26 #include <Config_WidgetAPI.h>
27 #include <Events_Loop.h>
29 #include <QVBoxLayout>
30 #include <QGridLayout>
34 SamplePanelPlugin_ModelWidget::SamplePanelPlugin_ModelWidget(QWidget* theParent,
35 const Config_WidgetAPI* theData)
36 : ModuleBase_ModelWidget(theParent, theData), myDefaultValue(0)
38 QVBoxLayout* aLay = new QVBoxLayout(this);
39 aLay->setContentsMargins(0, 0, 0, 0);
41 myMainWidget = new QWidget(this);
42 aLay->addWidget(myMainWidget);
44 QGridLayout* aLayout = new QGridLayout(myMainWidget);
45 aLayout->addWidget(new QLabel(tr("Values:")), 0, 0);
47 myComboBox = new QComboBox(myMainWidget);
48 myComboBox->addItem("Value_1");
49 myComboBox->addItem("Value_2");
50 myComboBox->addItem("Value_3");
52 connect(myComboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(valuesChanged()));
53 aLayout->addWidget(myComboBox, 0, 1);
56 QList<QWidget*> SamplePanelPlugin_ModelWidget::getControls() const
58 QList<QWidget*> aControls;
59 // this control will accept focus and will be highlighted in the Property Panel
60 aControls.push_back(myComboBox);
64 bool SamplePanelPlugin_ModelWidget::storeValueCustom()
66 AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
67 AttributeIntegerPtr aValueAttribute =
68 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
69 aValueAttribute->setValue(myComboBox->currentIndex());
70 updateObject(myFeature);
74 bool SamplePanelPlugin_ModelWidget::restoreValueCustom()
76 AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
77 AttributeIntegerPtr aValueAttribute =
78 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
80 bool isBlocked = myComboBox->blockSignals(true);
81 myComboBox->setCurrentIndex(aValueAttribute->value());
82 myComboBox->blockSignals(isBlocked);