]> SALOME platform Git repositories - modules/shaper.git/blob - src/ModuleBase/ModuleBase_WidgetChoice.cpp
Salome HOME
Boolean operations created
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetChoice.cpp
1 // File:        ModuleBase_WidgetChoice.cpp
2 // Created:     03 Sept 2014
3 // Author:      Vitaly Smetannikov
4
5 #include "ModuleBase_WidgetChoice.h"
6
7 #include <ModelAPI_AttributeInteger.h>
8 #include <ModelAPI_Data.h>
9 #include <Config_WidgetAPI.h>
10
11 #include <QWidget>
12 #include <QLayout>
13 #include <QLabel>
14 #include <QComboBox>
15
16 ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, 
17                                                  const Config_WidgetAPI* theData, 
18                                                  const std::string& theParentId)
19     : ModuleBase_ModelWidget(theParent, theData, theParentId)
20 {
21   myContainer = new QWidget(theParent);
22   QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
23   aLayout->setContentsMargins(0, 0, 0, 0);
24
25   QString aLabelText = QString::fromStdString(theData->widgetLabel());
26   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
27   myLabel = new QLabel(aLabelText, myContainer);
28   if (!aLabelIcon.isEmpty())
29     myLabel->setPixmap(QPixmap(aLabelIcon));
30   aLayout->addWidget(myLabel);
31
32   myCombo = new QComboBox(myContainer);
33   aLayout->addWidget(myCombo, 1);
34  
35   std::string aTypes = theData->getProperty("string_list");
36   QStringList aList = QString(aTypes.c_str()).split(' ');
37   myCombo->addItems(aList);
38
39   connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
40 }
41
42 ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
43 {
44 }
45   
46 bool ModuleBase_WidgetChoice::storeValue() const
47 {
48   DataPtr aData = myFeature->data();
49   boost::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
50
51   aIntAttr->setValue(myCombo->currentIndex());
52   updateObject(myFeature);
53   return true;
54 }
55
56 bool ModuleBase_WidgetChoice::restoreValue()
57 {
58   DataPtr aData = myFeature->data();
59   boost::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
60
61   bool isBlocked = myCombo->blockSignals(true);
62   myCombo->setCurrentIndex(aIntAttr->value());
63   myCombo->blockSignals(isBlocked);
64   return true;
65 }
66
67 bool ModuleBase_WidgetChoice::focusTo()
68 {
69   myCombo->setFocus();
70   return true;
71 }
72
73 QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
74 {
75   QList<QWidget*> aControls;
76   aControls.append(myLabel);
77   aControls.append(myCombo);
78   return aControls;
79 }
80
81 void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
82 {
83   emit valuesChanged();
84   emit focusOutWidget(this);
85 }