From: vsv Date: Tue, 6 Nov 2018 12:12:37 +0000 (+0300) Subject: Provide show new and delete obsolete commands in toolbars. X-Git-Tag: Jan2019~38^2~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=67f3d1f9daf5dbbec9b01664435e8e76ea753ddb;p=modules%2Fshaper.git Provide show new and delete obsolete commands in toolbars. --- diff --git a/src/SHAPERGUI/SHAPERGUI.cpp b/src/SHAPERGUI/SHAPERGUI.cpp index 1a1004970..28f3de9a4 100644 --- a/src/SHAPERGUI/SHAPERGUI.cpp +++ b/src/SHAPERGUI/SHAPERGUI.cpp @@ -83,6 +83,11 @@ SHAPERGUI_EXPORT char* getModuleVersion() } } // extern "C" + +static const QString ToolbarsSection("SHAPER_Toolbars"); +static const QString FreeCommandsParam("OutOFToolbars"); + + /** * Class for preferences management */ @@ -902,7 +907,7 @@ void SHAPERGUI::saveToolbarsConfig() { if (!myIsToolbarsModified) return; - // Set toolbars config + // Save toolbars config into map QMap aToolbarsConfig; QtxActionToolMgr* aMgr = toolMgr(); QStringList aToolbars = myToolbars.keys(); @@ -918,30 +923,39 @@ void SHAPERGUI::saveToolbarsConfig() } aToolbarsConfig[aName] = aContent; } - + // Store the config into resources 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(",")); + aResMgr->setValue(ToolbarsSection, aToolbar, aToolbarsConfig[aToolbar].join(",")); } - QStringList aOldParams = aResMgr->parameters(aSection); + // Remove obsolete parameters from resources + QStringList aOldParams = aResMgr->parameters(ToolbarsSection); foreach(QString aName, aOldParams) { if (!aToolbars.contains(aName)) - aResMgr->remove(aSection, aName); + aResMgr->remove(ToolbarsSection, aName); } + // Store current list of free commands + QIntList aFreeCommands = getFreeCommands(); + QStringList aFreeList; + foreach(int aId, aFreeCommands) { + aFreeList.append(action(aId)->data().toString()); + } + if (aFreeList.size() > 0) + aResMgr->setValue(ToolbarsSection, FreeCommandsParam, aFreeList.join(",")); + myIsToolbarsModified = false; } void SHAPERGUI::loadToolbarsConfig() { - const QString aSection("SHAPER_Toolbars"); SUIT_ResourceMgr* aResMgr = application()->resourceMgr(); - QStringList aToolbarNames = aResMgr->parameters(aSection); + QStringList aToolbarNames = aResMgr->parameters(ToolbarsSection); if (aToolbarNames.size() == 0) return; + // Create commands map QMap aCommandsMap; QString aCmdIdStr; foreach(int aId, myActionsList) { @@ -949,19 +963,65 @@ void SHAPERGUI::loadToolbarsConfig() aCommandsMap[aCmdIdStr] = aId; } + // Create new toolbars structure QMap aToolbars; QStringList aCommands; + QIntList aKnownCommands; QList aActions; foreach(QString aName, aToolbarNames) { - aCommands = aResMgr->stringValue(aSection, aName).split(","); - - aToolbars[aName] = QIntList(); - if (aCommands.size() > 0) { + aCommands = aResMgr->stringValue(ToolbarsSection, aName).split(","); + if (aName == FreeCommandsParam) { + // The value is a list of free commands foreach(QString aCommand, aCommands) { - if (aCommand.isEmpty()) - aToolbars[aName].append(-1); - else if (aCommandsMap.contains(aCommand)) { - aToolbars[aName].append(aCommandsMap[aCommand]); + aKnownCommands.append(aCommandsMap[aCommand]); + } + } + else { + aToolbars[aName] = QIntList(); + if (aCommands.size() > 0) { + foreach(QString aCommand, aCommands) { + if (aCommand.isEmpty()) + aToolbars[aName].append(-1); + else if (aCommandsMap.contains(aCommand)) { + int aId = aCommandsMap[aCommand]; + aToolbars[aName].append(aId); + aKnownCommands.append(aId); + } + } + } + } + } + // Find new and obsolete commands + QIntList aNewCommands = myActionsList; + foreach(int aId, myActionsList) { + if (aKnownCommands.contains(aId)) { + aKnownCommands.removeAll(aId); + aNewCommands.removeAll(aId); + } + } + if (aNewCommands.size() > 0) { + // Add new commands to toolbars structure + QStringList aKeys = myToolbars.keys(); + foreach(int aNewId, aNewCommands) { + foreach(QString aName, aKeys) { + if (myToolbars[aName].contains(aNewId)) { + if (!aToolbars.contains(aName)) { + aToolbars[aName] = QIntList(); + } + aToolbars[aName].append(aNewId); + } + } + } + } + if (aKnownCommands.size() > 0) { + // Remove obsolete commands from the toolbars structure + QStringList aKeys = aToolbars.keys(); + foreach(int aOldId, aKnownCommands) { + foreach(QString aName, aKeys) { + if (aToolbars[aName].contains(aOldId)) { + aToolbars[aName].removeAll(aOldId); + if (aToolbars[aName].size() == 0) + aToolbars.remove(aName); } } } @@ -969,3 +1029,21 @@ void SHAPERGUI::loadToolbarsConfig() updateToolbars(aToolbars); myIsToolbarsModified = false; } + + +QIntList SHAPERGUI::getFreeCommands() const +{ + QIntList aFreeCommands; + QtxActionToolMgr* aMgr = toolMgr(); + QAction* anAction; + int aId; + QMap::const_iterator aIt; + QIntList aShaperActions = shaperActions(); + foreach(int aCmd, aShaperActions) { + anAction = action(aCmd); + aId = aMgr->actionId(anAction); + if (!aMgr->containsAction(aId)) + aFreeCommands.append(aCmd); + } + return aFreeCommands; +} diff --git a/src/SHAPERGUI/SHAPERGUI.h b/src/SHAPERGUI/SHAPERGUI.h index 598c45023..9504446a2 100644 --- a/src/SHAPERGUI/SHAPERGUI.h +++ b/src/SHAPERGUI/SHAPERGUI.h @@ -156,10 +156,14 @@ Q_OBJECT virtual void updateModuleVisibilityState(); - + /// Returns list of the module commands QIntList shaperActions() const { return myActionsList; } + + /// Returns structure of tool bars QMap shaperToolbars() const { return myToolbars; } + /// Returns free commands which are not in toolbars in the module + QIntList getFreeCommands() const; public slots: /// \brief The method is redefined to connect to the study viewer before the data diff --git a/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp index 673bab04e..e1e6b1137 100644 --- a/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp +++ b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.cpp @@ -82,7 +82,7 @@ SHAPERGUI_ToolbarsDlg::SHAPERGUI_ToolbarsDlg(SHAPERGUI* theModule) myModule(theModule), myResult(theModule->shaperToolbars()) { - myFreeCommands = getModuleFreeCommands(); + myFreeCommands = theModule->getFreeCommands(); setWindowTitle(tr("Toolbars")); QVBoxLayout* aMailLayout = new QVBoxLayout(this); @@ -211,23 +211,6 @@ void SHAPERGUI_ToolbarsDlg::updateToolbarsList() myToolbarsList->addItems(aItems); } -QIntList SHAPERGUI_ToolbarsDlg::getModuleFreeCommands() const -{ - QIntList aFreeCommands; - QtxActionToolMgr* aMgr = myModule->toolMgr(); - QAction* anAction; - int aId; - QMap::const_iterator aIt; - QIntList aShaperActions = myModule->shaperActions(); - foreach(int aCmd, aShaperActions) { - anAction = myModule->action(aCmd); - aId = aMgr->actionId(anAction); - if (!aMgr->containsAction(aId)) - aFreeCommands.append(aCmd); - } - return aFreeCommands; -} - void SHAPERGUI_ToolbarsDlg::onDoubleClick(const QModelIndex& theIdx) { diff --git a/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h index 9d6e77536..19d40013c 100644 --- a/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h +++ b/src/SHAPERGUI/SHAPERGUI_ToolbarsMgr.h @@ -124,9 +124,6 @@ private: /// Update number of free items void updateNumber(); - /// Returns free commands which are not in toolbars in the module - QIntList getModuleFreeCommands() const; - private: SHAPERGUI* myModule; QMap myResult;