From: nds Date: Thu, 2 Nov 2017 12:31:35 +0000 (+0300) Subject: ModuleBase_WidgetChoice is extended to use in a combo box a list of values read from... X-Git-Tag: V_2.10.0RC~177 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8f8d5744ae689e0715519aa0edd1f903195529bf;p=modules%2Fshaper.git ModuleBase_WidgetChoice is extended to use in a combo box a list of values read from a file (each file row is an item) ModuleBase_WidgetFileSelector uses "import_initial_path" key for QFileDialog initial directory. --- diff --git a/src/ModuleBase/ModuleBase_WidgetChoice.cpp b/src/ModuleBase/ModuleBase_WidgetChoice.cpp index 1bc6987e1..0930fa73b 100644 --- a/src/ModuleBase/ModuleBase_WidgetChoice.cpp +++ b/src/ModuleBase/ModuleBase_WidgetChoice.cpp @@ -25,7 +25,10 @@ #include #include #include +#include +#include +#include #include #include #include @@ -33,8 +36,27 @@ #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) @@ -51,6 +73,14 @@ ModuleBase_WidgetChoice::ModuleBase_WidgetChoice(QWidget* theParent, foreach(QString aType, QString(aTypes.c_str()).split(' ')) { 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); + } + } if (theData->getBooleanAttribute("use_in_title", false)) myButtonTitles = aList; diff --git a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp index 57db592c3..c7e1c0df9 100644 --- a/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFileSelector.cpp @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -49,6 +50,9 @@ ModuleBase_WidgetFileSelector::ModuleBase_WidgetFileSelector(QWidget* theParent, myType = (theData->getProperty("type") == "save") ? WFS_SAVE : WFS_OPEN; myDefaultPath = QString::fromStdString(theData->getProperty("path")); + if (myDefaultPath.isEmpty()) + myDefaultPath = Config_PropManager::string("Plugins", "import_initial_path").c_str(); + QGridLayout* aMainLay = new QGridLayout(this); ModuleBase_Tools::adjustMargins(aMainLay); QLabel* aTitleLabel = new QLabel(myTitle, this); diff --git a/src/XGUI/CMakeLists.txt b/src/XGUI/CMakeLists.txt index 9663e386a..7f0fe59ff 100644 --- a/src/XGUI/CMakeLists.txt +++ b/src/XGUI/CMakeLists.txt @@ -164,7 +164,7 @@ SOURCE_GROUP ("Generated Files" FILES ${PROJECT_AUTOMOC} ${PROJECT_COMPILED_RESO #SOURCE_GROUP ("Generated Files" FILES ${PROJECT_AUTOMOC} ${PROJECT_COMPILED_RESOURCES}) SOURCE_GROUP ("Resource Files" FILES ${TEXT_RESOURCES} ${PROJECT_RESOURCES} ${PREFERENCES_XML}) -ADD_DEFINITIONS( -DXGUI_EXPORTS ${CAS_DEFINITIONS} ) +ADD_DEFINITIONS( -DXGUI_EXPORTS ${CAS_DEFINITIONS} -D_CRT_SECURE_NO_WARNINGS) SET(PROJECT_INCLUDES ${PROJECT_SOURCE_DIR}/src/Events diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index 737d28e91..43f6f446e 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -295,7 +295,17 @@ void XGUI_Workshop::startApplication() Config_PropManager::registerProp("Plugins", "default_path", "Default Path", Config_Prop::Directory, ""); + QString aDefaultPath = QString("%1Resources").arg(ModuleBase_Preferences::resourceMgr()->appName()); + std::string aDir = getenv(aDefaultPath.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); +#ifdef _DEBUG + Config_PropManager::registerProp("Plugins", "create_part_by_start", "Create Part by Start", + Config_Prop::Boolean, "false"); +#endif registerValidators(); // Calling of loadCustomProps before activating module is required @@ -315,6 +325,13 @@ void XGUI_Workshop::startApplication() SLOT(onTrihedronVisibilityChanged(bool))); emit applicationStarted(); + +#ifdef _DEBUG + bool aNewPart = Config_PropManager::boolean("Plugins", "create_part_by_start"); + if (aNewPart) { + module()->launchOperation("Part", false); + } +#endif } void XGUI_Workshop::activateModule()