#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)));
}
}
+StationScheduleItem &parseResult(QWebElement &result)
+{
+
+}
+
void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUrl)
{
Q_UNUSED(baseUrl);
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())
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:";
#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();
private:
QString m_name;
- QStringList departures;
- QStringList arrivals;
+ QList<StationScheduleItem> m_schedules;
};
#endif // STATIONSCHEDULEMODEL_H