1 // Copyright (C) 2014-2024 CEA, EDF
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #ifndef XGUI_ActionsMgr_H
21 #define XGUI_ActionsMgr_H
25 #include <Events_Listener.h>
26 #include <ModelAPI_Feature.h>
28 #include <ModuleBase_ActionInfo.h>
33 #include <QStringList>
34 #include <QKeySequence>
37 class XGUI_OperationMgr;
38 class ModuleBase_Operation;
41 /// class XGUI_ActionsMgr
43 /// A class for management of actions (features) activation/deactivation
44 class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
50 /// \param theWorkshop an instance of workshop
51 XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
52 virtual ~XGUI_ActionsMgr();
54 /// Actions on operations
55 enum OperationStateActionId {
65 /// Add a command in the manager.
66 /// Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
67 /// won't be extracted and should be added manually using the addNestedCommands method.
68 void addCommand(QAction* theCmd);
70 /// Sets relation between the command (with given Id) and it's nested actions.
71 void addNestedCommands(const QString& theId, const QStringList& theCommands);
73 /// Returns list of nested commands by parent command Id
74 /// \param theId a parent command Id
75 QStringList nestedCommands(const QString& theId) const;
77 /// Returns True if the given Id is an Id of nested command
78 /// \param theId an Id to check
79 bool isNested(const QString& theId) const;
81 /// Registers shortcut (key sequence) for the command triggering
82 /// \param theKeySequence a key sequence to register
83 QKeySequence registerShortcut(const QKeySequence& theKeySequence);
85 /// This is an overloaded function.
86 /// Registers shortcut (key sequence) for the command triggering
87 /// \param theKeySequence - string that contain a key sequence to register
88 QKeySequence registerShortcut(const QString& theKeySequence);
90 /// Redefinition of Events_Listener method
91 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
93 /// Return property panel's action like ok, cancel, help.
94 /// If there is no such action, it will be created.
95 QAction* operationStateAction(OperationStateActionId theId);
97 /// Return an action by the given id, if it was registered in the manager
98 QAction* action(const QString& theId);
100 /// Return info (icon, text, etc) about the action by the given id,
101 /// if it was registered in the manager
102 ActionInfo actionInfoById(const QString& theId);
105 /// Update workbench actions according to OperationMgr state:
106 /// No active operations: all actions but nested are available
107 /// There is active operation: current operation + it's nested
108 /// are enabled, all the rest is disabled. All active commands is checked.
109 void updateCommandsStatus();
111 /// Sets all commands checked if it's operation is active.
112 void updateCheckState();
114 /// Updates actions according to current selection in the viewer
115 void updateOnViewSelection();
117 /// Sets all actions to enabled state.
118 void setAllEnabled();
120 /// Sets all nested actions to isEnabled state for the command with given ID.
121 /// If ID is empty - all nested actions will be affected.
122 void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
124 /// Sets to enabled state all siblings of the given operation and it's parents recursively
125 void setNestedStackEnabled(ModuleBase_Operation* theOperation);
127 /// Sets the action with theId to theChecked state.
128 void setActionChecked(const QString& theId, const bool theChecked);
130 /// Sets the action with theId to theEnabled state.
131 void setActionEnabled(const QString& theId, const bool theEnabled);
133 /// Updates actions according to their "document" tag
134 void updateByDocumentKind();
136 /// Asks plugins about their features state, using the Events system
137 void updateByPlugins(FeaturePtr theActiveFeature);
139 /// Returns names of nested action for the feature of given operation
140 /// \param theOperation an operation
141 QStringList allNestedCommands(ModuleBase_Operation* theOperation);
145 QMap<QString, QAction*> myActions;
146 QMap<QString, QStringList> myNestedActions;
147 QMap<OperationStateActionId, QAction*> myOperationActions;
148 QList<QKeySequence> myShortcuts;
150 XGUI_Workshop* myWorkshop;
151 XGUI_OperationMgr* myOperationMgr;
153 friend class XGUI_Workshop;
156 #endif /* XGUI_ActionsMgr_H */