Salome HOME
fefb792d085d657ff85e92b0c0e130b0880575b7
[modules/shaper.git] / src / SamplePanelPlugin / SamplePanelPlugin_ModelWidget.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include <SamplePanelPlugin_ModelWidget.h>
22 #include <SamplePanelPlugin_Feature.h>
23
24 #include <ModelAPI_AttributeInteger.h>
25 #include <ModelAPI_Events.h>
26
27 #include <Config_WidgetAPI.h>
28 #include <Events_Loop.h>
29
30 #include <QVBoxLayout>
31 #include <QGridLayout>
32 #include <QLabel>
33 #include <QComboBox>
34
35 SamplePanelPlugin_ModelWidget::SamplePanelPlugin_ModelWidget(QWidget* theParent,
36                                                 const Config_WidgetAPI* theData)
37 : ModuleBase_ModelWidget(theParent, theData), myDefaultValue(0)
38 {
39   QVBoxLayout* aLay = new QVBoxLayout(this);
40   aLay->setContentsMargins(0, 0, 0, 0);
41
42   myMainWidget = new QWidget(this);
43   aLay->addWidget(myMainWidget);
44
45   QGridLayout* aLayout = new QGridLayout(myMainWidget);
46   aLayout->addWidget(new QLabel(tr("Values:")), 0, 0);
47
48   myComboBox = new QComboBox(myMainWidget);
49   myComboBox->addItem("Value_1");
50   myComboBox->addItem("Value_2");
51   myComboBox->addItem("Value_3");
52
53   connect(myComboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(valuesChanged()));
54   aLayout->addWidget(myComboBox, 0, 1);
55 }
56
57 QList<QWidget*> SamplePanelPlugin_ModelWidget::getControls() const
58 {
59   QList<QWidget*> aControls;
60   // this control will accept focus and will be highlighted in the Property Panel
61   aControls.push_back(myComboBox);
62   return aControls;
63 }
64
65 bool SamplePanelPlugin_ModelWidget::storeValueCustom()
66 {
67   AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
68   AttributeIntegerPtr aValueAttribute =
69                         std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
70   aValueAttribute->setValue(myComboBox->currentIndex());
71   updateObject(myFeature);
72   return true;
73 }
74
75 bool SamplePanelPlugin_ModelWidget::restoreValueCustom()
76 {
77   AttributePtr anAttribute = myFeature->attribute(SamplePanelPlugin_Feature::VALUE_ID());
78   AttributeIntegerPtr aValueAttribute =
79                         std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(anAttribute);
80
81   bool isBlocked = myComboBox->blockSignals(true);
82   myComboBox->setCurrentIndex(aValueAttribute->value());
83   myComboBox->blockSignals(isBlocked);
84
85   return true;
86 }
87