]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #6 advanced command enable/disable state processing
authorsbh <sergey.belash@opencascade.com>
Mon, 28 Apr 2014 14:43:37 +0000 (18:43 +0400)
committersbh <sergey.belash@opencascade.com>
Mon, 28 Apr 2014 14:43:37 +0000 (18:43 +0400)
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_ActionsMgr.cpp [new file with mode: 0644]
src/XGUI/XGUI_ActionsMgr.h [new file with mode: 0644]
src/XGUI/XGUI_Command.cpp
src/XGUI/XGUI_MainMenu.cpp
src/XGUI/XGUI_MainMenu.h
src/XGUI/XGUI_MainWindow.h
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index c91631f06b3eb6e6ad7fae0466a893ce0b9b663e..58a0a9450cd182b24b8205c8d0db1fcebe5fcb43 100644 (file)
@@ -63,6 +63,11 @@ void PartSet_Module::featureCreated(XGUI_Command* theFeature)
   theFeature->connectTo(this, SLOT(onFeatureTriggered()));
 }
 
+QStringList PartSet_Module::nestedFeatures(QString)
+{
+  return QStringList();
+}
+
 std::string PartSet_Module::featureFile(const std::string& theFeatureId)
 {
   return myFeaturesInFiles[theFeatureId];
@@ -74,6 +79,9 @@ std::string PartSet_Module::featureFile(const std::string& theFeatureId)
 void PartSet_Module::onFeatureTriggered()
 {
   XGUI_Command* aCmd = dynamic_cast<XGUI_Command*>(sender());
+  //Do nothing on uncheck
+  if(aCmd->isCheckable() && !aCmd->isChecked())
+    return;
   launchOperation(aCmd->id());
 }
   
index 523a15ad210a702de378f66562dc510329ff97c5..cb86b7c4e833dfa90c1406fea4b0460d747dcba1 100644 (file)
@@ -21,6 +21,7 @@ public:
 
   virtual void createFeatures();
   virtual void featureCreated(XGUI_Command* theFeature);
+  virtual QStringList nestedFeatures(QString theFeature);
   std::string featureFile(const std::string&);
 
   virtual void launchOperation(const QString& theCmdId);
index 460458d1ab561bfc9abc421cca0a489eafa594ad..989980d3b6703be775e7e581dceab9942f963da5 100644 (file)
@@ -26,6 +26,7 @@ SET(PROJECT_HEADERS
     XGUI_DataTreeModel.h
     XGUI_SelectionMgr.h
     XGUI_SalomeConnector.h
+    XGUI_ActionsMgr.h
 )
 
 SET(PROJECT_AUTOMOC 
@@ -51,6 +52,7 @@ SET(PROJECT_SOURCES
        XGUI_ObjectsBrowser.cpp
        XGUI_OperationMgr.cpp
     XGUI_SelectionMgr.cpp
+    XGUI_ActionsMgr.cpp
 )
 
 SET(PROJECT_RESOURCES 
diff --git a/src/XGUI/XGUI_ActionsMgr.cpp b/src/XGUI/XGUI_ActionsMgr.cpp
new file mode 100644 (file)
index 0000000..0d652dc
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * XGUI_ActionsMgr.cpp
+ */
+
+#include <XGUI_ActionsMgr.h>
+#include <XGUI_Command.h>
+#include <QAction>
+
+
+XGUI_ActionsMgr::XGUI_ActionsMgr(QObject* theParent)
+ : QObject(theParent)
+{
+
+}
+
+XGUI_ActionsMgr::~XGUI_ActionsMgr()
+{
+}
+
+
+void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd)
+{
+  myActions.insert(theCmd->id(),theCmd);
+  myActionsState.insert(theCmd->id(), theCmd->enabled());
+  theCmd->connectTo(this, SLOT(setActionsDisabled(bool)));
+}
+
+void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
+{
+  //Re-enable actions (just restore their state)
+  if (!isDisabled) {
+    restoreCommandState();
+    return;
+  }
+  //Disable all actions, but caller and unblockable (defined in a xml)
+  saveCommandsState();
+  QStringList aSkippedIds;
+  XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
+  aSkippedIds.append(aToggledFeature->unblockableCommands());
+  aSkippedIds.append(aToggledFeature->id());
+  QStringList anActionIdsList = myActions.keys();
+  foreach(QString eachKey, anActionIdsList) {
+    if (aSkippedIds.removeAll(eachKey) > 0) {
+      continue;
+    }
+    myActions[eachKey]->setEnabled(false);
+  }
+}
+
+void XGUI_ActionsMgr::saveCommandsState()
+{
+  myActionsState.clear();
+  QStringList anActionIdsList = myActions.keys();
+  foreach(QString eachKey, anActionIdsList) {
+    myActionsState.insert(eachKey, myActions[eachKey]->isEnabled());
+  }
+
+}
+
+void XGUI_ActionsMgr::restoreCommandState()
+{
+  QStringList anActionIdsList = myActions.keys();
+  foreach(QString eachKey, anActionIdsList) {
+    myActions[eachKey]->setEnabled(myActionsState[eachKey]);
+    myActions[eachKey]->setChecked(false);
+  }
+}
diff --git a/src/XGUI/XGUI_ActionsMgr.h b/src/XGUI/XGUI_ActionsMgr.h
new file mode 100644 (file)
index 0000000..a3d7dea
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * XGUI_ActionsMgr.h
+ */
+
+#ifndef XGUI_ACTIONSMGR_H_
+#define XGUI_ACTIONSMGR_H_
+
+#include <QObject>
+#include <QMap>
+#include <QStringList>
+
+class XGUI_Command;
+class QAction;
+
+class XGUI_ActionsMgr: public QObject
+{
+  Q_OBJECT
+
+public:
+  XGUI_ActionsMgr(QObject* theParent);
+  virtual ~XGUI_ActionsMgr();
+
+  void addCommand(XGUI_Command* theCmd);
+  void restoreCommandState();
+  void saveCommandsState();
+
+public slots:
+  void setActionsDisabled(bool isEnabled);
+
+private:
+  QMap<QString, QAction*> myActions;
+  QMap<QString, bool> myActionsState;
+};
+
+#endif /* XGUI_ACTIONSMGR_H_ */
index ffd6ab103f7338b833a05020b60e635534532867..9b5dd7b9abfa4ea89a6e5e81f9e2ecbc529a0dab 100644 (file)
@@ -63,7 +63,7 @@ void XGUI_Command::disable()
 
 void XGUI_Command::connectTo(const QObject* theResiver, const char* theSlot)
 {
-    connect(this, SIGNAL(triggered()), theResiver, theSlot);
+    connect(this, SIGNAL(triggered(bool)), theResiver, theSlot);
 }
 
 const QStringList& XGUI_Command::unblockableCommands() const
index 96106a9111357da303ce4d14993cd204893aa057..4c8e7dc3c6ce612b6530213ce6c974f56ae5cdda 100644 (file)
@@ -91,48 +91,3 @@ QList<XGUI_Command*> XGUI_MainMenu::features() const
   return aList;
 }
 
-void XGUI_MainMenu::onFeatureChecked(bool isChecked)
-{
-  if (!isChecked) {
-    restoreCommandState();
-    return;
-  }
-
-  saveCommandsState();
-  QStringList aSkippedIds;
-  XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
-  aSkippedIds.append(aToggledFeature->unblockableCommands());
-//  aSkippedIds.append(aToggledFeature->id());
-  XGUI_Workbench* aGeneralWB = findWorkbench(tr("General"));
-  foreach(XGUI_Command* eachFeature, aGeneralWB->features()) {
-    aSkippedIds.append(eachFeature->id());
-  }
-  QList<XGUI_Command*> allFeatures = features();
-  foreach(XGUI_Command* eachFeature, allFeatures) {
-    QString aFeatureId = eachFeature->id();
-    if (aSkippedIds.removeAll(aFeatureId) > 0) {
-      continue;
-    }
-    eachFeature->setEnabled(false);
-  }
-}
-
-void XGUI_MainMenu::saveCommandsState()
-{
-  myCommandState.clear();
-  QList<XGUI_Command*> allFeatures = features();
-  XGUI_Command* eachFeature = NULL;
-  foreach(eachFeature, allFeatures) {
-    myCommandState.insert(eachFeature, eachFeature->enabled());
-  }
-}
-
-void XGUI_MainMenu::restoreCommandState()
-{
-  QList<XGUI_Command*> allFeatures = features();
-  XGUI_Command* eachFeature = NULL;
-  foreach(eachFeature, allFeatures) {
-    eachFeature->setChecked(false);
-    eachFeature->setEnabled(myCommandState[eachFeature]);
-  }
-}
index 0fed1a07ff64a11c83d68665cd2b1e11b11aac21..48d97459135f78be9f26e3f2b6a6d7450e10f833 100644 (file)
@@ -47,12 +47,6 @@ public:
   //! Returns list of created commands
   QList<XGUI_Command*> features() const;
 
-public slots:
-  void onFeatureChecked(bool);
-
-  void saveCommandsState();
-  void restoreCommandState();
-
   virtual bool eventFilter(QObject *theWatched, QEvent *theEvent);
 
 private:
index 553aa27358cf613de2479593b1897022770034e5..17357858d7a89abc248b8113be9392368966aaf0 100644 (file)
@@ -6,6 +6,7 @@
 
 class XGUI_MainMenu;
 class XGUI_Viewer;
+class XGUI_ActionsMgr;
 class QMdiArea;
 class PyConsole_EnhConsole;
 
@@ -43,7 +44,6 @@ public slots:
 
 private:
   XGUI_MainMenu* myMenuBar;
-
   XGUI_Viewer* myViewer;
 
   PyConsole_EnhConsole* myPythonConsole;
index b453a3ec935d363fe2fc0a4d78eb339869b1dab9..127949282264d046762516c3e67a01ff0d1b46b7 100644 (file)
@@ -14,6 +14,7 @@
 #include "XGUI_Displayer.h"
 #include "XGUI_OperationMgr.h"
 #include "XGUI_SalomeConnector.h"
+#include "XGUI_ActionsMgr.h"
 
 #include <ModelAPI_PluginManager.h>
 #include <ModelAPI_Feature.h>
@@ -60,6 +61,7 @@ XGUI_Workshop::XGUI_Workshop(XGUI_SalomeConnector* theConnector)
 
   mySelector = new XGUI_SelectionMgr(this);
   myOperationMgr = new XGUI_OperationMgr(this);
+  myActionsMgr = new XGUI_ActionsMgr(this);
   connect(myOperationMgr, SIGNAL(operationStarted()),  this, SLOT(onOperationStarted()));
   connect(myOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
@@ -230,10 +232,9 @@ void XGUI_Workshop::onOperationStopped(ModuleBase_Operation* theOperation)
     hidePropertyPanel();
     updateCommandStatus();
 
-  if (myMainWindow) {
-    XGUI_MainMenu* aMenu = myMainWindow->menuObject();
-    aMenu->restoreCommandState();
-  }
+    if (myMainWindow) {
+      myActionsMgr->restoreCommandState();
+    }
   }
 }
 
