Salome HOME
c0003e8ecdae8658374edc4fc7720c1e3137cf52
[modules/shaper.git] / src / XGUI / XGUI_ActionsMgr.h
1 /*
2  * XGUI_ActionsMgr.h
3  */
4
5 #ifndef XGUI_ACTIONSMGR_H_
6 #define XGUI_ACTIONSMGR_H_
7
8 #include "XGUI.h"
9
10 #include <QObject>
11 #include <QMap>
12 #include <QList>
13 #include <QStringList>
14 #include <QKeySequence>
15
16 class XGUI_Workshop;
17 class XGUI_OperationMgr;
18 class ModuleBase_Operation;
19 class QAction;
20
21 class XGUI_EXPORT XGUI_ActionsMgr : public QObject
22 {
23 Q_OBJECT
24
25  public:
26   XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
27   virtual ~XGUI_ActionsMgr();
28
29   //! Add a command in the manager.
30   //! Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
31   //! won't be extracted and should be added manually using the addNestedCommands method.
32   void addCommand(QAction* theCmd);
33   //! Sets relation between the command (with given Id) and it's nested actions.
34   void addNestedCommands(const QString& theId, const QStringList& theCommands);
35
36   QStringList nestedCommands(const QString& theId) const;
37
38   bool isNested(const QString& theId) const;
39
40   QKeySequence registerShortcut(const QString& theKeySequence);
41
42   void updateByDocumentKind();
43
44  public slots:
45   //! Update workbench actions according to OperationMgr state:
46   //! No active operations: all actions but nested are available
47   //! There is active operation: current operation + it's nested
48   //! are enabled, all the rest is disabled. All active commands is checked.
49   void update();
50   //! Sets all commands checked if it's operation is active.
51   void updateCheckState();
52
53  protected:
54   //! Sets all actions to isEnabled state.
55   void setAllEnabled(bool isEnabled);
56   //! Sets to isEnabled state all siblings of the given operation and it's parents recursively
57   void setNestedStackEnabled(ModuleBase_Operation* theOperation);
58   //! Sets all nested actions to isEnabled state for the command with given ID.
59   //! If ID is empty - all nested actions will be affected.
60   void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
61   //! Sets the action with theId to theChecked state.
62   void setActionChecked(const QString& theId, const bool theChecked);
63   //! Sets the action with theId to theEnabled state.
64   void setActionEnabled(const QString& theId, const bool theEnabled);
65
66  private:
67   QMap<QString, QAction*> myActions;
68   QMap<QString, QStringList> myNestedActions;
69   QList<QKeySequence> myShortcuts;
70
71   XGUI_Workshop* myWorkshop;
72   XGUI_OperationMgr* myOperationMgr;
73 };
74
75 #endif /* XGUI_ACTIONSMGR_H_ */
76