From 8244e342044af86f045ab64566cf6e5b7a168d55 Mon Sep 17 00:00:00 2001 From: Luciano Montanaro Date: Sun, 20 Nov 2011 16:33:47 +0100 Subject: [PATCH] Update to new ScheduleItem class --- application/application.pro | 8 ++++++-- application/resources/stations/downloaddata.sh | 8 +++++--- application/stationschedulemodel.cpp | 24 +++++++++++++++++++----- application/stationschedulemodel.h | 23 +++++++++++++++++++---- 4 files changed, 49 insertions(+), 14 deletions(-) diff --git a/application/application.pro b/application/application.pro index 56c8400..e05d2b9 100644 --- a/application/application.pro +++ b/application/application.pro @@ -75,7 +75,8 @@ SOURCES += \ stationlistproxymodel.cpp \ settings.cpp \ dataprovider.cpp \ - stationschedulemodel.cpp + stationschedulemodel.cpp \ + stationscheduleitem.cpp HEADERS += \ $$PLATFORM_HEADERS \ @@ -83,7 +84,8 @@ HEADERS += \ stationlistproxymodel.h \ settings.h \ dataprovider.h \ - stationschedulemodel.h + stationschedulemodel.h \ + stationscheduleitem.h FORMS += \ settingsdialog.ui \ @@ -182,3 +184,5 @@ harmattan { qml.path = $$DATADIR/qml INSTALLS += qml } + + diff --git a/application/resources/stations/downloaddata.sh b/application/resources/stations/downloaddata.sh index 8a7e356..d3ebc7c 100755 --- a/application/resources/stations/downloaddata.sh +++ b/application/resources/stations/downloaddata.sh @@ -1,10 +1,11 @@ #! /bin/sh -BASEURL=http://jxapi.openstreetmap.org/xapi/api/0.6 -#BASEURL=http://open.mapquestapi.com/xapi/api/0.6 +#BASEURL=http://jxapi.openstreetmap.org/xapi/api/0.6 +BASEURL=http://open.mapquestapi.com/xapi/api/0.6 -curl --location --globoff "$BASEURL/node[railway=station][bbox=8,46,14,47]" -o nord.osm +#curl --location --globoff "$BASEURL/node[railway=station][bbox=8,46,14,47]" -o nord.osm curl --location --globoff "$BASEURL/node[railway=station][bbox=6.7,44,10,46]" -o nordovest.osm curl --location --globoff "$BASEURL/node[railway=station][bbox=10,44,14,46]" -o nordest.osm +exit 0 curl --location --globoff "$BASEURL/node[railway=station][bbox=7.5,43.5,8.5,44]" -o liguria.osm curl --location --globoff "$BASEURL/node[railway=station][bbox=10,42,15,44]" -o centronord.osm curl --location --globoff "$BASEURL/node[railway=station][bbox=12,40,17,42]" -o centrosud.osm @@ -23,6 +24,7 @@ curl --location --globoff "$BASEURL/node[railway=halt][bbox=12.3,38,17.3,40]" -o curl --location --globoff "$BASEURL/node[railway=halt][bbox=12,36.5,16.5,38]" -o h-sicilia.osm curl --location --globoff "$BASEURL/node[railway=halt][bbox=17.3,39.5,19,41]" -o h-puglia.osm curl --location --globoff "$BASEURL/node[railway=halt][bbox=8,38.7,10,41.3]" -o h-sardegna.osm +exit 0 curl --location --globoff "$BASEURL/way[railway=station][bbox=8,46,14,47]" -o w-nord.osm curl --location --globoff "$BASEURL/way[railway=station][bbox=6.7,44,10,46]" -o w-nordovest.osm diff --git a/application/stationschedulemodel.cpp b/application/stationschedulemodel.cpp index 34021be..483d9ff 100644 --- a/application/stationschedulemodel.cpp +++ b/application/stationschedulemodel.cpp @@ -27,13 +27,21 @@ Boston, MA 02110-1301, USA. #include #include #include - StationScheduleModel::StationScheduleModel(const QString &name, QObject *parent) : - QStringListModel(parent), + QAbstractListModel(parent), m_name(name) { DataProvider *provider = DataProvider::instance(); + QHash roles; + roles[DepartureStationRole] = "departureStation"; + roles[DepartureTimeRole] = "departureTime"; + roles[ArrivalStationRole] = "arrivalStation"; + roles[ArrivalTimeRole] = "ArrivalTime"; + roles[DetailsUrlRole] = "DetailsUrl"; + roles[DelayRole] = "delay"; + roles[DelayClassRole] = "delayClassRole"; + setRoleNames(roles); connect(provider, SIGNAL(stationScheduleReady(QByteArray,QUrl)), this, SLOT(parse(QByteArray,QUrl))); @@ -52,6 +60,11 @@ void StationScheduleModel::setName(const QString &name) } } +StationScheduleItem &parseResult(QWebElement &result) +{ + +} + void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUrl) { Q_UNUSED(baseUrl); @@ -84,7 +97,10 @@ void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUr if (current.classes().contains("bloccorisultato")) { departures << current.toPlainText(); } - current.addClass("departures"); + StationScheduleItem schedule = parseResult(current); + if (schedule.isValid()) { + m_schedules << schedule; + } current = current.nextSibling(); qDebug() << "marking as departures"; if (current.isNull()) @@ -96,14 +112,12 @@ void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUr if (current.classes().contains("bloccorisultato")) { arrivals << current.toPlainText(); } - current.addClass("arrivals"); current = current.nextSibling(); qDebug() << "marking as arrival"; if (current.isNull()) break; } - setStringList(departures); qDebug() << "departures list contain:"; qDebug() << departures; qDebug() << "arrivals list contain:"; diff --git a/application/stationschedulemodel.h b/application/stationschedulemodel.h index 957364c..31f39f8 100644 --- a/application/stationschedulemodel.h +++ b/application/stationschedulemodel.h @@ -22,21 +22,37 @@ Boston, MA 02110-1301, USA. #ifndef STATIONSCHEDULEMODEL_H #define STATIONSCHEDULEMODEL_H +#include "stationscheduleitem.h" + #include -#include +#include #include -class StationScheduleModel : public QStringListModel +class StationScheduleModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + enum StationRoles { + RefRole = Qt::UserRole +1, + DepartureStationRole, + DepartureTimeRole, + ArrivalStationRole, + ArrivalTimeRole, + DetailsUrlRole, + DelayRole, + DelayClassRole + }; + public: explicit StationScheduleModel(const QString &name = "", QObject *parent = 0); QString &name(); void setName(const QString &name); + int rowCount(const QModelIndex &parent) const; + QVariant data(const QModelIndex &index, int role) const; + signals: void nameChanged(); @@ -48,8 +64,7 @@ private slots: private: QString m_name; - QStringList departures; - QStringList arrivals; + QList m_schedules; }; #endif // STATIONSCHEDULEMODEL_H -- 1.7.9.5