Salome HOME
Facilate action processing with ModuleBase_ActionInfo
[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 <QObject>
16 #include <QMap>
17 #include <QList>
18 #include <QStringList>
19 #include <QKeySequence>
20
21 class XGUI_Workshop;
22 class XGUI_OperationMgr;
23 class ModuleBase_Operation;
24 class QAction;
25
26 /**
27 * \ingroup GUI
28 * A class for management of actions (features) activation/deactivation
29 */
30 class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
31 {
32 Q_OBJECT
33
34  public:
35    /// Constructor
36    /// \param theWorkshop an instance of workshop
37   XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
38   virtual ~XGUI_ActionsMgr();
39
40   //! Add a command in the manager.
41   //! Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
42   //! won't be extracted and should be added manually using the addNestedCommands method.
43   void addCommand(QAction* theCmd);
44
45   //! Sets relation between the command (with given Id) and it's nested actions.
46   void addNestedCommands(const QString& theId, const QStringList& theCommands);
47
48   //! Returns list of nested commands by parent command Id
49   //! \param theId a parent command Id
50   QStringList nestedCommands(const QString& theId) const;
51
52   /// Returns True if the given Id is an Id of nested command
53   /// \param theId an Id to check
54   bool isNested(const QString& theId) const;
55
56   /// Registers shortcut (key sequence) for the command triggering
57   /// \param theKeySequence a key sequence to register
58   QKeySequence registerShortcut(const QKeySequence& theKeySequence);
59
60   /// This is an overloaded function.
61   /// Registers shortcut (key sequence) for the command triggering
62   /// \param theKeySequence - string that contain a key sequence to register
63   QKeySequence registerShortcut(const QString& theKeySequence);
64
65   //! Redefinition of Events_Listener method
66   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
67
68  public slots:
69   //! Update workbench actions according to OperationMgr state:
70   //! No active operations: all actions but nested are available
71   //! There is active operation: current operation + it's nested
72   //! are enabled, all the rest is disabled. All active commands is checked.
73   void update();
74   //! Sets all commands checked if it's operation is active.
75   void updateCheckState();
76   //! Updates actions according to current selection in the viewer
77   void updateOnViewSelection();
78
79  protected:
80   //! Sets all actions to isEnabled state.
81   void setAllEnabled(bool isEnabled);
82   //! Sets all nested actions to isEnabled state for the command with given ID.
83   //! If ID is empty - all nested actions will be affected.
84   void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
85   //! Sets to enabled state all siblings of the given operation and it's parents recursively
86   void setNestedStackEnabled(ModuleBase_Operation* theOperation);
87   //! Sets the action with theId to theChecked state.
88   void setActionChecked(const QString& theId, const bool theChecked);
89   //! Sets the action with theId to theEnabled state.
90   void setActionEnabled(const QString& theId, const bool theEnabled);
91   //! Updates actions according to their "document" tag
92   void updateByDocumentKind();
93   //! Asks plugins about their features state, using the Events system
94   void updateByPlugins(FeaturePtr theActiveFeature);
95
96  private:
97   QMap<QString, QAction*> myActions;
98   QMap<QString, QStringList> myNestedActions;
99   QList<QKeySequence> myShortcuts;
100
101   XGUI_Workshop* myWorkshop;
102   XGUI_OperationMgr* myOperationMgr;
103 };
104
105 #endif /* XGUI_ACTIONSMGR_H_ */
106