]> SALOME platform Git repositories - modules/shaper.git/blob - src/XGUI/XGUI_ActionsMgr.cpp
Salome HOME
8722c089649af58c9bd6f1229c8d06ba1e1c8f78
[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_OperationMgr.h"
9 #include "XGUI_SalomeConnector.h"
10
11 #include <ModuleBase_Operation.h>
12
13 #include <QAction>
14
15 #ifdef _DEBUG
16 #include <QDebug>
17 #endif
18
19
20 XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
21  : QObject(theParent), myOperationMgr(theParent->operationMgr())
22 {
23
24 }
25
26 XGUI_ActionsMgr::~XGUI_ActionsMgr()
27 {
28 }
29
30
31 void XGUI_ActionsMgr::addCommand(QAction* theCmd)
32 {
33   QString aId = theCmd->data().toString();
34   if(aId.isEmpty()) {
35     return;
36   }
37   myActions.insert(aId, theCmd);
38   XGUI_Command* aXCmd = dynamic_cast<XGUI_Command*>(theCmd);
39   if (aXCmd) {
40     myNestedActions[aId] = aXCmd->nestedCommands();
41   } else {
42     XGUI_Workshop* aWorkshop = static_cast<XGUI_Workshop*>(parent());
43     myNestedActions[aId] = aWorkshop->salomeConnector()->nestedActions(aId);
44   }
45 }
46
47 void XGUI_ActionsMgr::addNestedCommands(const QString& theId, const QStringList& theCommands)
48 {
49   myNestedActions[theId] = theCommands;
50 }
51
52 void XGUI_ActionsMgr::update()
53 {
54   if(myOperationMgr->hasOperation()) {
55     setAllEnabled(false);
56     ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
57     QString anOperationId = anOperation->id();
58     setActionEnabled(anOperationId, true);
59     bool isNestedEnabled = anOperation->isNestedOperationsEnabled();
60     setNestedCommandsEnabled(isNestedEnabled, anOperationId);
61   } else {
62     setAllEnabled(true);
63     setNestedCommandsEnabled(false);
64   }
65   updateCheckState();
66 }
67
68 void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
69 {
70   foreach(QString eachAction, myActions.keys()) {
71     setActionEnabled(eachAction, isEnabled);
72   }
73 }
74
75 //!
76 void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent)
77 {
78   QStringList ltNestedActions;
79   if(theParent.isEmpty()) { //Disable ALL nested
80     foreach(QString eachParent, myNestedActions.keys()) {
81       ltNestedActions << myNestedActions[eachParent];
82     }
83   } else {
84     ltNestedActions << myNestedActions[theParent];
85   }
86   foreach(QString eachNested, ltNestedActions) {
87     setActionEnabled(eachNested, theEnabled);
88   }
89 }
90
91 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
92 {
93   QAction* anAction = myActions[theId];
94   if(anAction && anAction->isCheckable()) {
95     anAction->setChecked(theChecked);
96   }
97 }
98
99
100 void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
101 {
102   QAction* anAction = myActions[theId];
103   if(anAction) {
104     anAction->setEnabled(theEnabled);
105   }
106 }
107
108 void XGUI_ActionsMgr::updateCheckState()
109 {
110   QString eachCommand = QString();
111   foreach(eachCommand, myActions.keys()) {
112     setActionChecked(eachCommand, false);
113   }
114   QStringList ltActiveCommands = myOperationMgr->operationList();
115   foreach(eachCommand, ltActiveCommands) {
116     setActionChecked(eachCommand, true);
117   }
118 }