1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: XGUI_OperationMgr.h
4 // Created: 20 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #ifndef XGUI_OperationMgr_H
8 #define XGUI_OperationMgr_H
12 #include <ModuleBase_Operation.h>
16 #include <QStringList>
20 class ModuleBase_IWorkshop;
22 /**\class XGUI_OperationMgr
24 * \brief Operation manager. Servers to manipulate to the workshop operations. Contains a stack
25 * of started operations. In simple case, if only one operation is started, the stack contains
26 * one operation. It is possible for some kind of operations to start them above already
27 * started one. In that case, the previous active operation becomes suspended, a new one - active.
28 * The new operation is added to the top of the stack. Then it is finished, it is removed from
29 * the stack and the previous operation is activated.
31 class XGUI_EXPORT XGUI_OperationMgr : public QObject
36 /// \param theParent the parent
37 XGUI_OperationMgr(QObject* theParent, ModuleBase_IWorkshop* theWorkshop);
39 virtual ~XGUI_OperationMgr();
41 void setWorkshop(ModuleBase_IWorkshop* theWorkshop)
42 { myWorkshop = theWorkshop; };
44 /// Returns the current operation or NULL
45 /// \return the current operation
46 ModuleBase_Operation* currentOperation() const;
48 /// Check if the given operation is active operation.
49 /// Also, returns false is ther is no active operation.
50 bool isCurrentOperation(ModuleBase_Operation* theOperation);
52 /// Returns true is operation manager has at least one non-null operation.
53 bool hasOperation() const;
55 /// Returns true is operation manager has an operation with given Id.
56 bool hasOperation(const QString& theId) const;
58 /// Returns true if the operation can be aborted
59 bool canStopOperation();
61 /// Find and return operation by its Id.
62 ModuleBase_Operation* findOperation(const QString& theId) const;
64 /// Returns number of operations in the stack
65 int operationsCount() const;
67 /// Returns list of all operations IDs
68 QStringList operationList() const;
70 /// Returns previous (parent) operation if given operation started.
71 /// else, or if there is no parent - returns NULL
72 ModuleBase_Operation* previousOperation(ModuleBase_Operation* theOperation) const;
74 /// Redefinition of virtual function
75 virtual bool eventFilter(QObject *theObject, QEvent *theEvent);
77 /// Start the operation and append it to the stack of operations
78 /// \param theOperation the started operation
79 /// \return the state whether the current operation is started
80 bool startOperation(ModuleBase_Operation* theOperation);
82 /// Returns whether the operation can be started. Check if there is already started operation and
83 /// the granted parameter of the launched operation
84 /// \param theId id of the operation which is going to start
85 bool canStartOperation(QString theId);
87 /// Blocking/unblocking enabling of Ok button in property panel.
88 /// It is used when operation can not be validated even all attributes are valid
89 void setLockValidating(bool toLock);
91 /// Returns state of validation locking
92 bool isValidationLocked() const { return myIsValidationLock; }
94 /// Returns enable apply state
95 /// \return theEnabled a boolean value
96 bool isApplyEnabled() const;
98 /// Returns valid state of the parent operation. If the current operation is the last one
99 /// it returns the valid state of the operation
100 /// \return boolean value
101 bool isParentOperationValid() const;
104 /// Slot that commits the current operation.
105 void onCommitOperation();
106 /// Slot that aborts the current operation.
107 void onAbortOperation();
108 /// Slot that validates the current operation using the validateOperation method.
109 void onValidateOperation();
110 /// Commit all operations
111 bool commitAllOperations();
112 /// Abort all operations
113 bool abortAllOperations();
116 /// Signal about an operation is started. It is emitted after the start() of operation is done.
117 void operationStarted(ModuleBase_Operation* theOperation);
119 /// Signal about an operation is stopped. It is emitted after the stop() of operation is done.
120 /// \param theOperation a stopped operation
121 void operationStopped(ModuleBase_Operation* theOperation);
123 /// Signal about an operation is resumed. It is emitted after the resume() of operation is done.
124 void operationResumed(ModuleBase_Operation* theOperation);
126 /// Emitted when current operation is Committed
127 void operationCommitted(ModuleBase_Operation* theOperation);
129 /// Emitted when current operation is aborted
130 void operationAborted(ModuleBase_Operation* theOperation);
132 /// Signal is emitted after the apply enable state changed.
133 void validationStateChanged(bool);
135 /// Signal is emitted after the apply enable state changed.
136 void nestedStateChanged(bool);
138 /// Signal is emitted after the current operation is filled with existing preselection.
139 void operationActivatedByPreselection();
141 /// Signal is emitted after the key released click.
142 void keyEnterReleased();
145 /// Sets apply state to the value and emit signal about this state is changed
146 /// \param theEnabled the state value
147 void setApplyEnabled(const bool theEnabled);
149 /// Commits the current operatin if it is valid
150 bool commitOperation();
152 /// Sets the current operation or NULL
153 /// \param theOperation the started operation
154 void resumeOperation(ModuleBase_Operation* theOperation);
157 /// SLOT, that is called by the key in the property panel is clicked.
158 /// \param theEvent the mouse event
159 bool onKeyReleased(QKeyEvent* theEvent);
162 /// Slot that is called by an operation stop. Removes the stopped operation form the stack.
163 /// If there is a suspended operation, restart it.
164 void onOperationStopped();
166 /// Slot called on operation start
167 void onOperationStarted();
169 /// Slot called on operation abort
170 void onOperationAborted();
172 /// Slot called on operation commit
173 void onOperationCommitted();
175 /// Slot called on operation resume
176 void onOperationResumed();
178 /// Slot called on operation triggered
179 void onOperationTriggered(bool theState);
182 typedef QList<ModuleBase_Operation*> Operations; ///< definition for a list of operations
183 Operations myOperations; ///< a stack of started operations. The active operation is on top,
184 // others are suspended and started by the active is finished
187 ModuleBase_IWorkshop* myWorkshop;
190 /// Lock/Unlock access to Ok button in property panel
191 bool myIsValidationLock;
192 /// Lock/Unlock access to Ok button in property panel
193 bool myIsApplyEnabled;