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(QAction* theCmd)
26 QString aId = theCmd->data().toString();
27 myActions.insert(aId, theCmd);
28 myActionsState.insert(aId, theCmd->isEnabled());
29 connect(theCmd, SIGNAL(triggered(bool)), this, SLOT(setActionsDisabled(bool)));
32 void XGUI_ActionsMgr::setActionsDisabled(bool isDisabled)
34 //Re-enable actions (just restore their state)
36 myNestedActions.clear();
37 restoreCommandState();
40 //Disable all actions, but caller and unblockable (defined in a xml)
44 QAction* aToggledFeature = dynamic_cast<QAction*>(sender());
45 aSkippedId = aToggledFeature->data().toString();
47 QStringList anActionIdsList = myActions.keys();
48 foreach(QString eachKey, anActionIdsList) {
49 if (eachKey == aSkippedId) {
52 myActions[eachKey]->setEnabled(false);
54 if (myWorkshop->isSalomeMode()) {
55 myNestedActions = myWorkshop->salomeConnector()->nestedActions(aSkippedId);
57 XGUI_Command* aToggledFeature = dynamic_cast<XGUI_Command*>(sender());
58 myNestedActions = aToggledFeature->unblockableCommands();
62 void XGUI_ActionsMgr::saveCommandsState()
64 myActionsState.clear();
65 QStringList anActionIdsList = myActions.keys();
66 foreach(QString eachKey, anActionIdsList) {
67 myActionsState.insert(eachKey, myActions[eachKey]->isEnabled());
72 void XGUI_ActionsMgr::restoreCommandState()
74 QStringList anActionIdsList = myActions.keys();
75 foreach(QString eachKey, anActionIdsList) {
76 myActions[eachKey]->setEnabled(myActionsState[eachKey]);
77 myActions[eachKey]->setChecked(false);
81 void XGUI_ActionsMgr::setActionChecked(const QString& theId, const bool theChecked)
83 if(myActions.contains(theId)) {
84 myActions[theId]->setChecked(theChecked);
88 void XGUI_ActionsMgr::updateAction(const QString& theId)
90 if(myActions.contains(theId)){
91 myActions[theId]->setEnabled(myActionsState[theId]);
92 myActions[theId]->setChecked(false);
96 void XGUI_ActionsMgr::setNestedActionsEnabled(bool isEnabled)
98 foreach(QString eachKey, myNestedActions) {
99 if (myActions.contains(eachKey))
100 myActions[eachKey]->setEnabled(isEnabled);