Check Qt version for Qt5 related features
authorLuciano Montanaro <mikelima@cirulla.net>
Mon, 7 Oct 2013 14:07:18 +0000 (16:07 +0200)
committerLuciano Montanaro <mikelima@cirulla.net>
Mon, 7 Oct 2013 14:07:18 +0000 (16:07 +0200)
application/main.cpp
application/stationlistmodel.cpp
application/stationlistproxymodel.cpp
application/stationlistproxymodel.h
application/stationschedulemodel.cpp
application/stationschedulemodel.h
application/view.cpp
application/view.h

index d26db6f..16eb301 100644 (file)
@@ -25,7 +25,8 @@ Boston, MA 02110-1301, USA.
 #include "view.h"
 #endif
 
-#ifdef TARGET_PLATFORM_SAILFISH
+#include <QtGlobal>
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
 #include <QtGui/QGuiApplication>
 #else
 #include <QtGui/QApplication>
@@ -45,7 +46,7 @@ Boston, MA 02110-1301, USA.
 
 Q_DECL_EXPORT int main(int argc, char *argv[])
 {
-#ifdef TARGET_PLATFORM_SAILFISH
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
     QScopedPointer< QGuiApplication > a(new QGuiApplication(argc, argv));
 #elif TARGET_PLATFORM_HARMATTAN
     QScopedPointer< QApplication > a(MDeclarativeCache::qApplication(argc, argv));
index 335e004..a86e090 100644 (file)
@@ -25,11 +25,9 @@ Boston, MA 02110-1301, USA.
 #include <QFileInfo>
 #include <QDebug>
 #include <QStandardItem>
-#ifndef TARGET_PLATFORM_SAILFISH
-#include <QGeoCoordinate>
-#endif
+#include <QtLocation/QGeoCoordinate>
 
-#ifndef TARGET_PLATFORM_SAILFISH
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
 QTM_USE_NAMESPACE
 Q_DECLARE_METATYPE(QGeoCoordinate)
 #endif
@@ -40,13 +38,13 @@ StationListModel::StationListModel(QObject *parent) :
     QStandardItemModel(parent)
 {
     setRowCount(0);
-#ifndef TARGET_PLATFORM_SAILFISH
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
     QHash<int, QByteArray> roles;
 #endif
     roles[Qt::DisplayRole] = "name";
     roles[StationListModel::PositionRole] = "position";
     roles[StationListModel::StationCodeRole] = "code";
-#ifndef TARGET_PLATFORM_SAILFISH
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
     setRoleNames(roles);
 #endif
 }
@@ -143,10 +141,8 @@ void StationListModel::readStationElement()
 void StationListModel::readPosElement(QStandardItem *item)
 {
     QStringList coordinates = m_reader.readElementText().split(",");
-#ifndef TARGET_PLATFORM_SAILFISH
     QGeoCoordinate pos = QGeoCoordinate(coordinates[0].toDouble(), coordinates[1].toDouble());
     item->setData(QVariant::fromValue(pos), PositionRole);
-#endif
     m_reader.readElementText();
     if (m_reader.isEndElement()) {
         m_reader.readNext();
index fe613c2..3ae09a5 100644 (file)
@@ -24,10 +24,11 @@ Boston, MA 02110-1301, USA.
 #include "settings.h"
 #include "stationlistmodel.h"
 
+#include <QtGlobal>
 #include <QDebug>
-#ifndef TARGET_PLATFORM_SAILFISH
-#include <QGeoCoordinate>
+#include <QtLocation/QGeoCoordinate>
 
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
 QTM_USE_NAMESPACE
 
 Q_DECLARE_METATYPE(QGeoCoordinate)
@@ -35,10 +36,8 @@ Q_DECLARE_METATYPE(QGeoCoordinate)
 
 StationListProxyModel::StationListProxyModel(QObject *parent) :
     QSortFilterProxyModel(parent),
-#ifndef TARGET_PLATFORM_SAILFISH
     positionInfoSource(QGeoPositionInfoSource::createDefaultSource(this)),
     m_here(44.5, 9.0),
-#endif
     m_filterRecentOnly(false)
 {
     Settings *settings = Settings::instance();
@@ -46,7 +45,6 @@ StationListProxyModel::StationListProxyModel(QObject *parent) :
     setFilterCaseSensitivity(Qt::CaseInsensitive);
     setSortCaseSensitivity(Qt::CaseInsensitive);
     setDynamicSortFilter(true);
-#ifndef TARGET_PLATFORM_SAILFISH
     if (positionInfoSource) {
         qDebug() << "position info source available";
         connect(positionInfoSource, SIGNAL(positionUpdated(QGeoPositionInfo)),
@@ -55,7 +53,6 @@ StationListProxyModel::StationListProxyModel(QObject *parent) :
     } else {
         qDebug() << "No position info source available";
     }
-#endif
     connect(settings, SIGNAL(recentStationsChanged()),
             this, SLOT(updateRecentStations()));
     updateRecentStations();
@@ -67,13 +64,9 @@ bool StationListProxyModel::lessThan(const QModelIndex &left,
     int role = sortRole();
 
     if (role == StationListModel::PositionRole) {
-#ifdef TARGET_PLATFORM_SAILFISH
-        return 0;
-#else
         QGeoCoordinate first = left.data(role).value<QGeoCoordinate>();
         QGeoCoordinate second = right.data(role).value<QGeoCoordinate>();
        return first.distanceTo(m_here) < second.distanceTo(m_here);
-#endif
     } else {
         return QString::compare(left.data(role).toString(),
                                 right.data(role).toString(),
@@ -82,8 +75,7 @@ bool StationListProxyModel::lessThan(const QModelIndex &left,
 }
 
 
-#ifndef TARGET_PLATFORM_SAILFISH
-void StationListProxyModel::setUserPosition(const QtMobility::QGeoCoordinate &pos)
+void StationListProxyModel::setUserPosition(const QGeoCoordinate &pos)
 {
     qDebug() << "Position is now" << pos;
     m_here = pos;
@@ -91,7 +83,6 @@ void StationListProxyModel::setUserPosition(const QtMobility::QGeoCoordinate &po
         invalidate();
     }
 }
-#endif
 
 void StationListProxyModel::setRecentStations(const QStringList &stations)
 {
@@ -175,19 +166,16 @@ void StationListProxyModel::forceSortingMode(SortingMode mode)
     default:
         break;
     }
-#ifndef TARGET_PLATFORM_SAILFISH
     if (mode == StationListProxyModel::DistanceSorting) {
         positionInfoSource->startUpdates();
     } else {
         positionInfoSource->stopUpdates();
     }
-#endif
     invalidate();
     sort(0);
 }
 
-#ifndef TARGET_PLATFORM_SAILFISH
-void StationListProxyModel::updatePosition(const QtMobility::QGeoPositionInfo &update)
+void StationListProxyModel::updatePosition(const QGeoPositionInfo &update)
 {
     qDebug() << "Position update received" << update;
     if (update.isValid()) {
@@ -199,4 +187,3 @@ void StationListProxyModel::updatePosition(const QtMobility::QGeoPositionInfo &u
         }
     }
 }
-#endif
index cb818c8..dfb9d14 100644 (file)
@@ -22,15 +22,14 @@ Boston, MA 02110-1301, USA.
 
 */
 
+#include <QtGlobal>
 #include <QSortFilterProxyModel>
-#ifndef TARGET_PLATFORM_SAILFISH
-#include <QGeoCoordinate>
-#include <QGeoPositionInfoSource>
-#endif
+#include <QtLocation/QGeoCoordinate>
+#include <QtLocation/QGeoPositionInfoSource>
 #include <QMetaType>
 #include <QStringList>
 
-#ifndef TARGET_PLATFORM_SAILFISH
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
 QTM_USE_NAMESPACE
 #endif
 
@@ -56,9 +55,7 @@ public:
     SortingMode sortingMode();
     void setSortingMode(SortingMode mode);
 
-#ifndef TARGET_PLATFORM_SAILFISH
     Q_INVOKABLE void setUserPosition(const QGeoCoordinate &pos);
-#endif
     Q_INVOKABLE void setRecentStations(const QStringList &stations);
     Q_INVOKABLE void setRecentOnlyFilter(bool);
 
@@ -74,16 +71,12 @@ private:
     void forceSortingMode(SortingMode mode);
 
 private slots:
-#ifndef TARGET_PLATFORM_SAILFISH
     void updatePosition(const QGeoPositionInfo &update);
-#endif
     void updateRecentStations(void);
 private:
     QString m_searchPattern;
-#ifndef TARGET_PLATFORM_SAILFISH
     QGeoPositionInfoSource *positionInfoSource;
     QGeoCoordinate m_here;
-#endif
     QStringList m_stations;
     SortingMode m_sortingMode;
     bool m_filterRecentOnly;
index 0712b73..3f9fa70 100644 (file)
@@ -24,12 +24,17 @@ Boston, MA 02110-1301, USA.
 #include "dataprovider.h"
 #include "settings.h"
 
+#include <QtGlobal>
 #include <QDebug>
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
+#include <QtWebKitWidgets/QtWebKitWidgets>
+#else
 #include <QWebElement>
-#ifndef TARGET_PLATFORM_SAILFISH
 #include <QWebFrame>
-#endif
 #include <QWebPage>
+#endif
+
+static QHash<int, QByteArray> roles;
 
 StationScheduleModel::StationScheduleModel(const QString &name, QObject *parent) :
     QAbstractListModel(parent),
@@ -49,7 +54,9 @@ StationScheduleModel::StationScheduleModel(const QString &name, QObject *parent)
     roles[DelayClassRole] = "delayClass";
     roles[ExpectedPlatformRole] = "expectedPlatform";
     roles[ActualPlatformRole] = "actualPlatform";
+#if (QT_VERSION <= QT_VERSION_CHECK(5, 0, 0))
     setRoleNames(roles);
+#endif
 
     connect(provider, SIGNAL(stationScheduleReady(QByteArray,QUrl)),
             this, SLOT(parse(QByteArray,QUrl)));
@@ -98,6 +105,11 @@ void StationScheduleModel::setError(const QString &error)
     }
 }
 
+QHash<int, QByteArray> StationScheduleModel::roleNames() const
+{
+    return roles;
+}
+
 StationScheduleModel::ScheduleType StationScheduleModel::type()
 {
     return m_scheduleType;
@@ -210,6 +222,7 @@ void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUr
 
     emit layoutAboutToBeChanged();
     beginResetModel();
+#if (QT_VERSION <= QT_VERSION_CHECK(5, 0, 0))
     QWebPage page;
     page.mainFrame()->setContent(htmlReply, "text/html", baseUrl);
     QWebElement doc = page.mainFrame()->documentElement();
@@ -269,6 +282,7 @@ void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUr
         if (current.isNull())
             break;
     }
+#endif
     endResetModel();
     emit layoutChanged();
 }
index ca668cd..1f97de7 100644 (file)
@@ -73,6 +73,8 @@ public:
     const QString &error();
     void setError(const QString &code);
 
+    QHash<int, QByteArray> roleNames() const;
+
 signals:
     void nameChanged();
     void codeChanged();
index d922d68..61c9171 100644 (file)
@@ -26,13 +26,14 @@ Boston, MA 02110-1301, USA.
 #include "stationlistproxymodel.h"
 #include "stationschedulemodel.h"
 
+#include <QtGlobal>
 #include <QDebug>
 #include <QDir>
 #include <QFile>
 #include <QModelIndex>
-#include <QtConcurrentRun>
-#ifdef TARGET_PLATFORM_SAILFISH
-#include <QtQuick>
+#include <QtConcurrent/QtConcurrentRun>
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
+#include <QtQuick/QtQuick>
 #else
 #include <QtDeclarative>
 #endif
@@ -64,7 +65,7 @@ static QString trueFilePath(const QString &path)
 #endif
 }
 
-#ifdef TARGET_PLATFORM_SAILFISH
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
 View::View(QWindow *parent) :
     QQuickView(parent),
 #else
@@ -88,7 +89,7 @@ View::View(QWidget *parent) :
     qmlRegisterType<StationScheduleModel>(
                 "net.cirulla.quandoparte", 1, 0, "StationScheduleModel");
 
-#ifdef TARGET_PLATFORM_SAILFISH
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
     QQmlContext *context = this->rootContext();
 #else
     QDeclarativeContext *context = this->rootContext();
index 8170f3e..0fff3aa 100644 (file)
@@ -22,9 +22,10 @@ Boston, MA 02110-1301, USA.
 
 */
 
+#include <QtGlobal>
 #include <QFuture>
-#ifdef TARGET_PLATFORM_SAILFISH
-#include <QQuickView>
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
+#include <QtQuick/QQuickView>
 #else
 #include <QDeclarativeView>
 #endif
@@ -33,7 +34,7 @@ class StationListModel;
 class StationListProxyModel;
 
 class View :
-#ifdef TARGET_PLATFORM_SAILFISH
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
         public QQuickView
 #else
         public QDeclarativeView
@@ -41,7 +42,7 @@ class View :
 {
     Q_OBJECT
 public:
-#ifdef TARGET_PLATFORM_SAILFISH
+#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
     explicit View(QWindow *parent = 0);
 #else
     explicit View(QWidget *parent = 0);