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