Line data Source code
1 : #include "AsyncOperation.h"
2 : #include "../db/DB.h"
3 : #include "../utilities/ErrorHandling.h"
4 : #include "../utilities/FangLogging.h"
5 :
6 0 : AsyncOperation::AsyncOperation(Priority priority, OperationManager* parent) :
7 : FangObject((QObject*)parent),
8 0 : operationManager(parent),
9 0 : priority(priority),
10 0 : error(false),
11 0 : terminate(false)
12 : {
13 :
14 0 : }
15 :
16 0 : void AsyncOperation::reportError(const QString& errorString)
17 : {
18 0 : qCDebug(logOperation) << "Error: [ " << metaObject()->className() << " ] " << errorString;
19 0 : error = true;
20 0 : emit finished(this);
21 0 : }
22 :
23 0 : void AsyncOperation::requireObject(QObject *object)
24 : {
25 0 : FANG_REQUIRE_VOID(object != nullptr);
26 0 : connect(object, &QObject::destroyed, this, &AsyncOperation::onRequiredQObjectDestroyed);
27 : }
28 :
29 0 : void AsyncOperation::onRequiredQObjectDestroyed(QObject *object)
30 : {
31 0 : reportError("Required object destroyed: " + object->objectName());
32 0 : terminate = true;
33 0 : }
34 :
35 0 : QSqlDatabase AsyncOperation::db()
36 : {
37 0 : return DB::instance()->db();
38 : }
39 :
40 0 : void AsyncOperation::reportSQLError(const QSqlQuery &query, const QString &errorString)
41 : {
42 0 : reportError(errorString + " SQLite says: " + query.lastError().text());
43 0 : }
|