@@ -277,9 +278,7 @@ void XGUI_Workshop::addFeature(const Config_FeatureMessage* theMessage)
                                                 QString::fromStdString(theMessage->tooltip()),
                                                 QIcon(theMessage->icon().c_str()),
                                                 QKeySequence(), isUsePropPanel);
-    
-    connect(aCommand,                   SIGNAL(toggled(bool)),
-            myMainWindow->menuObject(), SLOT(onFeatureChecked(bool)));
+    myActionsMgr->addCommand(aCommand);
     myPartSetModule->featureCreated(aCommand);
   }
 }
@@ -304,7 +303,7 @@ void XGUI_Workshop::connectWithOperation(ModuleBase_Operation* theOperation)
     aCommand = aMenu->feature(theOperation->operationId());
   }
   //Abort operation on uncheck the command
-  connect(aCommand, SIGNAL(toggled(bool)), theOperation, SLOT(setRunning(bool)));
+  connect(aCommand, SIGNAL(triggered(bool)), theOperation, SLOT(setRunning(bool)));
 }
 
 //******************************************************
index 937aca3830d42f01b7f2d132bfcfb8d0b67d5d58..551f23c50d1432e84aa30eb93b185576be30370a 100644 (file)
@@ -18,6 +18,7 @@ class XGUI_Displayer;
 class XGUI_OperationMgr;
 class XGUI_SalomeConnector;
 class XGUI_ObjectsBrowser;
+class XGUI_ActionsMgr;
 class ModuleBase_Operation;
 class ModuleBase_PropPanelOperation;
 
@@ -127,6 +128,8 @@ private:
   XGUI_Displayer* myDisplayer;
 
   XGUI_OperationMgr* myOperationMgr; ///< manager to manipulate through the operations
+  XGUI_ActionsMgr* myActionsMgr;
+
 
   XGUI_SalomeConnector* mySalomeConnector;
 };