Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[modules/shaper.git] / src / XGUI / XGUI_ActionsMgr.cpp
index 0d652dceba7eed7cdeba455230e3056d03bc361f..7f0b02d9ae0e668688a24dbaaa15d1a65caf1a19 100644 (file)
@@ -2,15 +2,18 @@
  * XGUI_ActionsMgr.cpp
  */
 
-#include <XGUI_ActionsMgr.h>
-#include <XGUI_Command.h>
+#include "XGUI_ActionsMgr.h"
+#include "XGUI_Command.h"
+#include "XGUI_Workshop.h"
+#include "XGUI_SalomeConnector.h"
+
 #include <QAction>
 
 
-XGUI_ActionsMgr::XGUI_ActionsMgr(QObject* theParent)
- : QObject(theParent)
+XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
+ : QObject(theParent), myWorkshop(theParent)
 {
-
+  
 }
 
 XGUI_ActionsMgr::~XGUI_ActionsMgr()
@@ -18,33 +21,42 @@ XGUI_ActionsMgr::~XGUI_ActionsMgr()
 }
 
 
-void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd)
+void XGUI_ActionsMgr::addCommand(QAction* theCmd)
 {
-  myActions.insert(theCmd->id(),theCmd);
-  myActionsState.insert(theCmd->id(), theCmd->enabled());
-  theCmd->connectTo(this, SLOT(setActionsDisabled(bool)));
+  QString aId = theCmd->data().toString();
+  myActions.insert(aId, theCmd);
+  myActionsState.insert(aId, theCmd->isEnabled());
+  connect(theCmd, SIGNAL(triggered(bool)), this, SLOT(setActionsDisabled(bool)));
 }
 
 void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
 {
   //Re-enable actions (just restore their state)
   if (!isDisabled) {
+    myNestedActions.clear();
     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());
+
+  QString aSkippedId;
+  QAction* aToggledFeature = dynamic_cast<QAction*>(sender());
+  aSkippedId = aToggledFeature->data().toString();
+
   QStringList anActionIdsList = myActions.keys();
   foreach(QString eachKey, anActionIdsList) {
-    if (aSkippedIds.removeAll(eachKey) > 0) {
+    if (eachKey == aSkippedId) {
       continue;
     }
     myActions[eachKey]->setEnabled(false);
   }
+  if (myWorkshop->isSalomeMode()) {
+    myNestedActions = myWorkshop->salomeConnector()->nestedActions(aSkippedId);
+  } else {
+    XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
+    myNestedActions = aToggledFeature->unblockableCommands();
+  }
 }
 
 void XGUI_ActionsMgr::saveCommandsState()
@@ -65,3 +77,26 @@ void XGUI_ActionsMgr::restoreCommandState()
     myActions[eachKey]->setChecked(false);
   }
 }
+
+void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
+{
+  if(myActions.contains(theId)) {
+    myActions[theId]->setChecked(theChecked);
+  }
+}
+
+void XGUI_ActionsMgr::updateAction(const QString& theId)
+{
+  if(myActions.contains(theId)){
+    myActions[theId]->setEnabled(myActionsState[theId]);
+    myActions[theId]->setChecked(false);
+  }
+}
+
+void XGUI_ActionsMgr::setNestedActionsEnabled(bool isEnabled)
+{
+  foreach(QString eachKey, myNestedActions) {
+    if (myActions.contains(eachKey))
+      myActions[eachKey]->setEnabled(isEnabled);
+  }
+}