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