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_Panel.h>
21 #include <SamplePanelPlugin_Feature.h>
23 #include <ModelAPI_AttributeInteger.h>
24 #include <ModelAPI_Events.h>
26 #include <Events_Loop.h>
28 #include <QGridLayout>
32 SamplePanelPlugin_Panel::SamplePanelPlugin_Panel(QWidget* theParent)
33 : QWidget(theParent), myDefaultValue(0)
35 QGridLayout* aLayout = new QGridLayout(this);
36 aLayout->addWidget(new QLabel(tr("Values:")), 0, 0);
38 myComboBox = new QComboBox(this);
39 myComboBox->addItem("Value_1");
40 myComboBox->addItem("Value_2");
41 myComboBox->addItem("Value_3");
43 connect(myComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
44 aLayout->addWidget(myComboBox, 0, 1);
47 void SamplePanelPlugin_Panel::setFeature(const FeaturePtr& theFeature)
49 myFeature = theFeature;
51 AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
52 AttributeIntegerPtr aValueAttribute =
53 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
54 /// the attribute should be filled with some value, because Apply button of the Property
55 /// panel is enabled only if all attributes of the feature are initialized
56 /// It is possible to make it in the initializeAttribute method of the feature after
57 /// attribute creation
58 if (!aValueAttribute->isInitialized()) {
59 aValueAttribute->setValue(myDefaultValue);
60 /// to update error state of the feature: previous value was that this attribute is not
61 /// initialized yet. Apply of Property panel was disabled.
62 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
65 int aValueId = aValueAttribute->value();
66 myComboBox->setCurrentIndex(aValueId);
69 void SamplePanelPlugin_Panel::onCurrentIndexChanged(int theIndex)
74 AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
75 AttributeIntegerPtr aValueAttribute =
76 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
77 aValueAttribute->setValue(theIndex);
78 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));