From f38cd96f79abd92f9f5e8ba12b8d7fd75bb1482e Mon Sep 17 00:00:00 2001 From: APTX Date: Tue, 2 Apr 2013 20:00:48 +0200 Subject: [PATCH] Make LocalMyList compile with Qt4 again. --- localmylist/database.cpp | 16 +++++++++++++--- localmylist/database.h | 8 +++++++- localmylist/databaseclasses.h | 1 + localmylist/mylistnode.cpp | 2 +- localmylist/sqlasyncquery.cpp | 13 +++++++++++++ localmylist/sqlasyncquery.h | 12 +++++++++++- localmylist/sqlasyncqueryinternal.h | 11 ++++++++--- 7 files changed, 54 insertions(+), 9 deletions(-) diff --git a/localmylist/database.cpp b/localmylist/database.cpp index 045f82d..ae3e707 100644 --- a/localmylist/database.cpp +++ b/localmylist/database.cpp @@ -1305,9 +1305,13 @@ bool Database::connect() qWarning() << "Failed opening database connection." << d->db.lastError(); return success; } - +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) QObject::connect(d->db.driver(), SIGNAL(notification(QString,QSqlDriver::NotificationSource,QVariant)), this, SLOT(handleNotification(QString,QSqlDriver::NotificationSource,QVariant))); +#else + QObject::connect(d->db.driver(), SIGNAL(notification(QString)), + this, SLOT(handleNotification(QString))); +#endif subscribeToNotifications(); emit connected(); @@ -1746,11 +1750,15 @@ bool Database::notifyRenameDataChanged() return notify("rename_data_changed"); } +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) void Database::handleNotification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload) +#else +void Database::handleNotification(const QString &name) +#endif { +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) Q_UNUSED(source); - Q_UNUSED(payload); - +#endif qDebug() << "Recieved notification" << name; if (name == "new_pending_request") { @@ -1768,6 +1776,7 @@ void Database::handleNotification(const QString &name, QSqlDriver::NotificationS { emit configChanged(); } +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) else if (name == "anime_update") { int id = payload.toInt(); @@ -1852,6 +1861,7 @@ void Database::handleNotification(const QString &name, QSqlDriver::NotificationS if (id) emit fileLocationInsert(id); } +#endif } diff --git a/localmylist/database.h b/localmylist/database.h index 6a879ef..f048141 100644 --- a/localmylist/database.h +++ b/localmylist/database.h @@ -22,7 +22,7 @@ public: QSqlResultIterator(QSqlQuery &query) : q(query) {} bool next() { return q.next(); } QVariant value(int index) const { return q.value(index); } - QVariant value(const QString &name) const { return q.value(name); } + QVariant value(const QString &name) const { return q.record().value(name); } int indexOf(const QString &name ) const { return q.record().indexOf(name); } private: QSqlQuery &q; @@ -166,7 +166,13 @@ signals: void fileLocationInsert(int id); private slots: +// moc doesn't expand macros +// QT_VERSION_CHECK(5, 0, 0) == 0x050000 +#if QT_VERSION >= 0x050000 void handleNotification(const QString &name, QSqlDriver::NotificationSource source, const QVariant &payload); +#else + void handleNotification(const QString &name); +#endif private: void subscribeToNotifications(); diff --git a/localmylist/databaseclasses.h b/localmylist/databaseclasses.h index 1db2259..23f1f27 100644 --- a/localmylist/databaseclasses.h +++ b/localmylist/databaseclasses.h @@ -5,6 +5,7 @@ #include #include +#include namespace LocalMyList { diff --git a/localmylist/mylistnode.cpp b/localmylist/mylistnode.cpp index 45f5ef9..50a39b1 100644 --- a/localmylist/mylistnode.cpp +++ b/localmylist/mylistnode.cpp @@ -18,7 +18,7 @@ MyListNode::MyListNode(MyListModel *model_, NodeType type, MyListNode *parent) : model = model_; query = new SqlAsyncQuery; - QObject::connect(query, &SqlAsyncQuery::resultReady, [this](){ fetchComplete();}); + query->setCallback([this](){ fetchComplete();}); if (m_type != RootNode) return; diff --git a/localmylist/sqlasyncquery.cpp b/localmylist/sqlasyncquery.cpp index 55eec35..13450b6 100644 --- a/localmylist/sqlasyncquery.cpp +++ b/localmylist/sqlasyncquery.cpp @@ -77,6 +77,16 @@ QString SqlAsyncQuery::lastError() const return d->lastError(); } +SqlAsyncCallback SqlAsyncQuery::callback() const +{ + return d->m_callback; +} + +void SqlAsyncQuery::setCallback(SqlAsyncCallback callback) +{ + d->m_callback = callback; +} + void SqlAsyncQuery::resultRecieved() { AsyncQueryTask *t = qobject_cast(sender()); @@ -84,6 +94,9 @@ void SqlAsyncQuery::resultRecieved() return; d->resultReady(t->result()); + if (d->m_callback) + d->m_callback(); + emit resultReady(); } diff --git a/localmylist/sqlasyncquery.h b/localmylist/sqlasyncquery.h index 0012089..83be9d7 100644 --- a/localmylist/sqlasyncquery.h +++ b/localmylist/sqlasyncquery.h @@ -3,12 +3,19 @@ #include "localmylist_global.h" #include -#include +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +# include +#else +# include +#endif +#include #include "sqlresultiteratorinterface.h" namespace LocalMyList { +typedef ::std::function SqlAsyncCallback; + namespace Internal { class SqlAsyncQueryInternal; } @@ -36,6 +43,9 @@ public: QString executedQuery() const; QString lastError() const; + SqlAsyncCallback callback() const; + void setCallback(SqlAsyncCallback callback); + signals: void resultReady(); diff --git a/localmylist/sqlasyncqueryinternal.h b/localmylist/sqlasyncqueryinternal.h index 57e969c..92b67e0 100644 --- a/localmylist/sqlasyncqueryinternal.h +++ b/localmylist/sqlasyncqueryinternal.h @@ -1,14 +1,17 @@ #ifndef SQLASYNCQUERYINTERNAL_H #define SQLASYNCQUERYINTERNAL_H +#include "sqlasyncquery.h" #include #include -#include +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +# include +#else +# include +#endif namespace LocalMyList { -class SqlAsyncQuery; - namespace Internal { struct BoundValue @@ -67,6 +70,8 @@ public: bool working; QString m_lastError; + + SqlAsyncCallback m_callback; }; } // namespace Internal -- 2.52.0