]> Some of my projects - localmylist.git/commitdiff
Make LocalMyList compile with Qt4 again.
authorAPTX <redacted>
Tue, 2 Apr 2013 18:00:48 +0000 (20:00 +0200)
committerAPTX <redacted>
Tue, 2 Apr 2013 18:00:48 +0000 (20:00 +0200)
localmylist/database.cpp
localmylist/database.h
localmylist/databaseclasses.h
localmylist/mylistnode.cpp
localmylist/sqlasyncquery.cpp
localmylist/sqlasyncquery.h
localmylist/sqlasyncqueryinternal.h

index 045f82d..ae3e707 100644 (file)
@@ -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
 }
 
 
index 6a879ef..f048141 100644 (file)
@@ -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();
index 1db2259..23f1f27 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <QString>
 #include <QDateTime>
+#include <QMetaType>
 
 namespace LocalMyList {
 
index 45f5ef9..50a39b1 100644 (file)
@@ -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;
index 55eec35..13450b6 100644 (file)
@@ -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<AsyncQueryTask *>(sender());
@@ -84,6 +94,9 @@ void SqlAsyncQuery::resultRecieved()
                return;
 
        d->resultReady(t->result());
+       if (d->m_callback)
+               d->m_callback();
+
        emit resultReady();
 }
 
index 0012089..83be9d7 100644 (file)
@@ -3,12 +3,19 @@
 
 #include "localmylist_global.h"
 #include <QObject>
-#include <QSql>
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#      include <QSql>
+#else
+#      include <QtSql>
+#endif
+#include <functional>
 
 #include "sqlresultiteratorinterface.h"
 
 namespace LocalMyList {
 
+typedef ::std::function<void()> 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();
 
index 57e969c..92b67e0 100644 (file)
@@ -1,14 +1,17 @@
 #ifndef SQLASYNCQUERYINTERNAL_H
 #define SQLASYNCQUERYINTERNAL_H
 
+#include "sqlasyncquery.h"
 #include <QStringList>
 #include <QVariant>
-#include <QSql>
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#      include <QSql>
+#else
+#      include <QtSql>
+#endif
 
 namespace LocalMyList {
 
-class SqlAsyncQuery;
-
 namespace Internal {
 
 struct BoundValue
@@ -67,6 +70,8 @@ public:
        bool working;
 
        QString m_lastError;
+
+       SqlAsyncCallback m_callback;
 };
 
 } // namespace Internal