1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
4 * ModuleBase_Operation.h
6 * Created on: Apr 2, 2014
10 #ifndef ModuleBase_Operation_H
11 #define ModuleBase_Operation_H
13 #include <ModuleBase.h>
17 #include <QStringList>
19 class ModuleBase_ModelWidget;
20 class ModuleBase_OperationDescription;
21 class ModuleBase_IPropertyPanel;
26 * \class ModuleBase_Operation
28 * \brief Base class for all operations
30 * Base class for all operations. If you perform an action it is reasonable to create
31 * operation intended for this. This is a base class for all operations which provides
32 * mechanism for correct starting operations, starting operations above already started
33 * ones, committing operations and so on. To create own operation it is reasonable to
34 * inherit it from this class and redefines virtual methods to provide own behavior
35 * Main virtual methods are
36 * - virtual bool isReadyToStart();
37 * - virtual void startOperation();
38 * - virtual void abortOperation();
39 * - virtual void commitOperation();
42 class MODULEBASE_EXPORT ModuleBase_Operation : public QObject
48 /// \param theId the operation identifier
49 /// \param theParent the QObject parent
50 ModuleBase_Operation(const QString& theId = "", QObject* theParent = 0);
53 virtual ~ModuleBase_Operation();
55 /// Returns the operation description
56 /// /returns the instance of the description class
57 ModuleBase_OperationDescription* getDescription() const { return myDescription; }
59 /// Returns list of granted operation indices
60 const QStringList& grantedOperationIds() const;
62 /// Sets list of operation indices, which can be started without the current operation stop
63 /// \param theList an ids
64 void setGrantedOperationIds(const QStringList& theList);
66 /// Must return true if this operation can be launched as nested for any current operation
67 /// and it is not necessary to check this operation on validity. By default
68 /// the operation is not granted.
69 /// The method has to be redefined for granted operations.
70 virtual bool isGranted(QString theId) const;
72 /// Returns True if data of its feature was modified during operation
73 virtual bool isModified() const { return myIsModified; }
75 /// Change the modified state of the operation
76 void setIsModified(const bool theIsModified) { myIsModified = theIsModified; }
78 /// Returns operations Id from it's description
81 /// Must return True if the operation's feature is valid.
82 /// Since IOperation does not have any feature returns false.
83 virtual bool isValid() const;
85 /// \brief Set property pane to the operation
86 /// \param theProp a property panel instance
87 virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp);
89 /// \return Currently installed property panel
90 ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; }
93 /// The operation is started
95 /// The operation is started
98 /// The operation is aborted
100 /// The operation is aborted
103 /// The operation is committed
104 void beforeCommitted();
105 /// The operation is committed
108 /// The operation is aborted or committed
111 /// The operation is resumed
114 /// The operation is postponed
119 /// Public slot. Verifies whether operation can be started and starts operation.
120 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
121 /// to change behavior of operation. There is no point in using this method. It would
122 /// be better to inherit own operator from base one and redefine startOperation method
124 /// \return true if the start is successful
125 virtual bool start();
127 /// Deactivates current operation which can be resumed later.
128 virtual void postpone();
130 /// Resumes operation
131 /// Public slot. Verifies whether operation can be started and starts operation.
132 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
133 /// to change behavior of operation. There is no point in using this method. It would
134 /// be better to inherit own operator from base one and redefine startOperation method
136 virtual void resume();
139 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
140 /// Redefine abortOperation method to change behavior of operation instead
141 virtual void abort();
143 /// Commits operation
144 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
145 /// Redefine commitOperation method to change behavior of operation instead
146 virtual bool commit();
148 /// Changes the modified flag of the operation
149 void onValuesChanged();
151 /// Changes the modified flag of the operation if the current state of the widget is modified
152 /// \param thePreviousState the previous vlaue state of the widget
153 void onValueStateChanged(int thePreviousState);
156 /// Virtual method called when operation started (see start() method for more description)
157 /// Default impl calls corresponding slot and commits immediately.
158 virtual void startOperation() {}
160 /// Implementation of specific steps on postpone operation
161 virtual void postponeOperation() {}
163 /// Virtual method called when operation stopped - committed or aborted.
164 virtual void stopOperation() {}
166 /// Virtual method called when operation aborted (see abort() method for more description)
167 virtual void abortOperation() {}
169 /// Virtual method called when operation committed (see commit() method for more description)
170 virtual void commitOperation() {};
172 /// Virtual method called after operation committed (see commit() method for more description)
173 virtual void afterCommitOperation() {}
175 /// Virtual method called after operation resume (see resume() method for more description)
176 virtual void resumeOperation() {}
178 /// Verifies whether this operator can be commited.
179 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
180 virtual bool canBeCommitted() const;
183 /// the container to have the operation description
184 ModuleBase_OperationDescription* myDescription;
186 /// Modified feature flag
189 /// List of operations IDs which are granted of the current operation
190 QStringList myGrantedIds;
192 /// Access to property panel
193 ModuleBase_IPropertyPanel* myPropertyPanel;