1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SamplePanelPlugin_PageGroupBox.h
4 // Created: 29 Mar 2015
5 // Author: Natalia ERMOLAEVA
7 #include <SamplePanelPlugin_Panel.h>
8 #include <SamplePanelPlugin_Feature.h>
10 #include <ModelAPI_AttributeInteger.h>
11 #include <ModelAPI_Events.h>
13 #include <Events_Loop.h>
15 #include <QGridLayout>
19 SamplePanelPlugin_Panel::SamplePanelPlugin_Panel(QWidget* theParent)
20 : QWidget(theParent), myDefaultValue(0)
22 QGridLayout* aLayout = new QGridLayout(this);
23 aLayout->addWidget(new QLabel(tr("Values:")), 0, 0);
25 myComboBox = new QComboBox(this);
26 myComboBox->addItem("Value_1");
27 myComboBox->addItem("Value_2");
28 myComboBox->addItem("Value_3");
30 connect(myComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
31 aLayout->addWidget(myComboBox, 0, 1);
34 void SamplePanelPlugin_Panel::setFeature(const FeaturePtr& theFeature)
36 myFeature = theFeature;
38 AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
39 AttributeIntegerPtr aValueAttribute =
40 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
41 /// the attribute should be filled with some value, because Apply button of the Property
42 /// panel is enabled only if all attributes of the feature are initialized
43 /// It is possible to make it in the initializeAttribute method of the feature after
44 /// attribute creation
45 if (!aValueAttribute->isInitialized()) {
46 aValueAttribute->setValue(myDefaultValue);
47 /// to update error state of the feature: previous value was that this attribute is not
48 /// initialized yet. Apply of Property panel was disabled.
49 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
52 int aValueId = aValueAttribute->value();
53 myComboBox->setCurrentIndex(aValueId);
56 void SamplePanelPlugin_Panel::onCurrentIndexChanged(int theIndex)
61 AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
62 AttributeIntegerPtr aValueAttribute =
63 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
64 aValueAttribute->setValue(theIndex);
65 Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));