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(ModuleBase_IOperation* theOperation) const { return false; }
69 * Must return True if the operation's feature is valid.
70 * Since IOperation does not have any feature returns false.
72 virtual bool isValid() const { return false; }
74 /// Sets a list of model widgets, according to the operation feature xml definition
75 /// \param theXmlRepresentation an xml feature definition
76 /// \param theWidgets a list of widgets
77 //void setModelWidgets(const std::string& theXmlRepresentation,
78 // QList<ModuleBase_ModelWidget*> theWidgets);
80 /// Returns True if data of its feature was modified during operation
81 virtual bool isModified() const
86 /// Returns True id the current operation is launched in editing mode
87 bool isEditOperation() const
92 /// Returns list of nested features
93 QStringList nestedFeatures() const { return myNestedFeatures; }
95 /// Sets list of nested features
96 void setNestedFeatures(const QStringList& theList) { myNestedFeatures = theList; }
99 void started(); /// the operation is started
100 void aborted(); /// the operation is aborted
101 void committed(); /// the operation is committed
102 void stopped(); /// the operation is aborted or committed
103 void resumed(); /// the operation is resumed
107 /// Public slot. Verifies whether operation can be started and starts operation.
108 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
109 /// to change behavior of operation. There is no point in using this method. It would
110 /// be better to inherit own operator from base one and redefine startOperation method
113 /// Resumes operation
114 /// Public slot. Verifies whether operation can be started and starts operation.
115 /// This slot is not virtual and cannot be redefined. Redefine startOperation method
116 /// to change behavior of operation. There is no point in using this method. It would
117 /// be better to inherit own operator from base one and redefine startOperation method
121 /// Public slot. Aborts operation. This slot is not virtual and cannot be redefined.
122 /// Redefine abortOperation method to change behavior of operation instead
124 /// Commits operation
125 /// Public slot. Commits operation. This slot is not virtual and cannot be redefined.
126 /// Redefine commitOperation method to change behavior of operation instead
129 /// Alias for start/abort slots
130 /// Public slot. Aborts operation if false, else does nothing.
131 /// Provided for S/S compatibility with QAction's toggle(bool)
132 /// \param theState th flag to abort, if it is true, do nothing, overwise abort
133 void setRunning(bool theState);
135 // Data model methods.
136 /// Stores a custom value in model.
137 virtual void storeCustomValue() = 0;
140 /// Virtual method called when operation started (see start() method for more description)
141 /// Default impl calls corresponding slot and commits immediately.
142 virtual void startOperation() = 0;
144 /// Virtual method called when operation stopped - committed or aborted.
145 virtual void stopOperation() = 0;
147 /// Virtual method called when operation aborted (see abort() method for more description)
148 virtual void abortOperation() = 0;
150 /// Virtual method called when operation committed (see commit() method for more description)
151 virtual void commitOperation() = 0;
153 /// Virtual method called after operation committed (see commit() method for more description)
154 /// it is important that the method is called after the stop() signal is emitted
155 virtual void afterCommitOperation() = 0;
157 /// Verifies whether this operator can be commited.
158 /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
159 virtual bool canBeCommitted() const;
161 /// Returns pointer to the root document.
162 boost::shared_ptr<ModelAPI_Document> document() const;
164 /// Editing feature flag
167 /// Modified feature flag
171 ModuleBase_OperationDescription* myDescription; /// the container to have the operation description
173 QStringList myNestedFeatures;