]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ActionsMgr.cpp
Salome HOME
0d652dceba7eed7cdeba455230e3056d03bc361f
[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     restoreCommandState();
33     return;
34   }
35   //Disable all actions, but caller and unblockable (defined in a xml)
36   saveCommandsState();
37   QStringList aSkippedIds;
38   XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
39   aSkippedIds.append(aToggledFeature->unblockableCommands());
40   aSkippedIds.append(aToggledFeature->id());
41   QStringList anActionIdsList = myActions.keys();
42   foreach(QString eachKey, anActionIdsList) {
43     if (aSkippedIds.removeAll(eachKey) > 0) {
44       continue;
45     }
46     myActions[eachKey]->setEnabled(false);
47   }
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 }