From 1db1cfee9026112b11556f189bf7261e76e2c140 Mon Sep 17 00:00:00 2001 From: Luciano Montanaro Date: Mon, 7 Oct 2013 16:07:18 +0200 Subject: [PATCH] Check Qt version for Qt5 related features --- application/main.cpp | 5 +++-- application/stationlistmodel.cpp | 12 ++++-------- application/stationlistproxymodel.cpp | 23 +++++------------------ application/stationlistproxymodel.h | 15 ++++----------- application/stationschedulemodel.cpp | 18 ++++++++++++++++-- application/stationschedulemodel.h | 2 ++ application/view.cpp | 11 ++++++----- application/view.h | 9 +++++---- 8 files changed, 45 insertions(+), 50 deletions(-) diff --git a/application/main.cpp b/application/main.cpp index d26db6f..16eb301 100644 --- a/application/main.cpp +++ b/application/main.cpp @@ -25,7 +25,8 @@ Boston, MA 02110-1301, USA. #include "view.h" #endif -#ifdef TARGET_PLATFORM_SAILFISH +#include +#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)) #include #else #include @@ -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)); diff --git a/application/stationlistmodel.cpp b/application/stationlistmodel.cpp index 335e004..a86e090 100644 --- a/application/stationlistmodel.cpp +++ b/application/stationlistmodel.cpp @@ -25,11 +25,9 @@ Boston, MA 02110-1301, USA. #include #include #include -#ifndef TARGET_PLATFORM_SAILFISH -#include -#endif +#include -#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 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(); diff --git a/application/stationlistproxymodel.cpp b/application/stationlistproxymodel.cpp index fe613c2..3ae09a5 100644 --- a/application/stationlistproxymodel.cpp +++ b/application/stationlistproxymodel.cpp @@ -24,10 +24,11 @@ Boston, MA 02110-1301, USA. #include "settings.h" #include "stationlistmodel.h" +#include #include -#ifndef TARGET_PLATFORM_SAILFISH -#include +#include +#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 second = right.data(role).value(); 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 diff --git a/application/stationlistproxymodel.h b/application/stationlistproxymodel.h index cb818c8..dfb9d14 100644 --- a/application/stationlistproxymodel.h +++ b/application/stationlistproxymodel.h @@ -22,15 +22,14 @@ Boston, MA 02110-1301, USA. */ +#include #include -#ifndef TARGET_PLATFORM_SAILFISH -#include -#include -#endif +#include +#include #include #include -#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; diff --git a/application/stationschedulemodel.cpp b/application/stationschedulemodel.cpp index 0712b73..3f9fa70 100644 --- a/application/stationschedulemodel.cpp +++ b/application/stationschedulemodel.cpp @@ -24,12 +24,17 @@ Boston, MA 02110-1301, USA. #include "dataprovider.h" #include "settings.h" +#include #include +#if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0)) +#include +#else #include -#ifndef TARGET_PLATFORM_SAILFISH #include -#endif #include +#endif + +static QHash 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 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(); } diff --git a/application/stationschedulemodel.h b/application/stationschedulemodel.h index ca668cd..1f97de7 100644 --- a/application/stationschedulemodel.h +++ b/application/stationschedulemodel.h @@ -73,6 +73,8 @@ public: const QString &error(); void setError(const QString &code); + QHash roleNames() const; + signals: void nameChanged(); void codeChanged(); diff --git a/application/view.cpp b/application/view.cpp index d922d68..61c9171 100644 --- a/application/view.cpp +++ b/application/view.cpp @@ -26,13 +26,14 @@ Boston, MA 02110-1301, USA. #include "stationlistproxymodel.h" #include "stationschedulemodel.h" +#include #include #include #include #include -#include -#ifdef TARGET_PLATFORM_SAILFISH -#include +#include +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) +#include #else #include #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( "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(); diff --git a/application/view.h b/application/view.h index 8170f3e..0fff3aa 100644 --- a/application/view.h +++ b/application/view.h @@ -22,9 +22,10 @@ Boston, MA 02110-1301, USA. */ +#include #include -#ifdef TARGET_PLATFORM_SAILFISH -#include +#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) +#include #else #include #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); -- 1.7.9.5