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