From c21ad98366ab170289e75ce6eb54239785dca7e1 Mon Sep 17 00:00:00 2001 From: vsv Date: Fri, 2 Nov 2018 13:23:23 +0300 Subject: [PATCH] Save/Restore toolbars configuration --- src/SHAPERGUI/SHAPERGUI.cpp | 90 +++++++++++++++++++++-- src/SHAPERGUI/SHAPERGUI.h | 4 + src/XGUI/XGUI_pictures.qrc | 1 + src/XGUI/pictures/configure_toolbars.png | Bin 0 -> 703 bytes 4 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 src/XGUI/pictures/configure_toolbars.png 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 0000000000000000000000000000000000000000..5d468bd8bcec26b7aa2027163bcda73e0bb6bed4 GIT binary patch literal 703 zcmV;w0zmzVP)itIuCIl|VR2D9{~C=(BR9F_<>l96dwcsiunq+760mI>DJ7v$h~3>?bX^A^m&;vW zUR~J|SRWaA67YJx05qGwZwa*9EmEn^08C9yVObXKcAJNf{DYNBMfLyzkHdE8|UayB>Fi19= z<>=@LpU+1olOY_Qq|vC;5zx>y!TEX7>2YW06N7{IF${yl!$XdbbIi=lP^;CLoP355 zg1x;o&JTnTjEx15QX`p6GBD7OVHjjG8P3kmn4g~qptra8){Gp1X0yS`Ngms_ak=g} zm5aq9b8~Zl?M67S9w1+>R&cxBl*?s=5Dt8CQ6>_J{4-c7HLBGLK;F57)6>(y=;$bh zVQ_G8!2bR|rfJ@JTph~;uTV;{w6wHfSyro1D5yjt(K1alrj()^XK``y<<{0#qEIOO zipS$E(=^|73oE5yb#?WfQi_d@jksx=3;zQvr4TDCD