From: vsv Date: Fri, 2 Nov 2018 10:23:23 +0000 (+0300) Subject: Save/Restore toolbars configuration X-Git-Tag: Jan2019~38^2~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c21ad98366ab170289e75ce6eb54239785dca7e1;p=modules%2Fshaper.git Save/Restore toolbars configuration --- diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index 53c7fcbbf..1a1004970 100644 --- a/src/SHAPERGUI/SHAPERGUI.cpp +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -124,7 +124,7 @@ private: SHAPERGUI::SHAPERGUI() : LightApp_Module("SHAPER"), mySelector(0), myIsOpened(0), myPopupMgr(0), myIsInspectionVisible(false), - myInspectionPanel(0) + myInspectionPanel(0), myIsToolbarsModified(false) { myWorkshop = new XGUI_Workshop(this); connect(myWorkshop, SIGNAL(commandStatusUpdated()), @@ -175,10 +175,10 @@ void SHAPERGUI::initialize(CAM_Application* theApp) // Define Edit toolbars command aId = getNextCommandId(); - myActionsList.append(aId); + //myActionsList.append(aId); Do not use it for editing of toolbars aTip = tr("Edit toolbars of the module"); - QAction* aAction = createAction(aId, aTip, QIcon(), tr("Edit toolbars..."), - aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars())); + QAction* aAction = createAction(aId, aTip, QIcon(":pictures/configure_toolbars.png"), + tr("Edit toolbars..."), aTip, QKeySequence(), aDesk, false, this, SLOT(onEditToolbars())); int aEditMenu = createMenu(tr("MEN_DESK_EDIT"), -1, -1, 30); int aEditItem = createMenu(aId, aEditMenu); } @@ -223,6 +223,8 @@ void SHAPERGUI::viewManagers(QStringList& theList) const bool SHAPERGUI::activateModule(SUIT_Study* theStudy) { bool isDone = LightApp_Module::activateModule(theStudy); + loadToolbarsConfig(); + SHAPERGUI_DataModel* aDataModel = dynamic_cast(dataModel()); aDataModel->initRootObject(); @@ -332,6 +334,8 @@ bool SHAPERGUI::activateModule(SUIT_Study* theStudy) //****************************************************** bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) { + saveToolbarsConfig(); + myProxyViewer->activateViewer(false); setMenuShown(false); setToolShown(false); @@ -390,7 +394,6 @@ bool SHAPERGUI::deactivateModule(SUIT_Study* theStudy) connect(getApp()->action(LightApp_Application::FileSaveAsId), SIGNAL(triggered(bool)), getApp(), SLOT(onSaveAsDoc())); - return LightApp_Module::deactivateModule(theStudy); } @@ -855,7 +858,7 @@ void SHAPERGUI::updateToolbars(const QMap& theNewToolbars) aToolbarId = aMgr->createToolBar(aName); } int aPos = 0; - foreach (int aCmd, aCommands) { + foreach(int aCmd, aCommands) { // Find action if (aCmd == -1) aAction = separator(); @@ -887,11 +890,82 @@ void SHAPERGUI::updateToolbars(const QMap& theNewToolbars) } // Remove extra toolbars aToolbars = myToolbars.keys(); - QToolBar* aToolbar = 0; - QList aActionList; foreach(QString aName, aToolbars) { aMgr->removeToolBar(aName); } // Set new toolbars structure myToolbars = theNewToolbars; + myIsToolbarsModified = true; +} + +void SHAPERGUI::saveToolbarsConfig() +{ + if (!myIsToolbarsModified) + return; + // Set toolbars config + QMap aToolbarsConfig; + QtxActionToolMgr* aMgr = toolMgr(); + QStringList aToolbars = myToolbars.keys(); + QIntList aActionsIds; + foreach(QString aName, aToolbars) { + aActionsIds = myToolbars[aName]; + QStringList aContent; + foreach(int aId, aActionsIds) { + if (aId == -1) + aContent.append(""); + else + aContent.append(action(aId)->data().toString()); + } + aToolbarsConfig[aName] = aContent; + } + + SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); + QStringList aNames = aToolbarsConfig.keys(); + QStringList aValues; + const QString aSection("SHAPER_Toolbars"); + foreach(QString aToolbar, aNames) { + aResMgr->setValue(aSection, aToolbar, aToolbarsConfig[aToolbar].join(",")); + } + QStringList aOldParams = aResMgr->parameters(aSection); + foreach(QString aName, aOldParams) { + if (!aToolbars.contains(aName)) + aResMgr->remove(aSection, aName); + } + myIsToolbarsModified = false; +} + +void SHAPERGUI::loadToolbarsConfig() +{ + const QString aSection("SHAPER_Toolbars"); + SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); + QStringList aToolbarNames = aResMgr->parameters(aSection); + if (aToolbarNames.size() == 0) + return; + + QMap aCommandsMap; + QString aCmdIdStr; + foreach(int aId, myActionsList) { + aCmdIdStr = action(aId)->data().toString(); + aCommandsMap[aCmdIdStr] = aId; + } + + QMap aToolbars; + QStringList aCommands; + QList aActions; + foreach(QString aName, aToolbarNames) { + aCommands = aResMgr->stringValue(aSection, aName).split(","); + + aToolbars[aName] = QIntList(); + if (aCommands.size() > 0) { + foreach(QString aCommand, aCommands) { + if (aCommand.isEmpty()) + aToolbars[aName].append(-1); + else if (aCommandsMap.contains(aCommand)) { + aToolbars[aName].append(aCommandsMap[aCommand]); + } + } + } + } + updateToolbars(aToolbars); + myIsToolbarsModified = false; } diff --git a/src/SHAPERGUI/SHAPERGUI.h b/src/SHAPERGUI/SHAPERGUI.h index afcc55bf6..598c45023 100644 --- a/src/SHAPERGUI/SHAPERGUI.h +++ b/src/SHAPERGUI/SHAPERGUI.h @@ -226,6 +226,9 @@ private slots: // Update current toolbars void updateToolbars(const QMap& theNewToolbars); + void saveToolbarsConfig(); + void loadToolbarsConfig(); + /// List of registered nested actions QStringList myNestedActionsList; @@ -263,6 +266,7 @@ private slots: /// List of registered actions QIntList myActionsList; QMap myToolbars; + bool myIsToolbarsModified; }; #endif diff --git a/src/XGUI/XGUI_pictures.qrc b/src/XGUI/XGUI_pictures.qrc index 8ea63a1e0..c499b468f 100644 --- a/src/XGUI/XGUI_pictures.qrc +++ b/src/XGUI/XGUI_pictures.qrc @@ -82,5 +82,6 @@ pictures/arrow-right.png pictures/arrow-up.png pictures/arrow-down.png + pictures/configure_toolbars.png diff --git a/src/XGUI/pictures/configure_toolbars.png b/src/XGUI/pictures/configure_toolbars.png new file mode 100644 index 000000000..5d468bd8b Binary files /dev/null and b/src/XGUI/pictures/configure_toolbars.png differ