Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetChoice.cpp
index 6a1c455d905a2eb46d771bcc4218ddd6216f3d06..65c6c189077c27f97a42a1eeafac4bbfb49cddc3 100644 (file)
@@ -3,7 +3,10 @@
 // Author:      Vitaly Smetannikov
 
 #include "ModuleBase_WidgetChoice.h"
+#include <ModuleBase_Tools.h>
 
+#include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_Data.h>
 #include <Config_WidgetAPI.h>
 
 #include <QWidget>
@@ -18,16 +21,22 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
 {
   myContainer = new QWidget(theParent);
   QHBoxLayout* aLayout = new QHBoxLayout(myContainer);
-  aLayout->setContentsMargins(0, 0, 0, 0);
+  ModuleBase_Tools::adjustMargins(aLayout);
 
   QString aLabelText = QString::fromStdString(theData->widgetLabel());
   QString aLabelIcon = QString::fromStdString(theData->widgetIcon());
   myLabel = new QLabel(aLabelText, myContainer);
-  myLabel->setPixmap(QPixmap(aLabelIcon));
+  if (!aLabelIcon.isEmpty())
+    myLabel->setPixmap(QPixmap(aLabelIcon));
   aLayout->addWidget(myLabel);
 
   myCombo = new QComboBox(myContainer);
-  aLayout->addWidget(myCombo);
+  aLayout->addWidget(myCombo, 1);
+  std::string aTypes = theData->getProperty("string_list");
+  QStringList aList = QString(aTypes.c_str()).split(' ');
+  myCombo->addItems(aList);
+
   connect(myCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
 }
 
@@ -37,11 +46,22 @@ ModuleBase_WidgetChoice::~ModuleBase_WidgetChoice()
   
 bool ModuleBase_WidgetChoice::storeValue() const
 {
+  DataPtr aData = myFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
+
+  aIntAttr->setValue(myCombo->currentIndex());
+  updateObject(myFeature);
   return true;
 }
 
 bool ModuleBase_WidgetChoice::restoreValue()
 {
+  DataPtr aData = myFeature->data();
+  boost::shared_ptr<ModelAPI_AttributeInteger> aIntAttr = aData->integer(attributeID());
+
+  bool isBlocked = myCombo->blockSignals(true);
+  myCombo->setCurrentIndex(aIntAttr->value());
+  myCombo->blockSignals(isBlocked);
   return true;
 }
 
@@ -54,11 +74,12 @@ bool ModuleBase_WidgetChoice::focusTo()
 QList<QWidget*> ModuleBase_WidgetChoice::getControls() const
 {
   QList<QWidget*> aControls;
-  aControls.append(myLabel);
   aControls.append(myCombo);
   return aControls;
 }
 
 void ModuleBase_WidgetChoice::onCurrentIndexChanged(int theIndex)
 {
-}
\ No newline at end of file
+  emit valuesChanged();
+  emit focusOutWidget(this);
+}