From d4bcefd8d541bc7046f2bebf1ae3bed48e39cd0c Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 8 Nov 2017 19:16:41 +0300 Subject: [PATCH] Opportunity for combo box of getting elements from the feature another attribute. --- src/Config/Config_XMLReader.cpp | 16 +++++++++ src/Config/Config_XMLReader.h | 5 +++ src/ModuleBase/ModuleBase_WidgetChoice.cpp | 41 +++++++--------------- src/ModuleBase/ModuleBase_WidgetChoice.h | 1 + src/XGUI/XGUI_Workshop.cpp | 2 -- 5 files changed, 34 insertions(+), 31 deletions(-) diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 0ab7ce325..f7af50c8f 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -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; diff --git a/src/Config/Config_XMLReader.h b/src/Config/Config_XMLReader.h index 6b4fde6ba..ab067cd4b 100644 --- a/src/Config/Config_XMLReader.h +++ b/src/Config/Config_XMLReader.h @@ -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 diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp index 0930fa73b..c4d642eaa 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.cpp +++ b/src/ModuleBase/ModuleBase_WidgetChoice.cpp @@ -23,12 +23,11 @@ #include "ModuleBase_IconFactory.h" #include +#include #include #include #include -#include -#include #include #include #include @@ -36,28 +35,8 @@ #include #include #include -#include #include -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); diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.h b/src/ModuleBase/ModuleBase_WidgetChoice.h index cd0fa9521..a6ac35cfc 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.h +++ b/src/ModuleBase/ModuleBase_WidgetChoice.h @@ -100,6 +100,7 @@ private: // XML definition of titles QStringList myButtonTitles; + std::string myStringListAttribute; }; #endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 92158be6a..56f264361 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -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); -- 2.39.2