]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ActionsMgr.cpp
Salome HOME
Issue #6 Extended processing of nested actions.
[modules/shaper.git] / src / XGUI / XGUI_ActionsMgr.cpp
1 /*
2  * XGUI_ActionsMgr.cpp
3  */
4
5 #include <XGUI_ActionsMgr.h>
6 #include <XGUI_Command.h>
7 #include <QAction>
8
9
10 XGUI_ActionsMgr::XGUI_ActionsMgr(QObject* theParent)
11  : QObject(theParent)
12 {
13
14 }
15
16 XGUI_ActionsMgr::~XGUI_ActionsMgr()
17 {
18 }
19
20
21 void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd)
22 {
23   myActions.insert(theCmd->id(),theCmd);
24   myActionsState.insert(theCmd->id(), theCmd->enabled());
25   theCmd->connectTo(this, SLOT(setActionsDisabled(bool)));
26 }
27
28 void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
29 {
30   //Re-enable actions (just restore their state)
31   if (!isDisabled) {
32     myNestedActions.clear();
33     restoreCommandState();
34     return;
35   }
36   //Disable all actions, but caller and unblockable (defined in a xml)
37   saveCommandsState();
38   XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
39   QString aSkippedId = aToggledFeature->id();
40   QStringList anActionIdsList = myActions.keys();
41   foreach(QString eachKey, anActionIdsList) {
42     if (eachKey == aSkippedId) {
43       continue;
44     }
45     myActions[eachKey]->setEnabled(false);
46   }
47   myNestedActions = aToggledFeature->unblockableCommands();
48 }
49
50 void XGUI_ActionsMgr::saveCommandsState()
51 {
52   myActionsState.clear();
53   QStringList anActionIdsList = myActions.keys();
54   foreach(QString eachKey, anActionIdsList) {
55     myActionsState.insert(eachKey, myActions[eachKey]->isEnabled());
56   }
57
58 }
59
60 void XGUI_ActionsMgr::restoreCommandState()
61 {
62   QStringList anActionIdsList = myActions.keys();
63   foreach(QString eachKey, anActionIdsList) {
64     myActions[eachKey]->setEnabled(myActionsState[eachKey]);
65     myActions[eachKey]->setChecked(false);
66   }
67 }
68
69 void XGUI_ActionsMgr::setNestedActionsEnabled(bool isEnabled)
70 {
71   foreach(QString eachKey, myNestedActions) {
72     myActions[eachKey]->setEnabled(isEnabled);
73   }
74 }