Salome HOME
Minor code correction
[modules/shaper.git] / src / XGUI / XGUI_ActionsMgr.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef XGUI_ActionsMgr_H
22 #define XGUI_ActionsMgr_H
23
24 #include "XGUI.h"
25
26 #include <Events_Listener.h>
27 #include <ModelAPI_Feature.h>
28
29 #include <ModuleBase_ActionInfo.h>
30
31 #include <QObject>
32 #include <QMap>
33 #include <QList>
34 #include <QStringList>
35 #include <QKeySequence>
36
37 class XGUI_Workshop;
38 class XGUI_OperationMgr;
39 class ModuleBase_Operation;
40 class QAction;
41
42 /// class XGUI_ActionsMgr
43 /// \ingroup GUI
44 /// A class for management of actions (features) activation/deactivation
45 class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
46 {
47   Q_OBJECT
48
49  public:
50   /// Constructor
51   /// \param theWorkshop an instance of workshop
52   XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
53   virtual ~XGUI_ActionsMgr();
54
55   /// Actions on operations
56   enum OperationStateActionId {
57     Abort = 0,
58     Accept = 1,
59     Help = 2,
60     AbortAll = 3,
61     AcceptAll = 4,
62     Preview = 5
63   };
64
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);
69
70   /// Sets relation between the command (with given Id) and it's nested actions.
71   void addNestedCommands(const QString& theId, const QStringList& theCommands);
72
73   /// Returns list of nested commands by parent command Id
74   /// \param theId a parent command Id
75   QStringList nestedCommands(const QString& theId) const;
76
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;
80
81   /// Registers shortcut (key sequence) for the command triggering
82   /// \param theKeySequence a key sequence to register
83   QKeySequence registerShortcut(const QKeySequence& theKeySequence);
84
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);
89
90   /// Redefinition of Events_Listener method
91   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
92
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);
96
97   /// Return an action by the given id, if it was registered in the manager
98   QAction* action(const QString& theId);
99
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);
103
104  private:
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();
110
111   /// Sets all commands checked if it's operation is active.
112   void updateCheckState();
113
114   /// Updates actions according to current selection in the viewer
115   void updateOnViewSelection();
116
117   /// Sets all actions to enabled state.
118   void setAllEnabled();
119
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());
123
124   /// Sets to enabled state all siblings of the given operation and it's parents recursively
125   void setNestedStackEnabled(ModuleBase_Operation* theOperation);
126
127   /// Sets the action with theId to theChecked state.
128   void setActionChecked(const QString& theId, const bool theChecked);
129
130   /// Sets the action with theId to theEnabled state.
131   void setActionEnabled(const QString& theId, const bool theEnabled);
132
133   /// Updates actions according to their "document" tag
134   void updateByDocumentKind();
135
136   /// Asks plugins about their features state, using the Events system
137   void updateByPlugins(FeaturePtr theActiveFeature);
138
139   /// Returns names of nested action for the feature of given operation
140   /// \param theOperation an operation
141   QStringList allNestedCommands(ModuleBase_Operation* theOperation);
142
143  private:
144
145   QMap<QString, QAction*> myActions;
146   QMap<QString, QStringList> myNestedActions;
147   QMap<OperationStateActionId, QAction*> myOperationActions;
148   QList<QKeySequence> myShortcuts;
149
150   XGUI_Workshop* myWorkshop;
151   XGUI_OperationMgr* myOperationMgr;
152
153   friend class XGUI_Workshop;
154 };
155
156 #endif /* XGUI_ActionsMgr_H */
157