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 QHBoxLayout* aLayout = new QHBoxLayout(this);
25 ModuleBase_Tools::adjustMargins(aLayout);
27 QString aLabelText = QString::fromStdString(theData->widgetLabel());
28 QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
29 myLabel = new QLabel(aLabelText, this);
30 if (!aLabelIcon.isEmpty())
31 myLabel->setPixmap(QPixmap(aLabelIcon));
32 aLayout->addWidget(myLabel);
34 std::string aToolstr = theData->widgetTooltip();
35 if (!aToolstr.empty()) {
36 myLabel->setToolTip(QString::fromStdString(aToolstr));
39 myCombo = new QComboBox(this);
40 aLayout->addWidget(myCombo, 1);
42 std::string aTypes = theData->getProperty("string_list");
43 QStringList aList = QString(aTypes.c_str()).split(' ');
44 myCombo->addItems(aList);
46 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
49 ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
53 bool ModuleBase_WidgetChoice::storeValueCustom() const
55 DataPtr aData = myFeature->data();
56 std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
58 aIntAttr->setValue(myCombo->currentIndex());
59 updateObject(myFeature);
63 bool ModuleBase_WidgetChoice::restoreValueCustom()
65 DataPtr aData = myFeature->data();
66 std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
68 bool isBlocked = myCombo->blockSignals(true);
69 myCombo->setCurrentIndex(aIntAttr->value());
70 myCombo->blockSignals(isBlocked);
74 bool ModuleBase_WidgetChoice::focusTo()
80 QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
82 QList<QWidget*> aControls;
83 aControls.append(myCombo);
87 void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
90 // Don't transfer focus
91 // emit focusOutWidget(this);