1 // File: XGUI_OperationMgr.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #ifndef XGUI_OperationMgr_H
6 #define XGUI_OperationMgr_H
10 #include <ModuleBase_Operation.h>
14 #include <QStringList>
18 /**\class XGUI_OperationMgr
20 * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack
21 * of started operations. In simple case, if only one operation 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 becomes 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.
27 class XGUI_EXPORT XGUI_OperationMgr : public QObject
32 /// \param theParent the parent
33 XGUI_OperationMgr(QObject* theParent);
35 virtual ~XGUI_OperationMgr();
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 /// Returns list of all operations IDs
45 QStringList operationList() const;
47 /// Returns previous (parent) operation if given operation started.
48 /// else, or if there is no parent - returns NULL
49 ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
51 virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
53 /// Start the operation and append it to the stack of operations
54 /// \param theOperation the started operation
55 /// \return the state whether the current operation is started
56 bool startOperation(ModuleBase_Operation* theOperation);
58 bool abortAllOperations();
61 /// Slot that commits the current operation.
62 void onCommitOperation();
63 /// Slot that aborts the current operation.
64 void onAbortOperation();
65 /// Slot that validates the current operation using the validateOperation method.
66 void onValidateOperation();
69 /// Signal about an operation is started. It is emitted after the start() of operation is done.
70 void operationStarted();
71 /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
72 /// \param theOperation a stopped operation
73 void operationStopped(ModuleBase_Operation* theOperation);
74 /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
75 void operationResumed();
76 /// Signal is emitted after the validate methods calls.
77 void operationValidated(bool);
78 /// Signal about the necessety of the next widget activating
79 /// \param theWidget the model widget
80 void activateNextWidget(ModuleBase_ModelWidget* theWidget);
84 /// Commits the current operatin if it is valid
85 bool commitOperation();
86 /// Sets the current operation or NULL
87 /// \param theOperation the started operation
88 /// \param isCheckBeforeStart the flag whether to check whether the operation can be started
89 /// \return the state whether the operation is resumed
90 void resumeOperation(ModuleBase_Operation* theOperation);
92 /// Checks if given operation is Valid, if so sends operationValidated signal
93 /// \param theOperation to be validated
94 /// \return validation state (true means valid)
95 bool validateOperation(ModuleBase_Operation* theOperation);
96 /// Returns whether the operation can be started. Check if there is already started operation and
97 /// the granted parameter of the launched operation
98 /// \param theOperation an operation to check
99 bool canStartOperation(ModuleBase_Operation* theOperation);
101 bool canStopOperation();
103 /// Returns true if the operation can be aborted
104 bool canAbortOperation();
107 /// SLOT, that is called by the key in the property panel is clicked.
108 /// \param theName the attribute name
109 /// \param theEvent the mouse event
110 void onKeyReleased(QKeyEvent* theEvent);
112 /// SLOT, that reacts to the widget activation
113 /// \param theWidget an activated widget
114 void onWidgetActivated(ModuleBase_ModelWidget* theWidget);
117 /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
118 /// If there is a suspended operation, restart it.
119 void onOperationStopped();
122 typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
123 Operations myOperations; ///< a stack of started operations. The active operation is on top,
124 // others are suspended and started by the active is finished