Salome HOME
f6632c161631d3b04c8ea152d09c3632d6b71cd5
[modules/shaper.git] / src / XGUI / XGUI_OperationMgr.h
1 // File:        XGUI_OperationMgr.h
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef XGUI_OperationMgr_H
6 #define XGUI_OperationMgr_H
7
8 #include "XGUI.h"
9
10 #include <ModuleBase_Operation.h>
11
12 #include <QList>
13 #include <QObject>
14 #include <QStringList>
15
16 class QKeyEvent;
17
18 /**\class XGUI_OperationMgr
19  * \ingroup GUI
20  * \brief Operation manager. Servers to manupulate to the workshop operations. Contains a stack
21  * of started operations. In simple case, if only one operration is started, the stack contains
22  * one operation. It is possible for some kind of operations to start them above already
23  * started one. In that case, the previous active operation becames suspended, a new one - active.
24  * The new operation is added to the top of the stack. Then it is finished, it is removed from
25  * the stack and the previous operation is activated.
26  */
27 class XGUI_EXPORT XGUI_OperationMgr : public QObject
28 {
29   Q_OBJECT
30 public:
31   /// Constructor
32   /// \param theParent the parent
33   XGUI_OperationMgr(QObject* theParent);
34   /// Destructor
35   virtual ~XGUI_OperationMgr();
36
37   /// Returns the current operation or NULL
38   /// \return the current operation
39   ModuleBase_Operation* currentOperation() const;
40   /// Returns true is operation manager has at least one non-null operation.
41   bool hasOperation() const;
42   /// Returns number of operations in the stack
43   int operationsCount() const;
44   /// Start the operation and append it to the stack of operations
45   /// \param theOperation the started operation
46   /// \return the state whether the current operation is started
47   bool startOperation(ModuleBase_Operation* theOperation);
48
49   /// Abort the operation and append it to the stack of operations
50   /// \return the state whether the current operation is aborted
51   bool abortOperation();
52   ///Returns list of all operations IDs
53   QStringList operationList();
54
55   virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
56
57 signals:
58   /// Signal about an operation is started. It is emitted after the start() of operation is done.
59   void operationStarted();
60   /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
61   /// \param theOperation a stopped operation
62   void operationStopped(ModuleBase_Operation* theOperation);
63   /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
64   void operationResumed();
65   /// Signal about the necessety of the next widget activating
66   /// \param theWidget the model widget
67   void activateNextWidget(ModuleBase_ModelWidget* theWidget);
68
69 protected:
70   /// Sets the current operation or NULL
71   /// \param theOperation the started operation
72   /// \param isCheckBeforeStart the flag whether to check whether the operation can be started
73   /// \return the state whether the operation is resumed
74   void resumeOperation(ModuleBase_Operation* theOperation);
75
76   /// Returns whether the operation can be started. Check if there is already started operation and
77   /// the granted parameter of the launched operation
78   /// \param theOperation an operation to check
79   bool canStartOperation(ModuleBase_Operation* theOperation);
80
81   /// Returns whether the operation can be stopped.
82   bool canStopOperation();
83
84   /// Returns true if the operation can be aborted
85   bool canAbortOperation();
86
87 protected slots:
88   /// Slot that commits the current operation.
89   void onCommitOperation();
90   /// Slot that aborts the current operation.
91   void onAbortOperation();
92
93   /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
94   /// If there is a suspended operation, restart it.
95   void onOperationStopped();
96
97   /// SLOT, that is called by the key in the property panel is clicked.
98   /// \param theName the attribute name
99   /// \param theEvent the mouse event
100   void onKeyReleased(const std::string& theName, QKeyEvent* theEvent);
101
102   /// SLOT, that reacts to the widget activation
103   /// \param theWidget an activated widget
104   void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
105
106 private:
107   typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
108   Operations myOperations; ///< a stack of started operations. The active operation is on top,
109                            // others are suspended and started by the active is finished
110 };
111
112 #endif