2 * ModuleBase_Operation.h
4 * Created on: Apr 2, 2014
9 #ifndef MODULEBASE_OPERATION_H
10 #define MODULEBASE_OPERATION_H
12 #include <ModuleBase.h>
21 class ModelAPI_Feature;
22 class ModelAPI_Document;
25 \class ModuleBase_Operation
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_Operation: public QObject
45 /*! Enum describes state of operation */
48 Waiting, //!< Operation is not used (it is not run or suspended)
49 Running //!< Operation is started
53 * Enum describes execution status of operation. Execution status often used after
54 * ending work of operation which was started from this one. In this case this
55 * operation can ask previously started operation whether it finished successfully.
59 Rejected, //!< Operation has not performed any action (modification of data model for example)
60 Accepted //!< Operation has performed an actions and must be stopped
64 * Enum describes setting of the operation.
68 None = 0x00, //!< None options
69 Transaction = 0x01 //!< Automatically open (commit/abort) transaction during start (commit/abort).
73 ModuleBase_Operation(const QString& theId = "", QObject* parent = 0);
74 virtual ~ModuleBase_Operation();
76 // Operation processing.
77 virtual QString operationId() const;
79 std::shared_ptr<ModelAPI_Feature> feature() const;
81 OperationState state() const;
82 bool isRunning() const;
83 virtual bool isValid(ModuleBase_Operation* theOtherOp) const;
84 virtual bool isGranted() const;
86 bool setSlot(const QObject* theReceiver, const char* theSlot);
88 void setFlags(const int);
89 void clearFlags(const int);
90 bool testFlags(const int) const;
92 int execStatus() const;
95 const QString& xmlRepresentation() const;
96 void setXmlRepresentation(const QString& xmlRepr);
102 void stopped(); //!< operation aborted or committed
111 //true = do nothing, false = abort()
112 //Provided for S/S compatibility with QAction's toggle(bool)
113 void setRunning(bool);
115 // Data model operations.
116 void storeReal(double);
119 virtual bool isReadyToStart() const;
121 virtual void startOperation();
122 virtual void stopOperation();
123 virtual void abortOperation();
124 virtual void commitOperation();
126 void setExecStatus(const int);
127 void setState(const OperationState);
129 std::shared_ptr<ModelAPI_Document> document() const;
132 int myFlags; //!< Operation flags
133 OperationState myState; //!< Operation state
134 ExecStatus myExecStatus; //!< Execution status
136 //!< Next fields could be extracted into a subclass;
137 QString myOperationId;
139 std::shared_ptr<ModelAPI_Feature> myFeature;