Salome HOME
Issue #348 Validate sketch is disabled when point coordinates are set manually
[modules/shaper.git] / src / XGUI / XGUI_ActionsMgr.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 /*
4  * XGUI_ActionsMgr.h
5  */
6
7 #ifndef XGUI_ACTIONSMGR_H_
8 #define XGUI_ACTIONSMGR_H_
9
10 #include "XGUI.h"
11
12 #include <Events_Listener.h>
13 #include <ModelAPI_Feature.h>
14
15 #include <QObject>
16 #include <QMap>
17 #include <QList>
18 #include <QStringList>
19 #include <QKeySequence>
20
21 class XGUI_Workshop;
22 class XGUI_OperationMgr;
23 class ModuleBase_Operation;
24 class QAction;
25
26 class XGUI_EXPORT XGUI_ActionsMgr : public QObject, public Events_Listener
27 {
28 Q_OBJECT
29
30  public:
31   XGUI_ActionsMgr(XGUI_Workshop* theWorkshop);
32   virtual ~XGUI_ActionsMgr();
33
34   //! Add a command in the manager.
35   //! Please note that nested commands in the Salome mode (No AppElements_Command, pure QActions)
36   //! won't be extracted and should be added manually using the addNestedCommands method.
37   void addCommand(QAction* theCmd);
38   //! Sets relation between the command (with given Id) and it's nested actions.
39   void addNestedCommands(const QString& theId, const QStringList& theCommands);
40
41   QStringList nestedCommands(const QString& theId) const;
42
43   bool isNested(const QString& theId) const;
44
45   QKeySequence registerShortcut(const QString& theKeySequence);
46
47   //! Redefinition of Events_Listener method
48   virtual void processEvent(const std::shared_ptr<Events_Message>& theMessage);
49
50  public slots:
51   //! Update workbench actions according to OperationMgr state:
52   //! No active operations: all actions but nested are available
53   //! There is active operation: current operation + it's nested
54   //! are enabled, all the rest is disabled. All active commands is checked.
55   void update();
56   //! Sets all commands checked if it's operation is active.
57   void updateCheckState();
58   //! Updates actions according to current selection in the viewer
59   void updateOnViewSelection();
60
61  protected:
62   //! Sets all actions to isEnabled state.
63   void setAllEnabled(bool isEnabled);
64   //! Sets all nested actions to isEnabled state for the command with given ID.
65   //! If ID is empty - all nested actions will be affected.
66   void setNestedCommandsEnabled(bool isEnabled, const QString& theParent = QString());
67   //! Sets to enabled state all siblings of the given operation and it's parents recursively
68   void setNestedStackEnabled(ModuleBase_Operation* theOperation);
69   //! Sets the action with theId to theChecked state.
70   void setActionChecked(const QString& theId, const bool theChecked);
71   //! Sets the action with theId to theEnabled state.
72   void setActionEnabled(const QString& theId, const bool theEnabled);
73   //! Updates actions according to their "document" tag
74   void updateByDocumentKind();
75   //! Asks plugins about their features state, using the Events system
76   void updateByPlugins(FeaturePtr theActiveFeature);
77
78  private:
79   QMap<QString, QAction*> myActions;
80   QMap<QString, QStringList> myNestedActions;
81   QList<QKeySequence> myShortcuts;
82
83   XGUI_Workshop* myWorkshop;
84   XGUI_OperationMgr* myOperationMgr;
85 };
86
87 #endif /* XGUI_ACTIONSMGR_H_ */
88