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