Line data Source code
1 : #ifndef SYNCOPERATION_H
2 : #define SYNCOPERATION_H
3 :
4 : #include <QObject>
5 : #include <QString>
6 :
7 : #include "../FangObject.h"
8 :
9 : class OperationManager;
10 :
11 : /*!
12 : \brief Base class for synchronous operations. This is mainly used for operations that
13 : complete quickly and/or need to happen in a certain order, such as database operations.
14 : */
15 : class SyncOperation : public FangObject
16 : {
17 : Q_OBJECT
18 :
19 : public:
20 : explicit SyncOperation(OperationManager* parent);
21 20 : virtual ~SyncOperation() = default;
22 :
23 : /*!
24 : \brief Executes the operation synchronously.
25 : */
26 : virtual void execute() = 0;
27 :
28 : /*!
29 : \return Returns true if there was an error, else false.
30 : */
31 : bool hasError() const { return error; }
32 :
33 : /*!
34 : \return Error message, if any.
35 : */
36 : QString errorMessage() const { return errorMsg; }
37 :
38 : protected:
39 :
40 : /*!
41 : \brief Call this to report an error. Logs the error and sets the error flag.
42 : Unlike AsyncOperation::reportError(), this does NOT emit any signals.
43 : \param errorString The text that will be logged along with the error.
44 : */
45 : void reportError(const QString& errorString);
46 :
47 : private:
48 : OperationManager* operationManager;
49 : bool error = false;
50 : QString errorMsg;
51 : };
52 :
53 : #endif // SYNCOPERATION_H
|