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 myCombo = new QComboBox(this);
35 aLayout->addWidget(myCombo, 1);
37 std::string aTypes = theData->getProperty("string_list");
38 QStringList aList = QString(aTypes.c_str()).split(' ');
39 myCombo->addItems(aList);
41 connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
44 ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
48 bool ModuleBase_WidgetChoice::storeValueCustom() const
50 DataPtr aData = myFeature->data();
51 std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
53 aIntAttr->setValue(myCombo->currentIndex());
54 updateObject(myFeature);
58 bool ModuleBase_WidgetChoice::restoreValueCustom()
60 DataPtr aData = myFeature->data();
61 std::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
63 bool isBlocked = myCombo->blockSignals(true);
64 myCombo->setCurrentIndex(aIntAttr->value());
65 myCombo->blockSignals(isBlocked);
69 bool ModuleBase_WidgetChoice::focusTo()
75 QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
77 QList<QWidget*> aControls;
78 aControls.append(myCombo);
82 void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
85 // Don't transfer focus
86 // emit focusOutWidget(this);