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>
18 #include <QStringList>
19 #include <QKeySequence>
22 class XGUI_OperationMgr;
23 class ModuleBase_Operation;
28 * A class for management of actions (features) activation/deactivation
30 class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
36 /// \param theWorkshop an instance of workshop
37 XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
38 virtual ~XGUI_ActionsMgr();
40 enum OperationStateActionId {
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);
53 //! Sets relation between the command (with given Id) and it's nested actions.
54 void addNestedCommands(const QString& theId, const QStringList& theCommands);
56 //! Returns list of nested commands by parent command Id
57 //! \param theId a parent command Id
58 QStringList nestedCommands(const QString& theId) const;
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;
64 /// Registers shortcut (key sequence) for the command triggering
65 /// \param theKeySequence a key sequence to register
66 QKeySequence registerShortcut(const QKeySequence& theKeySequence);
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);
73 //! Redefinition of Events_Listener method
74 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
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);
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.
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();
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);
110 QMap<QString, QAction*> myActions;
111 QMap<QString, QStringList> myNestedActions;
112 QMap<OperationStateActionId, QAction*> myOperationActions;
113 QList<QKeySequence> myShortcuts;
115 XGUI_Workshop* myWorkshop;
116 XGUI_OperationMgr* myOperationMgr;
119 #endif /* XGUI_ACTIONSMGR_H_ */