1 // File: ModuleBase_WidgetChoice.cpp
2 // Created: 03 Sept 2014
3 // Author: Vitaly Smetannikov
5 #include "ModuleBase_WidgetChoice.h"
6 #include <ModuleBase_Tools.h>
8 #include <ModelAPI_AttributeInteger.h>
9 #include <ModelAPI_Data.h>
10 #include <Config_WidgetAPI.h>
17 ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
18 const Config_WidgetAPI* theData,
19 const std::string& theParentId)
20 : ModuleBase_ModelWidget(theParent, theData, theParentId)
22 myContainer = new QWidget(theParent);
23 QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
24 ModuleBase_Tools::adjustMargins(aLayout);
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);
33 myCombo = new QComboBox(myContainer);
34 aLayout->addWidget(myCombo, 1);
36 std::string aTypes = theData->getProperty("string_list");
37 QStringList aList = QString(aTypes.c_str()).split(' ');
38 myCombo->addItems(aList);
40 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
43 ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
47 bool ModuleBase_WidgetChoice::storeValue() const
49 DataPtr aData = myFeature->data();
50 std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
52 aIntAttr->setValue(myCombo->currentIndex());
53 updateObject(myFeature);
57 bool ModuleBase_WidgetChoice::restoreValue()
59 DataPtr aData = myFeature->data();
60 std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
62 bool isBlocked = myCombo->blockSignals(true);
63 myCombo->setCurrentIndex(aIntAttr->value());
64 myCombo->blockSignals(isBlocked);
68 bool ModuleBase_WidgetChoice::focusTo()
74 QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
76 QList<QWidget*> aControls;
77 aControls.append(myCombo);
81 void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
84 // Don't transfer focus
85 // emit focusOutWidget(this);