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 {
70 //! Add a command in the manager.
71 //! Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
72 //! won't be extracted and should be added manually using the addNestedCommands method.
73 void addCommand(QAction* theCmd);
75 //! Sets relation between the command (with given Id) and it's nested actions.
76 void addNestedCommands(const QString& theId, const QStringList& theCommands);
78 //! Returns list of nested commands by parent command Id
79 //! \param theId a parent command Id
80 QStringList nestedCommands(const QString& theId) const;
82 /// Returns True if the given Id is an Id of nested command
83 /// \param theId an Id to check
84 bool isNested(const QString& theId) const;
86 /// Registers shortcut (key sequence) for the command triggering
87 /// \param theKeySequence a key sequence to register
88 QKeySequence registerShortcut(const QKeySequence& theKeySequence);
90 /// This is an overloaded function.
91 /// Registers shortcut (key sequence) for the command triggering
92 /// \param theKeySequence - string that contain a key sequence to register
93 QKeySequence registerShortcut(const QString& theKeySequence);
95 //! Redefinition of Events_Listener method
96 virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
98 //! Return property panel's action like ok, cancel, help.
99 //! If there is no such action, it will be created.
100 QAction* operationStateAction(OperationStateActionId theId);
102 /// Return an action by the given id, if it was registered in the manager
103 QAction* action(const QString& theId);
105 /// Return info (icon, text, etc) about the action by the given id,
106 /// if it was registered in the manager
107 ActionInfo actionInfoById(const QString& theId);
110 //! Update workbench actions according to OperationMgr state:
111 //! No active operations: all actions but nested are available
112 //! There is active operation: current operation + it's nested
113 //! are enabled, all the rest is disabled. All active commands is checked.
114 void updateCommandsStatus();
116 //! Sets all commands checked if it's operation is active.
117 void updateCheckState();
119 //! Updates actions according to current selection in the viewer
120 void updateOnViewSelection();
122 //! Sets all actions to enabled state.
123 void setAllEnabled();
125 //! Sets all nested actions to isEnabled state for the command with given ID.
126 //! If ID is empty - all nested actions will be affected.
127 void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
129 //! Sets to enabled state all siblings of the given operation and it's parents recursively
130 void setNestedStackEnabled(ModuleBase_Operation* theOperation);
132 //! Sets the action with theId to theChecked state.
133 void setActionChecked(const QString& theId, const bool theChecked);
135 //! Sets the action with theId to theEnabled state.
136 void setActionEnabled(const QString& theId, const bool theEnabled);
138 //! Updates actions according to their "document" tag
139 void updateByDocumentKind();
141 //! Asks plugins about their features state, using the Events system
142 void updateByPlugins(FeaturePtr theActiveFeature);
144 QStringList allNestedCommands(ModuleBase_Operation* theOperation);
148 QMap<QString, QAction*> myActions;
149 QMap<QString, QStringList> myNestedActions;
150 QMap<OperationStateActionId, QAction*> myOperationActions;
151 QList<QKeySequence> myShortcuts;
153 XGUI_Workshop* myWorkshop;
154 XGUI_OperationMgr* myOperationMgr;
156 friend class XGUI_Workshop;
159 #endif /* XGUI_ACTIONSMGR_H_ */