Salome HOME
Opportunity for combo box of getting elements from the feature another attribute.
authornds <nds@opencascade.com>
Wed, 8 Nov 2017 16:16:41 +0000 (19:16 +0300)
committernds <nds@opencascade.com>
Wed, 8 Nov 2017 16:16:41 +0000 (19:16 +0300)
src/Config/Config_XMLReader.cpp
src/Config/Config_XMLReader.h
src/ModuleBase/ModuleBase_WidgetChoice.cpp
src/ModuleBase/ModuleBase_WidgetChoice.h
src/XGUI/XGUI_Workshop.cpp

index 0ab7ce325ab49fb54694def552a30ed183b7d54d..f7af50c8f21e7a9ead3ecf0652948525c84bbe84 100644 (file)
@@ -60,6 +60,22 @@ Config_XMLReader::~Config_XMLReader()
   xmlFreeDoc(myXmlDoc);
 }
 
+std::string Config_XMLReader::resourcesConfigFile()
+{
+  std::string aValue;
+  char* anEnv = getenv("SHAPER_ROOT_DIR");
+  if (anEnv) {
+    aValue = std::string(anEnv) +
+      FSEP + "share" + FSEP + "salome" + FSEP + "resources" + FSEP + "shaper";
+  } else {
+    anEnv = getenv("OPENPARTS_ROOT_DIR");
+    if (anEnv) {
+      aValue = std::string(anEnv) + FSEP + "resources";
+    }
+  }
+  return aValue;
+}
+
 std::string Config_XMLReader::pluginConfigFile()
 {
   std::string aValue;
index 6b4fde6ba7aa64fed52de459b502dd293357725c..ab067cd4bce224b276b14408f716e805dc38041d 100644 (file)
@@ -54,6 +54,11 @@ class Config_XMLReader
    */
   CONFIG_EXPORT Config_XMLReader(const std::string& theXmlFile);
   CONFIG_EXPORT virtual ~Config_XMLReader();
+  /*!
+   * Returns a path to resource files (created from ROOT_DIR environment variable)
+   * \return string value
+   */
+  CONFIG_EXPORT static std::string resourcesConfigFile();
   /*!
    * Returns a path to the plugins.xml file (created from ROOT_DIR environment variable)
    * \return string value
index 0930fa73b78497327fdb54d7b6d761a0f9174f46..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 <QDir>
-#include <QFile>
 #include <QWidget>
 #include <QLayout>
 #include <QLabel>
 #include <QButtonGroup>
 #include <QGroupBox>
 #include <QRadioButton>
-#include <QTextStream>
 #include <QToolButton>
 
-void getValues(const std::string& thePath, const std::string& theFileName,
-               QStringList& theValues)
-{
-  QString aFileName = thePath.c_str();
-  aFileName += QDir::separator();
-  aFileName += theFileName.c_str();
-
-  QFile aFile(aFileName);
-  if (!aFile.open(QIODevice::ReadOnly | QIODevice::Text))
-    return;
-
-  QTextStream aStream(&aFile);
-  while (!aStream.atEnd()) {
-    QString aLine = aStream.readLine();
-    if (!aLine.isEmpty())
-      theValues.append(aLine);
-  }
-}
-
 ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
                                                  const Config_WidgetAPI* theData)
 : ModuleBase_ModelWidget(theParent, theData), myCombo(0), myButtons(0)
@@ -74,14 +53,10 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent,
     aList.append(translate(aType.toStdString()));
   }
   if (aTypes.empty()) {
-    aList.clear();
-    std::string aFileName = theData->getProperty("file_name");
-    if (!aFileName.empty()) {
-      std::string aPath = Config_PropManager::string("Plugins", "combo_box_elements_path");
-      getValues(aPath, aFileName, aList);
-    }
+    myStringListAttribute = theData->getProperty("string_list_attribute");
+    if (!myStringListAttribute.empty())
+      aList.clear();
   }
-
   if (theData->getBooleanAttribute("use_in_title", false))
     myButtonTitles = aList;
 
@@ -179,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);
index cd0fa9521b1848d7b68b96f0164811d9bd31c8a9..a6ac35cfcf3eb5aa6205a21de6791d44ff202342 100644 (file)
@@ -100,6 +100,7 @@ private:
 
   // XML definition of titles
   QStringList myButtonTitles;
+  std::string myStringListAttribute;
 };
 
 #endif
index 92158be6a97c0cad763ef74aa9986b9328d56150..56f264361ea8e8903f10343c8b43333525e27f7f 100755 (executable)
@@ -297,8 +297,6 @@ void XGUI_Workshop::startApplication()
 
   std::string aDir = getenv(QString("%1Resources").arg(
     ModuleBase_Preferences::resourceMgr()->appName()).toLatin1());
-  Config_PropManager::registerProp("Plugins", "combo_box_elements_path",
-    "ComboBox elements directory", Config_Prop::Directory, aDir);
   Config_PropManager::registerProp("Plugins", "import_initial_path", "Import initial directory",
                                    Config_Prop::Directory, aDir);