Salome HOME
Save/Restore toolbars configuration
authorvsv <vsv@opencascade.com>
Fri, 2 Nov 2018 10:23:23 +0000 (13:23 +0300)
committervsv <vsv@opencascade.com>
Fri, 2 Nov 2018 10:23:23 +0000 (13:23 +0300)
src/SHAPERGUI/SHAPERGUI.cpp
src/SHAPERGUI/SHAPERGUI.h
src/XGUI/XGUI_pictures.qrc
src/XGUI/pictures/configure_toolbars.png [new file with mode: 0644]

index 53c7fcbbf83d608f45ca3f0cce196a810aeb3e1e..1a1004970a11405ff923ee909e8bbfc9529c04c7 100644 (file)
@@ -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<SHAPERGUI_DataModel*>(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<QString, QIntList>& 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<QString, QIntList>& theNewToolbars)
   }
   // Remove extra toolbars
   aToolbars = myToolbars.keys();
-  QToolBar* aToolbar = 0;
-  QList<QAction*> 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<QString, QStringList> 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<QString, int> aCommandsMap;
+  QString aCmdIdStr;
+  foreach(int aId, myActionsList) {
+    aCmdIdStr = action(aId)->data().toString();
+    aCommandsMap[aCmdIdStr] = aId;
+  }
+
+  QMap<QString, QIntList> aToolbars;
+  QStringList aCommands;
+  QList<QAction*> 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;
 }
index afcc55bf61be8718fb433ff0ec3accf8fea63e74..598c4502335dfe6fe7aaf0df699748bbc1185086 100644 (file)
@@ -226,6 +226,9 @@ private slots:
   // Update current toolbars
   void updateToolbars(const QMap<QString, QIntList>& 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<QString, QIntList> myToolbars;
+  bool myIsToolbarsModified;
 };
 
 #endif
index 8ea63a1e068ae987d4fc4780463334a7bcb332a9..c499b468f6c8a9b97441fb0f79326ad51ed55565 100644 (file)
@@ -82,5 +82,6 @@
      <file>pictures/arrow-right.png</file>
      <file>pictures/arrow-up.png</file>
      <file>pictures/arrow-down.png</file>
+     <file>pictures/configure_toolbars.png</file>
  </qresource>
  </RCC>
diff --git a/src/XGUI/pictures/configure_toolbars.png b/src/XGUI/pictures/configure_toolbars.png
new file mode 100644 (file)
index 0000000..5d468bd
Binary files /dev/null and b/src/XGUI/pictures/configure_toolbars.png differ