1 // File: ModuleBase_WidgetChoice.cpp
2 // Created: 03 Sept 2014
3 // Author: Vitaly Smetannikov
5 #include "ModuleBase_WidgetChoice.h"
7 #include <ModelAPI_AttributeInteger.h>
8 #include <ModelAPI_Data.h>
9 #include <Config_WidgetAPI.h>
16 ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
17 const Config_WidgetAPI* theData,
18 const std::string& theParentId)
19 : ModuleBase_ModelWidget(theParent, theData, theParentId)
21 myContainer = new QWidget(theParent);
22 QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
23 aLayout->setContentsMargins(0, 0, 0, 0);
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);
32 myCombo = new QComboBox(myContainer);
33 aLayout->addWidget(myCombo, 1);
35 std::string aTypes = theData->getProperty("string_list");
36 QStringList aList = QString(aTypes.c_str()).split(' ');
37 myCombo->addItems(aList);
39 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
42 ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
46 bool ModuleBase_WidgetChoice::storeValue() const
48 DataPtr aData = myFeature->data();
49 boost::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
51 aIntAttr->setValue(myCombo->currentIndex());
52 updateObject(myFeature);
56 bool ModuleBase_WidgetChoice::restoreValue()
58 DataPtr aData = myFeature->data();
59 boost::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
61 bool isBlocked = myCombo->blockSignals(true);
62 myCombo->setCurrentIndex(aIntAttr->value());
63 myCombo->blockSignals(isBlocked);
67 bool ModuleBase_WidgetChoice::focusTo()
73 QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
75 QList<QWidget*> aControls;
76 aControls.append(myLabel);
77 aControls.append(myCombo);
81 void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
84 emit focusOutWidget(this);