Salome HOME
Opportunity for combo box of getting elements from the feature another attribute.
[modules/shaper.git] / src / ModuleBase / ModuleBase_WidgetChoice.cpp
index 1bc6987e13ca85abce3a4453421d18871d0226da..c4d642eaa507f7170e272f410efc708dd191b68a 100644 (file)
 #include "ModuleBase_IconFactory.h"
 
 #include <ModelAPI_AttributeInteger.h>
+#include <ModelAPI_AttributeStringArray.h>
 #include <ModelAPI_Data.h>
 #include <Config_WidgetAPI.h>
+#include <Config_PropManager.h>
 
 #include <QWidget>
 #include <QLayout>
@@ -35,7 +37,6 @@
 #include <QRadioButton>
 #include <QToolButton>
 
-
 ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
                                                  const Config_WidgetAPI* theData)
 : ModuleBase_ModelWidget(theParent, theData), myCombo(0), myButtons(0)
@@ -51,7 +52,11 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
   foreach(QString aType, QString(aTypes.c_str()).split(' ')) {
     aList.append(translate(aType.toStdString()));
   }
-
+  if (aTypes.empty()) {
+    myStringListAttribute = theData->getProperty("string_list_attribute");
+    if (!myStringListAttribute.empty())
+      aList.clear();
+  }
   if (theData->getBooleanAttribute("use_in_title", false))
     myButtonTitles = aList;
 
@@ -149,6 +154,14 @@ bool ModuleBase_WidgetChoice::restoreValueCustom()
 
   if (aIntAttr->value() != -1) {
     if (myCombo) {
+      if (myCombo->count() == 0 && !myStringListAttribute.empty()) {
+        AttributeStringArrayPtr aStrAttr = aData->stringArray(myStringListAttribute);
+        if (aStrAttr) {
+          for (int i = 0; i < aStrAttr->size(); i++) {
+            myCombo->insertItem(i, aStrAttr->value(i).c_str());
+          }
+        }
+      }
       bool isBlocked = myCombo->blockSignals(true);
       myCombo->setCurrentIndex(aIntAttr->value());
       myCombo->blockSignals(isBlocked);