Update to new ScheduleItem class
authorLuciano Montanaro <mikelima@cirulla.net>
Sun, 20 Nov 2011 15:33:47 +0000 (16:33 +0100)
committerLuciano Montanaro <mikelima@cirulla.net>
Sun, 20 Nov 2011 15:33:47 +0000 (16:33 +0100)
application/application.pro
application/resources/stations/downloaddata.sh
application/stationschedulemodel.cpp
application/stationschedulemodel.h

index 56c8400..e05d2b9 100644 (file)
@@ -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
 }
+
+
index 8a7e356..d3ebc7c 100755 (executable)
@@ -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
index 34021be..483d9ff 100644 (file)
@@ -27,13 +27,21 @@ Boston, MA 02110-1301, USA.
 #include <QWebElement>
 #include <QWebFrame>
 #include <QWebPage>
-
 StationScheduleModel::StationScheduleModel(const QString &name, QObject *parent) :
-    QStringListModel(parent),
+    QAbstractListModel(parent),
     m_name(name)
 
 {
     DataProvider *provider = DataProvider::instance();
+    QHash<int, QByteArray> 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:";
index 957364c..31f39f8 100644 (file)
@@ -22,21 +22,37 @@ Boston, MA 02110-1301, USA.
 #ifndef STATIONSCHEDULEMODEL_H
 #define STATIONSCHEDULEMODEL_H
 
+#include "stationscheduleitem.h"
+
 #include <QObject>
-#include <QStringListModel>
+#include <QAbstractListModel>
 #include <QUrl>
 
-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<StationScheduleItem> m_schedules;
 };
 
 #endif // STATIONSCHEDULEMODEL_H