1 // Copyright (C) 2014-2017 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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include <SamplePanelPlugin_Panel.h>
22 #include <SamplePanelPlugin_Feature.h>
24 #include <ModelAPI_AttributeInteger.h>
25 #include <ModelAPI_Events.h>
27 #include <Events_Loop.h>
29 #include <QGridLayout>
33 SamplePanelPlugin_Panel::SamplePanelPlugin_Panel(QWidget* theParent)
34 : QWidget(theParent), myDefaultValue(0)
36 QGridLayout* aLayout = new QGridLayout(this);
37 aLayout->addWidget(new QLabel(tr("Values:")), 0, 0);
39 myComboBox = new QComboBox(this);
40 myComboBox->addItem("Value_1");
41 myComboBox->addItem("Value_2");
42 myComboBox->addItem("Value_3");
44 connect(myComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
45 aLayout->addWidget(myComboBox, 0, 1);
48 void SamplePanelPlugin_Panel::setFeature(const FeaturePtr& theFeature)
50 myFeature = theFeature;
52 AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
53 AttributeIntegerPtr aValueAttribute =
54 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
55 /// the attribute should be filled with some value, because Apply button of the Property
56 /// panel is enabled only if all attributes of the feature are initialized
57 /// It is possible to make it in the initializeAttribute method of the feature after
58 /// attribute creation
59 if (!aValueAttribute->isInitialized()) {
60 aValueAttribute->setValue(myDefaultValue);
61 /// to update error state of the feature: previous value was that this attribute is not
62 /// initialized yet. Apply of Property panel was disabled.
63 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
66 int aValueId = aValueAttribute->value();
67 myComboBox->setCurrentIndex(aValueId);
70 void SamplePanelPlugin_Panel::onCurrentIndexChanged(int theIndex)
75 AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
76 AttributeIntegerPtr aValueAttribute =
77 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
78 aValueAttribute->setValue(theIndex);
79 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));