5 #include "XGUI_ActionsMgr.h"
6 #include "XGUI_Command.h"
7 #include "XGUI_Workshop.h"
8 #include "XGUI_OperationMgr.h"
10 #include <ModuleBase_Operation.h>
19 XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
20 : QObject(theParent), myOperationMgr(theParent->operationMgr())
25 XGUI_ActionsMgr::~XGUI_ActionsMgr()
30 void XGUI_ActionsMgr::addCommand(QAction* theCmd)
32 QString aId = theCmd->data().toString();
36 myActions.insert(aId, theCmd);
37 XGUI_Command* aXCmd = dynamic_cast<XGUI_Command*>(theCmd);
39 myNestedActions[aId] = aXCmd->nestedCommands();
43 void XGUI_ActionsMgr::addNestedCommands(const QString& theId, const QStringList& theCommands)
45 myNestedActions[theId] = theCommands;
48 void XGUI_ActionsMgr::update()
50 if(myOperationMgr->hasOperation()) {
52 ModuleBase_Operation* anOperation = myOperationMgr->currentOperation();
53 QString anOperationId = anOperation->id();
54 setActionEnabled(anOperationId, true);
55 bool isNestedEnabled = anOperation->isNestedOperationsEnabled();
56 setNestedCommandsEnabled(isNestedEnabled, anOperationId);
59 setNestedCommandsEnabled(false);
64 void XGUI_ActionsMgr::setAllEnabled(bool isEnabled)
66 foreach(QString eachAction, myActions.keys()) {
67 setActionEnabled(eachAction, isEnabled);
72 void XGUI_ActionsMgr::setNestedCommandsEnabled(bool theEnabled, const QString& theParent)
74 QStringList ltNestedActions;
75 if(theParent.isEmpty()) { //Disable ALL nested
76 foreach(QString eachParent, myNestedActions.keys()) {
77 ltNestedActions << myNestedActions[eachParent];
80 ltNestedActions << myNestedActions[theParent];
82 foreach(QString eachNested, ltNestedActions) {
83 setActionEnabled(eachNested, theEnabled);
87 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
89 QAction* anAction = myActions[theId];
90 if(anAction && anAction->isCheckable()) {
91 anAction->setChecked(theChecked);
96 void XGUI_ActionsMgr::setActionEnabled(const QString& theId, const bool theEnabled)
98 QAction* anAction = myActions[theId];
100 anAction->setEnabled(theEnabled);
104 void XGUI_ActionsMgr::updateCheckState()
106 QString eachCommand = QString();
107 foreach(eachCommand, myActions.keys()) {
108 setActionChecked(eachCommand, false);
110 QStringList ltActiveCommands = myOperationMgr->operationList();
111 foreach(eachCommand, ltActiveCommands) {
112 setActionChecked(eachCommand, true);