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