1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
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
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
25 #ifndef XGUI_ACTIONSMGR_H_
26 #define XGUI_ACTIONSMGR_H_
30 #include <Events_Listener.h>
31 #include <ModelAPI_Feature.h>
33 #include <ModuleBase_ActionInfo.h>
38 #include <QStringList>
39 #include <QKeySequence>
42 class XGUI_OperationMgr;
43 class ModuleBase_Operation;
48 * A class for management of actions (features) activation/deactivation
50 class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
56 /// \param theWorkshop an instance of workshop
57 XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
58 virtual ~XGUI_ActionsMgr();
60 /// Actions on operations
61 enum OperationStateActionId {
71 //! Add a command in the manager.
72 //! Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
73 //! won't be extracted and should be added manually using the addNestedCommands method.
74 void addCommand(QAction* theCmd);
76 //! Sets relation between the command (with given Id) and it's nested actions.
77 void addNestedCommands(const QString& theId, const QStringList& theCommands);
79 //! Returns list of nested commands by parent command Id
80 //! \param theId a parent command Id
81 QStringList nestedCommands(const QString& theId) const;
83 /// Returns True if the given Id is an Id of nested command
84 /// \param theId an Id to check
85 bool isNested(const QString& theId) const;
87 /// Registers shortcut (key sequence) for the command triggering
88 /// \param theKeySequence a key sequence to register
89 QKeySequence registerShortcut(const QKeySequence& theKeySequence);
91 /// This is an overloaded function.
92 /// Registers shortcut (key sequence) for the command triggering
93 /// \param theKeySequence - string that contain a key sequence to register
94 QKeySequence registerShortcut(const QString& theKeySequence);
96 //! Redefinition of Events_Listener method
97 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
99 //! Return property panel's action like ok, cancel, help.
100 //! If there is no such action, it will be created.
101 QAction* operationStateAction(OperationStateActionId theId);
103 /// Return an action by the given id, if it was registered in the manager
104 QAction* action(const QString& theId);
106 /// Return info (icon, text, etc) about the action by the given id,
107 /// if it was registered in the manager
108 ActionInfo actionInfoById(const QString& theId);
111 //! Update workbench actions according to OperationMgr state:
112 //! No active operations: all actions but nested are available
113 //! There is active operation: current operation + it's nested
114 //! are enabled, all the rest is disabled. All active commands is checked.
115 void updateCommandsStatus();
117 //! Sets all commands checked if it's operation is active.
118 void updateCheckState();
120 //! Updates actions according to current selection in the viewer
121 void updateOnViewSelection();
123 //! Sets all actions to enabled state.
124 void setAllEnabled();
126 //! Sets all nested actions to isEnabled state for the command with given ID.
127 //! If ID is empty - all nested actions will be affected.
128 void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
130 //! Sets to enabled state all siblings of the given operation and it's parents recursively
131 void setNestedStackEnabled(ModuleBase_Operation* theOperation);
133 //! Sets the action with theId to theChecked state.
134 void setActionChecked(const QString& theId, const bool theChecked);
136 //! Sets the action with theId to theEnabled state.
137 void setActionEnabled(const QString& theId, const bool theEnabled);
139 //! Updates actions according to their "document" tag
140 void updateByDocumentKind();
142 //! Asks plugins about their features state, using the Events system
143 void updateByPlugins(FeaturePtr theActiveFeature);
145 QStringList allNestedCommands(ModuleBase_Operation* theOperation);
149 QMap<QString, QAction*> myActions;
150 QMap<QString, QStringList> myNestedActions;
151 QMap<OperationStateActionId, QAction*> myOperationActions;
152 QList<QKeySequence> myShortcuts;
154 XGUI_Workshop* myWorkshop;
155 XGUI_OperationMgr* myOperationMgr;
157 friend class XGUI_Workshop;
160 #endif /* XGUI_ACTIONSMGR_H_ */