]> Some of my projects - localmylist.git/commitdiff
Make LocalMyList compile with Qt4 again.
authorAPTX <marek321@gmail.com>
Tue, 2 Apr 2013 18:00:48 +0000 (20:00 +0200)
committerAPTX <marek321@gmail.com>
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 045f82d6def890bf5bd29162bf7707f3e8ff9e77..ae3e70702fdd7baa67d039f775f8be39713e934a 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 6a879efa1d02a208514e2602d9059886fae96cac..f048141513d325f2f2dd81480129422ed64a668c 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 1db2259d498d6ade030d35dca0a8cc9d813a9355..23f1f27e291f28b785f974ea7410294cd0c05665 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <QString>
 #include <QDateTime>
+#include <QMetaType>
 
 namespace LocalMyList {
 
index 45f5ef9fa1564cdcc50b9292a994c8c99caebacf..50a39b14ae1a997d429e064cfa02393532892679 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 55eec353c09dde141d54dbd259d1cdf05d1d2570..13450b6c90094a65af273a93a13b3d5e3289c2b2 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 0012089cbc37e9128f5219d86dcd9fce01e28adf..83be9d7578fa510e4b175c9df6c2716d58f42034 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 57e969ce1e4fa3990d2681d4687d61bda8b07f0f..92b67e0ef6cae3e9e741678b371c592cb2aa42a3 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