From 3f24e90e54348a9e4d93adb08759361fce8716d4 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 10 Sep 2014 17:55:25 +0400 Subject: [PATCH] Update preferences on plug-in loading --- src/Model/Model_PluginManager.cpp | 3 +++ src/ModelAPI/ModelAPI_Events.h | 2 ++ src/NewGeom/NewGeom_Module.cpp | 12 ++++++++++-- src/XGUI/XGUI_SalomeConnector.h | 2 ++ src/XGUI/XGUI_Workshop.cpp | 14 +++++++++++++- src/XGUI/XGUI_Workshop.h | 4 +++- 6 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/Model/Model_PluginManager.cpp b/src/Model/Model_PluginManager.cpp index 06893e6fc..ad5767a5a 100644 --- a/src/Model/Model_PluginManager.cpp +++ b/src/Model/Model_PluginManager.cpp @@ -159,6 +159,9 @@ void Model_PluginManager::LoadPluginsInfo() void Model_PluginManager::registerPlugin(ModelAPI_Plugin* thePlugin) { myPluginObjs[myCurrentPluginName] = thePlugin; + static Events_ID EVENT_LOAD = Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED); + ModelAPI_EventCreator::get()->sendUpdated(ObjectPtr(), EVENT_LOAD); + Events_Loop::loop()->flush(EVENT_LOAD); } ModelAPI_ValidatorsFactory* Model_PluginManager::validators() diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 89b1fd5b9..c35573168 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -27,6 +27,8 @@ static const char * EVENT_OBJECT_MOVED = "ObjectsMoved"; static const char * EVENT_OBJECT_TO_REDISPLAY = "ObjectsToRedisplay"; /// Event ID that visualization must be redisplayed (comes with ModelAPI_ObjectUpdatedMessage) static const char * EVENT_OPERATION_LAUNCHED = "OperationLaunched"; +/// Event ID that plugin is loaded (comes with ModelAPI_ObjectUpdatedMessage) +static const char * EVENT_PLUGIN_LOADED = "PliginLoaded"; /// Message that feature was changed (used for Object Browser update): moved, updated and deleted class ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup diff --git a/src/NewGeom/NewGeom_Module.cpp b/src/NewGeom/NewGeom_Module.cpp index dd97f0fc5..1caf55c95 100644 --- a/src/NewGeom/NewGeom_Module.cpp +++ b/src/NewGeom/NewGeom_Module.cpp @@ -286,10 +286,18 @@ void NewGeom_Module::createPreferences() { XGUI_Preferences::updateCustomProps(); LightApp_Preferences* pref = preferences(); - int catId = pref->addPreference( moduleName(), -1 ); + QString aModName = moduleName(); + + QtxPreferenceItem* item = pref->findItem(aModName, true ); + if ( item && (!item->isEmpty() )) { + item->parentItem()->removeItem(item); + delete item; + } + + int catId = pref->addPreference(aModName, -1 ); if ( catId == -1 ) return; - NewGeom_PrefMgr aMgr(pref, moduleName()); + NewGeom_PrefMgr aMgr(pref, aModName); XGUI_Preferences::createEditContent(&aMgr, catId); pref->retrieve(); } diff --git a/src/XGUI/XGUI_SalomeConnector.h b/src/XGUI/XGUI_SalomeConnector.h index 58489c127..0055714b7 100644 --- a/src/XGUI/XGUI_SalomeConnector.h +++ b/src/XGUI/XGUI_SalomeConnector.h @@ -69,6 +69,8 @@ class XGUI_EXPORT XGUI_SalomeConnector //! Returns interface to Salome viewer virtual XGUI_SalomeViewer* viewer() const = 0; + + virtual void createPreferences() = 0; }; #endif diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index fec644039..a2c6ff0f0 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -86,7 +86,8 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector) mySalomeConnector(theConnector), myPropertyPanel(0), myObjectBrowser(0), - myDisplayer(0) + myDisplayer(0), + myUpdatePrefs(false) { myMainWindow = mySalomeConnector ? 0 : new XGUI_MainWindow(); @@ -139,6 +140,7 @@ void XGUI_Workshop::startApplication() aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_DELETED)); aLoop->registerListener(this, Events_Loop::eventByName("LongOperation")); + aLoop->registerListener(this, Events_Loop::eventByName(EVENT_PLUGIN_LOADED)); registerValidators(); activateModule(); @@ -243,6 +245,15 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) const ModelAPI_ObjectUpdatedMessage* aUpdMsg = dynamic_cast(theMessage); onFeatureCreatedMsg(aUpdMsg); + if (myUpdatePrefs) { + if (mySalomeConnector) + mySalomeConnector->createPreferences(); + myUpdatePrefs = false; + } + return; + } + if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_PLUGIN_LOADED)) { + myUpdatePrefs = true; return; } @@ -302,6 +313,7 @@ void XGUI_Workshop::processEvent(const Events_Message* theMessage) } } + //****************************************************** void XGUI_Workshop::onStartWaiting() { diff --git a/src/XGUI/XGUI_Workshop.h b/src/XGUI/XGUI_Workshop.h index 95644a07f..dbf160d15 100644 --- a/src/XGUI/XGUI_Workshop.h +++ b/src/XGUI/XGUI_Workshop.h @@ -208,7 +208,7 @@ signals: void displayDocumentResults(DocumentPtr theDoc); void displayGroupResults(DocumentPtr theDoc, std::string theGroup); - protected slots: + private slots: /// SLOT, that is called after the operation is started. Update workshop state according to /// the started operation, e.g. visualizes the property panel and connect to it. void onOperationStarted(); @@ -253,6 +253,8 @@ signals: QString myCurrentDir; static QMap myIcons; + + bool myUpdatePrefs; }; #endif -- 2.39.2