]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ActionsMgr.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 "XGUI_Workshop.h"
8 #include "XGUI_SalomeConnector.h"
9
10 #include <QAction>
11
12
13 XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
14  : QObject(theParent), myWorkshop(theParent)
15 {
16   
17 }
18
19 XGUI_ActionsMgr::~XGUI_ActionsMgr()
20 {
21 }
22
23
24 void XGUI_ActionsMgr::addCommand(QString theId, QAction* theCmd)
25 {
26   myActions.insert(theId,theCmd);
27   myActionsState.insert(theId, theCmd->isEnabled());
28   connect(theCmd, SIGNAL(triggered(bool)), this, SLOT(setActionsDisabled(bool)));
29 }
30
31 void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd)
32 {
33   myActions.insert(theCmd->id(),theCmd);
34   myActionsState.insert(theCmd->id(), theCmd->enabled());
35   theCmd->connectTo(this, SLOT(setActionsDisabled(bool)));
36 }
37
38 void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
39 {
40   //Re-enable actions (just restore their state)
41   if (!isDisabled) {
42     myNestedActions.clear();
43     restoreCommandState();
44     return;
45   }
46   //Disable all actions, but caller and unblockable (defined in a xml)
47   saveCommandsState();
48
49   QString aSkippedId;
50   if (myWorkshop->isSalomeMode()) {
51     QAction* aToggledFeature = dynamic_cast<QAction*>(sender());
52     aSkippedId = myWorkshop->salomeConnector()->commandId(aToggledFeature);
53   } else {
54     XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
55     aSkippedId = aToggledFeature->id();
56   }
57   QStringList anActionIdsList = myActions.keys();
58   foreach(QString eachKey, anActionIdsList) {
59     if (eachKey == aSkippedId) {
60       continue;
61     }
62     myActions[eachKey]->setEnabled(false);
63   }
64   if (myWorkshop->isSalomeMode()) {
65     myNestedActions = myWorkshop->salomeConnector()->nestedActions(aSkippedId);
66   } else {
67     XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
68     myNestedActions = aToggledFeature->unblockableCommands();
69   }
70 }
71
72 void XGUI_ActionsMgr::saveCommandsState()
73 {
74   myActionsState.clear();
75   QStringList anActionIdsList = myActions.keys();
76   foreach(QString eachKey, anActionIdsList) {
77     myActionsState.insert(eachKey, myActions[eachKey]->isEnabled());
78   }
79
80 }
81
82 void XGUI_ActionsMgr::restoreCommandState()
83 {
84   QStringList anActionIdsList = myActions.keys();
85   foreach(QString eachKey, anActionIdsList) {
86     myActions[eachKey]->setEnabled(myActionsState[eachKey]);
87     myActions[eachKey]->setChecked(false);
88   }
89 }
90
91 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
92 {
93   if(myActions.contains(theId)) {
94     myActions[theId]->setChecked(theChecked);
95   }
96 }
97
98 void XGUI_ActionsMgr::updateAction(const QString& theId)
99 {
100   if(myActions.contains(theId)){
101     myActions[theId]->setEnabled(myActionsState[theId]);
102     myActions[theId]->setChecked(false);
103   }
104 }
105
106 void XGUI_ActionsMgr::setNestedActionsEnabled(bool isEnabled)
107 {
108   foreach(QString eachKey, myNestedActions) {
109     if (myActions.contains(eachKey))
110       myActions[eachKey]->setEnabled(isEnabled);
111   }
112 }