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