1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
7 #ifndef XGUI_ACTIONSMGR_H_
8 #define XGUI_ACTIONSMGR_H_
12 #include <Events_Listener.h>
13 #include <ModelAPI_Feature.h>
15 #include <ModuleBase_ActionInfo.h>
20 #include <QStringList>
21 #include <QKeySequence>
24 class XGUI_OperationMgr;
25 class ModuleBase_Operation;
30 * A class for management of actions (features) activation/deactivation
32 class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
38 /// \param theWorkshop an instance of workshop
39 XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
40 virtual ~XGUI_ActionsMgr();
42 /// Actions on operations
43 enum OperationStateActionId {
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);
57 //! Sets relation between the command (with given Id) and it's nested actions.
58 void addNestedCommands(const QString& theId, const QStringList& theCommands);
60 //! Returns list of nested commands by parent command Id
61 //! \param theId a parent command Id
62 QStringList nestedCommands(const QString& theId) const;
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;
68 /// Registers shortcut (key sequence) for the command triggering
69 /// \param theKeySequence a key sequence to register
70 QKeySequence registerShortcut(const QKeySequence& theKeySequence);
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);
77 //! Redefinition of Events_Listener method
78 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
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);
84 /// Return an action by the given id, if it was registered in the manager
85 QAction* action(const QString& theId);
87 /// Return info (icon, text, etc) about the action by the given id,
88 /// if it was registered in the manager
89 ActionInfo actionInfoById(const QString& theId);
92 //! Update workbench actions according to OperationMgr state:
93 //! No active operations: all actions but nested are available
94 //! There is active operation: current operation + it's nested
95 //! are enabled, all the rest is disabled. All active commands is checked.
96 void updateCommandsStatus();
98 //! Sets all commands checked if it's operation is active.
99 void updateCheckState();
101 //! Updates actions according to current selection in the viewer
102 void updateOnViewSelection();
104 //! Sets all actions to enabled state.
105 void setAllEnabled();
107 //! Sets all nested actions to isEnabled state for the command with given ID.
108 //! If ID is empty - all nested actions will be affected.
109 void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
111 //! Sets to enabled state all siblings of the given operation and it's parents recursively
112 void setNestedStackEnabled(ModuleBase_Operation* theOperation);
114 //! Sets the action with theId to theChecked state.
115 void setActionChecked(const QString& theId, const bool theChecked);
117 //! Sets the action with theId to theEnabled state.
118 void setActionEnabled(const QString& theId, const bool theEnabled);
120 //! Updates actions according to their "document" tag
121 void updateByDocumentKind();
123 //! Asks plugins about their features state, using the Events system
124 void updateByPlugins(FeaturePtr theActiveFeature);
126 QStringList allNestedCommands(ModuleBase_Operation* theOperation);
130 QMap<QString, QAction*> myActions;
131 QMap<QString, QStringList> myNestedActions;
132 QMap<OperationStateActionId, QAction*> myOperationActions;
133 QList<QKeySequence> myShortcuts;
135 XGUI_Workshop* myWorkshop;
136 XGUI_OperationMgr* myOperationMgr;
138 friend class XGUI_Workshop;
141 #endif /* XGUI_ACTIONSMGR_H_ */