Salome HOME
Issue #1735: Names in deflection dialog box.
[modules/shaper.git] / src / SamplePanelPlugin / SamplePanelPlugin_ModelWidget.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:        SamplePanelPlugin_PageGroupBox.h
4 // Created:     29 Mar 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <SamplePanelPlugin_ModelWidget.h>
8 #include <SamplePanelPlugin_Feature.h>
9
10 #include <ModelAPI_AttributeInteger.h>
11 #include <ModelAPI_Events.h>
12
13 #include <Config_WidgetAPI.h>
14 #include <Events_Loop.h>
15
16 #include <QVBoxLayout>
17 #include <QGridLayout>
18 #include <QLabel>
19 #include <QComboBox>
20
21 SamplePanelPlugin_ModelWidget::SamplePanelPlugin_ModelWidget(QWidget* theParent,
22                                                 const Config_WidgetAPI* theData)
23 : ModuleBase_ModelWidget(theParent, theData), myDefaultValue(0)
24 {
25   QVBoxLayout* aLay = new QVBoxLayout(this);
26   aLay->setContentsMargins(0, 0, 0, 0);
27
28   myMainWidget = new QWidget(this);
29   aLay->addWidget(myMainWidget);
30
31   QGridLayout* aLayout = new QGridLayout(myMainWidget);
32   aLayout->addWidget(new QLabel(tr("Values:")), 0, 0);
33
34   myComboBox = new QComboBox(myMainWidget);
35   myComboBox->addItem("Value_1");
36   myComboBox->addItem("Value_2");
37   myComboBox->addItem("Value_3");
38
39   connect(myComboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(valuesChanged()));
40   aLayout->addWidget(myComboBox, 0, 1);
41 }
42
43 QList<QWidget*> SamplePanelPlugin_ModelWidget::getControls() const
44 {
45   QList<QWidget*> aControls;
46   // this control will accept focus and will be highlighted in the Property Panel
47   aControls.push_back(myComboBox);
48   return aControls;
49 }
50
51 bool SamplePanelPlugin_ModelWidget::storeValueCustom()
52 {
53   AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
54   AttributeIntegerPtr aValueAttribute =
55                         std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
56   aValueAttribute->setValue(myComboBox->currentIndex());
57   updateObject(myFeature);
58   return true;
59 }
60
61 bool SamplePanelPlugin_ModelWidget::restoreValueCustom()
62 {
63   AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
64   AttributeIntegerPtr aValueAttribute =
65                         std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
66
67   bool isBlocked = myComboBox->blockSignals(true);
68   myComboBox->setCurrentIndex(aValueAttribute->value());
69   myComboBox->blockSignals(isBlocked);
70
71   return true;
72 }
73