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 {
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);
56 //! Sets relation between the command (with given Id) and it's nested actions.
57 void addNestedCommands(const QString& theId, const QStringList& theCommands);
59 //! Returns list of nested commands by parent command Id
60 //! \param theId a parent command Id
61 QStringList nestedCommands(const QString& theId) const;
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;
67 /// Registers shortcut (key sequence) for the command triggering
68 /// \param theKeySequence a key sequence to register
69 QKeySequence registerShortcut(const QKeySequence& theKeySequence);
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);
76 //! Redefinition of Events_Listener method
77 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
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);
83 /// Return info (icon, text, etc) about the action by the given id, if it was registered in the manager
84 ActionInfo actionInfoById(const QString& theId);
87 //! Update workbench actions according to OperationMgr state:
88 //! No active operations: all actions but nested are available
89 //! There is active operation: current operation + it's nested
90 //! are enabled, all the rest is disabled. All active commands is checked.
92 //! Sets all commands checked if it's operation is active.
93 void updateCheckState();
94 //! Updates actions according to current selection in the viewer
95 void updateOnViewSelection();
98 //! Sets all actions to isEnabled state.
99 void setAllEnabled(bool isEnabled);
100 //! Sets all nested actions to isEnabled state for the command with given ID.
101 //! If ID is empty - all nested actions will be affected.
102 void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
103 //! Sets to enabled state all siblings of the given operation and it's parents recursively
104 void setNestedStackEnabled(ModuleBase_Operation* theOperation);
105 //! Sets the action with theId to theChecked state.
106 void setActionChecked(const QString& theId, const bool theChecked);
107 //! Sets the action with theId to theEnabled state.
108 void setActionEnabled(const QString& theId, const bool theEnabled);
109 //! Updates actions according to their "document" tag
110 void updateByDocumentKind();
111 //! Asks plugins about their features state, using the Events system
112 void updateByPlugins(FeaturePtr theActiveFeature);
116 QMap<QString, QAction*> myActions;
117 QMap<QString, QStringList> myNestedActions;
118 QMap<OperationStateActionId, QAction*> myOperationActions;
119 QList<QKeySequence> myShortcuts;
121 XGUI_Workshop* myWorkshop;
122 XGUI_OperationMgr* myOperationMgr;
125 #endif /* XGUI_ACTIONSMGR_H_ */