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