5 #include "XGUI_ActionsMgr.h"
6 #include "XGUI_Command.h"
7 #include "XGUI_Workshop.h"
8 #include "XGUI_SalomeConnector.h"
13 XGUI_ActionsMgr::XGUI_ActionsMgr(XGUI_Workshop* theParent)
14 : QObject(theParent), myWorkshop(theParent)
19 XGUI_ActionsMgr::~XGUI_ActionsMgr()
24 void XGUI_ActionsMgr::addCommand(QString theId, QAction* theCmd)
26 myActions.insert(theId,theCmd);
27 myActionsState.insert(theId, theCmd->isEnabled());
28 connect(theCmd, SIGNAL(triggered(bool)), this, SLOT(setActionsDisabled(bool)));
31 void XGUI_ActionsMgr::addCommand(XGUI_Command* theCmd)
33 myActions.insert(theCmd->id(),theCmd);
34 myActionsState.insert(theCmd->id(), theCmd->enabled());
35 theCmd->connectTo(this, SLOT(setActionsDisabled(bool)));
38 void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
40 //Re-enable actions (just restore their state)
42 myNestedActions.clear();
43 restoreCommandState();
46 //Disable all actions, but caller and unblockable (defined in a xml)
50 if (myWorkshop->isSalomeMode()) {
51 QAction* aToggledFeature = dynamic_cast<QAction*>(sender());
52 aSkippedId = myWorkshop->salomeConnector()->commandId(aToggledFeature);
54 XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
55 aSkippedId = aToggledFeature->id();
57 QStringList anActionIdsList = myActions.keys();
58 foreach(QString eachKey, anActionIdsList) {
59 if (eachKey == aSkippedId) {
62 myActions[eachKey]->setEnabled(false);
64 if (myWorkshop->isSalomeMode()) {
65 myNestedActions = myWorkshop->salomeConnector()->nestedActions(aSkippedId);
67 XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
68 myNestedActions = aToggledFeature->unblockableCommands();
72 void XGUI_ActionsMgr::saveCommandsState()
74 myActionsState.clear();
75 QStringList anActionIdsList = myActions.keys();
76 foreach(QString eachKey, anActionIdsList) {
77 myActionsState.insert(eachKey, myActions[eachKey]->isEnabled());
82 void XGUI_ActionsMgr::restoreCommandState()
84 QStringList anActionIdsList = myActions.keys();
85 foreach(QString eachKey, anActionIdsList) {
86 myActions[eachKey]->setEnabled(myActionsState[eachKey]);
87 myActions[eachKey]->setChecked(false);
91 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
93 if(myActions.contains(theId)) {
94 myActions[theId]->setChecked(theChecked);
98 void XGUI_ActionsMgr::updateAction(const QString& theId)
100 if(myActions.contains(theId)){
101 myActions[theId]->setEnabled(myActionsState[theId]);
102 myActions[theId]->setChecked(false);
106 void XGUI_ActionsMgr::setNestedActionsEnabled(bool isEnabled)
108 foreach(QString eachKey, myNestedActions) {
109 if (myActions.contains(eachKey))
110 myActions[eachKey]->setEnabled(isEnabled);