Salome HOME
Merge Dev_2.1.0 with PythonAPI branch
[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   };
50
51   //! Add a command in the manager.
52   //! Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
53   //! won't be extracted and should be added manually using the addNestedCommands method.
54   void addCommand(QAction* theCmd);
55
56   //! Sets relation between the command (with given Id) and it's nested actions.
57   void addNestedCommands(const QString& theId, const QStringList& theCommands);
58
59   //! Returns list of nested commands by parent command Id
60   //! \param theId a parent command Id
61   QStringList nestedCommands(const QString& theId) const;
62
63   /// Returns True if the given Id is an Id of nested command
64   /// \param theId an Id to check
65   bool isNested(const QString& theId) const;
66
67   /// Registers shortcut (key sequence) for the command triggering
68   /// \param theKeySequence a key sequence to register
69   QKeySequence registerShortcut(const QKeySequence& theKeySequence);
70
71   /// This is an overloaded function.
72   /// Registers shortcut (key sequence) for the command triggering
73   /// \param theKeySequence - string that contain a key sequence to register
74   QKeySequence registerShortcut(const QString& theKeySequence);
75
76   //! Redefinition of Events_Listener method
77   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
78
79   //! Return property panel's action like ok, cancel, help.
80   //! If there is no such action, it will be created.
81   QAction* operationStateAction(OperationStateActionId theId, QObject* theParent = 0);
82
83   /// Return an action by the given id, if it was registered in the manager
84   QAction* action(const QString& theId);
85
86   /// Return info (icon, text, etc) about the action by the given id, if it was registered in the manager
87   ActionInfo actionInfoById(const QString& theId);
88
89  private:
90   //! Update workbench actions according to OperationMgr state:
91   //! No active operations: all actions but nested are available
92   //! There is active operation: current operation + it's nested
93   //! are enabled, all the rest is disabled. All active commands is checked.
94   void updateCommandsStatus();
95
96   //! Sets all commands checked if it's operation is active.
97   void updateCheckState();
98
99   //! Updates actions according to current selection in the viewer
100   void updateOnViewSelection();
101   
102   //! Sets all actions to isEnabled state.
103   void setAllEnabled(bool isEnabled);
104   
105   //! Sets all nested actions to isEnabled state for the command with given ID.
106   //! If ID is empty - all nested actions will be affected.
107   void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
108   
109   //! Sets to enabled state all siblings of the given operation and it's parents recursively
110   void setNestedStackEnabled(ModuleBase_Operation* theOperation);
111   
112   //! Sets the action with theId to theChecked state.
113   void setActionChecked(const QString& theId, const bool theChecked);
114   
115   //! Sets the action with theId to theEnabled state.
116   void setActionEnabled(const QString& theId, const bool theEnabled);
117   
118   //! Updates actions according to their "document" tag
119   void updateByDocumentKind();
120
121   //! Asks plugins about their features state, using the Events system
122   void updateByPlugins(FeaturePtr theActiveFeature);
123
124   QStringList allNestedCommands(ModuleBase_Operation* theOperation);
125
126  private:
127
128   QMap<QString, QAction*> myActions;
129   QMap<QString, QStringList> myNestedActions;
130   QMap<OperationStateActionId, QAction*> myOperationActions;
131   QList<QKeySequence> myShortcuts;
132
133   XGUI_Workshop* myWorkshop;
134   XGUI_OperationMgr* myOperationMgr;
135
136   friend class XGUI_Workshop;
137 };
138
139 #endif /* XGUI_ACTIONSMGR_H_ */
140