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 //! 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);
45 //! Sets relation between the command (with given Id) and it's nested actions.
46 void addNestedCommands(const QString& theId, const QStringList& theCommands);
48 //! Returns list of nested commands by parent command Id
49 //! \param theId a parent command Id
50 QStringList nestedCommands(const QString& theId) const;
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;
56 /// Registers shortcut (key sequence) for the command triggering
57 /// \param theKeySequence a key sequence to register
58 QKeySequence registerShortcut(const QKeySequence& theKeySequence);
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);
65 //! Redefinition of Events_Listener method
66 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
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.
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();
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);
97 QMap<QString, QAction*> myActions;
98 QMap<QString, QStringList> myNestedActions;
99 QList<QKeySequence> myShortcuts;
101 XGUI_Workshop* myWorkshop;
102 XGUI_OperationMgr* myOperationMgr;
105 #endif /* XGUI_ACTIONSMGR_H_ */