Salome HOME
Documentation update
[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 <Events_Listener.h>
13 #include <ModelAPI_Feature.h>
14
15 #include <ModuleBase_ActionInfo.h>
16
17 #include <QObject>
18 #include <QMap>
19 #include <QList>
20 #include <QStringList>
21 #include <QKeySequence>
22
23 class XGUI_Workshop;
24 class XGUI_OperationMgr;
25 class ModuleBase_Operation;
26 class QAction;
27
28 /**
29 * \ingroup GUI
30 * A class for management of actions (features) activation/deactivation
31 */
32 class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
33 {
34   Q_OBJECT
35
36  public:
37   /// Constructor
38   /// \param theWorkshop an instance of workshop
39   XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
40   virtual ~XGUI_ActionsMgr();
41
42   /// Actions on operations
43   enum OperationStateActionId {
44     Abort = 0,
45     Accept = 1,
46     Help = 2,
47     AbortAll = 3,
48     AcceptAll = 4,
49     Preview = 5
50   };
51
52   //! Add a command in the manager.
53   //! Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
54   //! won't be extracted and should be added manually using the addNestedCommands method.
55   void addCommand(QAction* theCmd);
56
57   //! Sets relation between the command (with given Id) and it's nested actions.
58   void addNestedCommands(const QString& theId, const QStringList& theCommands);
59
60   //! Returns list of nested commands by parent command Id
61   //! \param theId a parent command Id
62   QStringList nestedCommands(const QString& theId) const;
63
64   /// Returns True if the given Id is an Id of nested command
65   /// \param theId an Id to check
66   bool isNested(const QString& theId) const;
67
68   /// Registers shortcut (key sequence) for the command triggering
69   /// \param theKeySequence a key sequence to register
70   QKeySequence registerShortcut(const QKeySequence& theKeySequence);
71
72   /// This is an overloaded function.
73   /// Registers shortcut (key sequence) for the command triggering
74   /// \param theKeySequence - string that contain a key sequence to register
75   QKeySequence registerShortcut(const QString& theKeySequence);
76
77   //! Redefinition of Events_Listener method
78   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
79
80   //! Return property panel's action like ok, cancel, help.
81   //! If there is no such action, it will be created.
82   QAction* operationStateAction(OperationStateActionId theId);
83
84   /// Return an action by the given id, if it was registered in the manager
85   QAction* action(const QString& theId);
86
87   /// Return info (icon, text, etc) about the action by the given id, if it was registered in the manager
88   ActionInfo actionInfoById(const QString& theId);
89
90  private:
91   //! Update workbench actions according to OperationMgr state:
92   //! No active operations: all actions but nested are available
93   //! There is active operation: current operation + it's nested
94   //! are enabled, all the rest is disabled. All active commands is checked.
95   void updateCommandsStatus();
96
97   //! Sets all commands checked if it's operation is active.
98   void updateCheckState();
99
100   //! Updates actions according to current selection in the viewer
101   void updateOnViewSelection();
102   
103   //! Sets all actions to enabled state.
104   void setAllEnabled();
105   
106   //! Sets all nested actions to isEnabled state for the command with given ID.
107   //! If ID is empty - all nested actions will be affected.
108   void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
109   
110   //! Sets to enabled state all siblings of the given operation and it's parents recursively
111   void setNestedStackEnabled(ModuleBase_Operation* theOperation);
112   
113   //! Sets the action with theId to theChecked state.
114   void setActionChecked(const QString& theId, const bool theChecked);
115   
116   //! Sets the action with theId to theEnabled state.
117   void setActionEnabled(const QString& theId, const bool theEnabled);
118   
119   //! Updates actions according to their "document" tag
120   void updateByDocumentKind();
121
122   //! Asks plugins about their features state, using the Events system
123   void updateByPlugins(FeaturePtr theActiveFeature);
124
125   QStringList allNestedCommands(ModuleBase_Operation* theOperation);
126
127  private:
128
129   QMap<QString, QAction*> myActions;
130   QMap<QString, QStringList> myNestedActions;
131   QMap<OperationStateActionId, QAction*> myOperationActions;
132   QList<QKeySequence> myShortcuts;
133
134   XGUI_Workshop* myWorkshop;
135   XGUI_OperationMgr* myOperationMgr;
136
137   friend class XGUI_Workshop;
138 };
139
140 #endif /* XGUI_ACTIONSMGR_H_ */
141