More porting to Qt5
authorLuciano Montanaro <mikelima@cirulla.net>
Sat, 26 Oct 2013 15:34:06 +0000 (17:34 +0200)
committerLuciano Montanaro <mikelima@cirulla.net>
Sat, 26 Oct 2013 15:34:06 +0000 (17:34 +0200)
application/stationlistmodel.cpp
application/stationlistproxymodel.cpp
application/stationlistproxymodel.h
application/stationschedulemodel.cpp

index a86e090..5770141 100644 (file)
@@ -25,27 +25,19 @@ Boston, MA 02110-1301, USA.
 #include <QFileInfo>
 #include <QDebug>
 #include <QStandardItem>
-#include <QtLocation/QGeoCoordinate>
+#include <QGeoCoordinate>
 
 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
 QTM_USE_NAMESPACE
 Q_DECLARE_METATYPE(QGeoCoordinate)
 #endif
 
-static QHash<int, QByteArray> roles;
-
 StationListModel::StationListModel(QObject *parent) :
     QStandardItemModel(parent)
 {
     setRowCount(0);
 #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";
-#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
-    setRoleNames(roles);
+    setRoleNames(roleNames());
 #endif
 }
 
@@ -91,6 +83,10 @@ bool StationListModel::load(const QString &filename)
 
 QHash<int, QByteArray> StationListModel::roleNames() const
 {
+    QHash<int, QByteArray> roles;
+    roles[Qt::DisplayRole] = "name";
+    roles[StationListModel::PositionRole] = "position";
+    roles[StationListModel::StationCodeRole] = "code";
     return roles;
 }
 
index 3ae09a5..44ad3b5 100644 (file)
@@ -26,7 +26,7 @@ Boston, MA 02110-1301, USA.
 
 #include <QtGlobal>
 #include <QDebug>
-#include <QtLocation/QGeoCoordinate>
+#include <QGeoCoordinate>
 
 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
 QTM_USE_NAMESPACE
@@ -169,7 +169,9 @@ void StationListProxyModel::forceSortingMode(SortingMode mode)
     if (mode == StationListProxyModel::DistanceSorting) {
         positionInfoSource->startUpdates();
     } else {
+#if 0
         positionInfoSource->stopUpdates();
+#endif
     }
     invalidate();
     sort(0);
index dfb9d14..5ab5260 100644 (file)
@@ -24,8 +24,8 @@ Boston, MA 02110-1301, USA.
 
 #include <QtGlobal>
 #include <QSortFilterProxyModel>
-#include <QtLocation/QGeoCoordinate>
-#include <QtLocation/QGeoPositionInfoSource>
+#include <QGeoCoordinate>
+#include <QGeoPositionInfoSource>
 #include <QMetaType>
 #include <QStringList>
 
index 3f9fa70..96b1f4c 100644 (file)
@@ -27,15 +27,13 @@ Boston, MA 02110-1301, USA.
 #include <QtGlobal>
 #include <QDebug>
 #if (QT_VERSION >= QT_VERSION_CHECK(5, 1, 0))
-#include <QtWebKitWidgets/QtWebKitWidgets>
+#include <QtWebKitWidgets>
 #else
 #include <QWebElement>
 #include <QWebFrame>
 #include <QWebPage>
 #endif
 
-static QHash<int, QByteArray> roles;
-
 StationScheduleModel::StationScheduleModel(const QString &name, QObject *parent) :
     QAbstractListModel(parent),
     m_name(name),
@@ -43,27 +41,15 @@ StationScheduleModel::StationScheduleModel(const QString &name, QObject *parent)
 
 {
     DataProvider *provider = DataProvider::instance();
-    QHash<int, QByteArray> roles;
-    roles[TrainRole] = "train";
-    roles[DepartureStationRole] = "departureStation";
-    roles[DepartureTimeRole] = "departureTime";
-    roles[ArrivalStationRole] = "arrivalStation";
-    roles[ArrivalTimeRole] = "arrivalTime";
-    roles[DetailsUrlRole] = "detailsUrl";
-    roles[DelayRole] = "delay";
-    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)));
     connect(provider, SIGNAL(error()),
             this, SLOT(onNetworkError()));
     Settings *settings = Settings::instance();
     m_scheduleType = settings->showArrivalsPreferred() ? ArrivalSchedule : DepartureSchedule;
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
+    setRoleNames(roleNames());
+#endif
 }
 
 const QString &StationScheduleModel::name()
@@ -107,6 +93,18 @@ void StationScheduleModel::setError(const QString &error)
 
 QHash<int, QByteArray> StationScheduleModel::roleNames() const
 {
+    QHash<int, QByteArray> roles;
+    roles[TrainRole] = "train";
+    roles[DepartureStationRole] = "departureStation";
+    roles[DepartureTimeRole] = "departureTime";
+    roles[ArrivalStationRole] = "arrivalStation";
+    roles[ArrivalTimeRole] = "arrivalTime";
+    roles[DetailsUrlRole] = "detailsUrl";
+    roles[DelayRole] = "delay";
+    roles[DelayClassRole] = "delayClass";
+    roles[ExpectedPlatformRole] = "expectedPlatform";
+    roles[ActualPlatformRole] = "actualPlatform";
+
     return roles;
 }