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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
24 #ifndef XGUI_ACTIONSMGR_H_
25 #define XGUI_ACTIONSMGR_H_
29 #include <Events_Listener.h>
30 #include <ModelAPI_Feature.h>
32 #include <ModuleBase_ActionInfo.h>
37 #include <QStringList>
38 #include <QKeySequence>
41 class XGUI_OperationMgr;
42 class ModuleBase_Operation;
47 * A class for management of actions (features) activation/deactivation
49 class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
55 /// \param theWorkshop an instance of workshop
56 XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
57 virtual ~XGUI_ActionsMgr();
59 /// Actions on operations
60 enum OperationStateActionId {
69 //! Add a command in the manager.
70 //! Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
71 //! won't be extracted and should be added manually using the addNestedCommands method.
72 void addCommand(QAction* theCmd);
74 //! Sets relation between the command (with given Id) and it's nested actions.
75 void addNestedCommands(const QString& theId, const QStringList& theCommands);
77 //! Returns list of nested commands by parent command Id
78 //! \param theId a parent command Id
79 QStringList nestedCommands(const QString& theId) const;
81 /// Returns True if the given Id is an Id of nested command
82 /// \param theId an Id to check
83 bool isNested(const QString& theId) const;
85 /// Registers shortcut (key sequence) for the command triggering
86 /// \param theKeySequence a key sequence to register
87 QKeySequence registerShortcut(const QKeySequence& theKeySequence);
89 /// This is an overloaded function.
90 /// Registers shortcut (key sequence) for the command triggering
91 /// \param theKeySequence - string that contain a key sequence to register
92 QKeySequence registerShortcut(const QString& theKeySequence);
94 //! Redefinition of Events_Listener method
95 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
97 //! Return property panel's action like ok, cancel, help.
98 //! If there is no such action, it will be created.
99 QAction* operationStateAction(OperationStateActionId theId);
101 /// Return an action by the given id, if it was registered in the manager
102 QAction* action(const QString& theId);
104 /// Return info (icon, text, etc) about the action by the given id,
105 /// if it was registered in the manager
106 ActionInfo actionInfoById(const QString& theId);
109 //! Update workbench actions according to OperationMgr state:
110 //! No active operations: all actions but nested are available
111 //! There is active operation: current operation + it's nested
112 //! are enabled, all the rest is disabled. All active commands is checked.
113 void updateCommandsStatus();
115 //! Sets all commands checked if it's operation is active.
116 void updateCheckState();
118 //! Updates actions according to current selection in the viewer
119 void updateOnViewSelection();
121 //! Sets all actions to enabled state.
122 void setAllEnabled();
124 //! Sets all nested actions to isEnabled state for the command with given ID.
125 //! If ID is empty - all nested actions will be affected.
126 void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
128 //! Sets to enabled state all siblings of the given operation and it's parents recursively
129 void setNestedStackEnabled(ModuleBase_Operation* theOperation);
131 //! Sets the action with theId to theChecked state.
132 void setActionChecked(const QString& theId, const bool theChecked);
134 //! Sets the action with theId to theEnabled state.
135 void setActionEnabled(const QString& theId, const bool theEnabled);
137 //! Updates actions according to their "document" tag
138 void updateByDocumentKind();
140 //! Asks plugins about their features state, using the Events system
141 void updateByPlugins(FeaturePtr theActiveFeature);
143 QStringList allNestedCommands(ModuleBase_Operation* theOperation);
147 QMap<QString, QAction*> myActions;
148 QMap<QString, QStringList> myNestedActions;
149 QMap<OperationStateActionId, QAction*> myOperationActions;
150 QList<QKeySequence> myShortcuts;
152 XGUI_Workshop* myWorkshop;
153 XGUI_OperationMgr* myOperationMgr;
155 friend class XGUI_Workshop;
158 #endif /* XGUI_ACTIONSMGR_H_ */