1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModuleBase_WidgetChoice.cpp
4 // Created: 03 Sept 2014
5 // Author: Vitaly Smetannikov
7 #include "ModuleBase_WidgetChoice.h"
8 #include <ModuleBase_Tools.h>
10 #include <ModelAPI_AttributeInteger.h>
11 #include <ModelAPI_Data.h>
12 #include <Config_WidgetAPI.h>
19 ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
20 const Config_WidgetAPI* theData,
21 const std::string& theParentId)
22 : ModuleBase_ModelWidget(theParent, theData, theParentId)
24 myContainer = new QWidget(theParent);
25 QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
26 ModuleBase_Tools::adjustMargins(aLayout);
28 QString aLabelText = QString::fromStdString(theData->widgetLabel());
29 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
30 myLabel = new QLabel(aLabelText, myContainer);
31 if (!aLabelIcon.isEmpty())
32 myLabel->setPixmap(QPixmap(aLabelIcon));
33 aLayout->addWidget(myLabel);
35 myCombo = new QComboBox(myContainer);
36 aLayout->addWidget(myCombo, 1);
38 std::string aTypes = theData->getProperty("string_list");
39 QStringList aList = QString(aTypes.c_str()).split(' ');
40 myCombo->addItems(aList);
42 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
45 ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
49 bool ModuleBase_WidgetChoice::storeValue() const
51 DataPtr aData = myFeature->data();
52 std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
54 aIntAttr->setValue(myCombo->currentIndex());
55 updateObject(myFeature);
59 bool ModuleBase_WidgetChoice::restoreValue()
61 DataPtr aData = myFeature->data();
62 std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
64 bool isBlocked = myCombo->blockSignals(true);
65 myCombo->setCurrentIndex(aIntAttr->value());
66 myCombo->blockSignals(isBlocked);
70 bool ModuleBase_WidgetChoice::focusTo()
76 QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
78 QList<QWidget*> aControls;
79 aControls.append(myCombo);
83 void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
86 // Don't transfer focus
87 // emit focusOutWidget(this);