2 * ModuleBase_IOperation.h
4 * Created on: May 5, 2014
8 #ifndef ModuleBase_IOperation_H
9 #define ModuleBase_IOperation_H
11 #include <ModuleBase.h>
16 #include <QStringList>
18 #include <boost/shared_ptr.hpp>
20 class ModelAPI_Document;
21 class ModuleBase_OperationDescription;
22 //class ModuleBase_ModelWidget;
25 \class ModuleBase_IOperation
26 * \brief Base class for all operations
28 * Base class for all operations. If you perform an action it is reasonable to create
29 * operation intended for this. This is a base class for all operations which provides
30 * mechanism for correct starting operations, starting operations above already started
31 * ones, committing operations and so on. To create own operation it is reasonable to
32 * inherit it from this class and redefines virtual methods to provide own behavior
33 * Main virtual methods are
34 * - virtual bool isReadyToStart();
35 * - virtual void startOperation();
36 * - virtual void abortOperation();
37 * - virtual void commitOperation();
40 class MODULEBASE_EXPORT ModuleBase_IOperation : public QObject
46 /// Constructs an empty operation. Constructor should work very fast because many
47 /// operators may be created after starting workshop but only several from them
48 /// may be used. As result this constructor stores given workshop in myApp field
49 /// and set Waiting status.
50 /// \param theId the operation identifier
51 /// \param theParent the QObject parent
52 ModuleBase_IOperation(const QString& theId = "", QObject* theParent = 0);
54 virtual ~ModuleBase_IOperation();
56 /// Returns the operation description
57 /// /returns the instance of the description class
58 ModuleBase_OperationDescription* getDescription() const;
61 * Must return true if this operation can be launched as nested for any current operation
62 * and it is not necessary to check this operation on validity. By default
63 * the operation is not granted.
64 * The method has to be redefined for granted operations.
66 virtual bool isGranted() const { return false; }
69 * Must return True if the given opertation can be launched as nested to current one.
70 * By default it returns false and it has to be redefined for operations which expect
71 * launching of nested operations
73 virtual bool isValid(ModuleBase_IOperation* theOperation) const { return false; }
75 /// Sets a list of model widgets, according to the operation feature xml definition
76 /// \param theXmlRepresentation an xml feature definition
77 /// \param theWidgets a list of widgets
78 //void setModelWidgets(const std::string& theXmlRepresentation,
79 // QList<ModuleBase_ModelWidget*> theWidgets);
81 /// Returns True if data of its feature was modified during operation
82 virtual bool isModified() const
87 /// Returns True id the current operation is launched in editing mode
88 bool isEditOperation() const
93 /// Returns list of nested features
94 QStringList nestedFeatures() const { return myNestedFeatures; }
96 /// Sets list of nested features
97 void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
100 void started(); /// the operation is started
101 void aborted(); /// the operation is aborted
102 void committed(); /// the operation is committed
103 void stopped(); /// the operation is aborted or committed
104 void resumed(); /// the operation is resumed
108 /// Public slot. Verifies whether operation can be started and starts operation.
109 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
110 /// to change behavior of operation. There is no point in using this method. It would
111 /// be better to inherit own operator from base one and redefine startOperation method
114 /// Resumes operation
115 /// Public slot. Verifies whether operation can be started and starts operation.
116 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
117 /// to change behavior of operation. There is no point in using this method. It would
118 /// be better to inherit own operator from base one and redefine startOperation method
122 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
123 /// Redefine abortOperation method to change behavior of operation instead
125 /// Commits operation
126 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
127 /// Redefine commitOperation method to change behavior of operation instead
130 /// Alias for start/abort slots
131 /// Public slot. Aborts operation if false, else does nothing.
132 /// Provided for S/S compatibility with QAction's toggle(bool)
133 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
134 void setRunning(bool theState);
136 // Data model methods.
137 /// Stores a custom value in model.
138 virtual void storeCustomValue() = 0;
141 /// Virtual method called when operation started (see start() method for more description)
142 /// Default impl calls corresponding slot and commits immediately.
143 virtual void startOperation() = 0;
145 /// Virtual method called when operation stopped - committed or aborted.
146 virtual void stopOperation() = 0;
148 /// Virtual method called when operation aborted (see abort() method for more description)
149 virtual void abortOperation() = 0;
151 /// Virtual method called when operation committed (see commit() method for more description)
152 virtual void commitOperation() = 0;
154 /// Virtual method called after operation committed (see commit() method for more description)
155 /// it is important that the method is called after the stop() signal is emitted
156 virtual void afterCommitOperation() = 0;
158 /// Verifies whether this operator can be commited.
159 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
160 virtual bool canBeCommitted() const;
162 /// Returns pointer to the root document.
163 boost::shared_ptr<ModelAPI_Document> document() const;
165 /// Editing feature flag
168 /// Modified feature flag
172 ModuleBase_OperationDescription* myDescription; /// the container to have the operation description
174 QStringList myNestedFeatures;