From b96e2811a7da18099c710dccc2aef5fed031e5a2 Mon Sep 17 00:00:00 2001 From: Luciano Montanaro Date: Sun, 15 Jan 2012 23:10:05 +0100 Subject: [PATCH] Make the station code visible to QML --- application/stationlistproxymodel.cpp | 4 ---- application/stationschedulemodel.cpp | 18 ++++++++++++++++-- application/stationschedulemodel.h | 8 +++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/application/stationlistproxymodel.cpp b/application/stationlistproxymodel.cpp index e7eccc4..da2152b 100644 --- a/application/stationlistproxymodel.cpp +++ b/application/stationlistproxymodel.cpp @@ -37,10 +37,6 @@ StationListProxyModel::StationListProxyModel(QObject *parent) : m_here(44.5, 9.0), m_filterRecentOnly(false) { - QHash roles; - roles[StationListModel::PositionRole] = "position"; - setRoleNames(roles); - Settings *settings = Settings::instance(); forceSortingMode(settings->stationListSortingMode()); setFilterCaseSensitivity(Qt::CaseInsensitive); diff --git a/application/stationschedulemodel.cpp b/application/stationschedulemodel.cpp index 2c60082..ade4a31 100644 --- a/application/stationschedulemodel.cpp +++ b/application/stationschedulemodel.cpp @@ -68,6 +68,19 @@ void StationScheduleModel::setName(const QString &name) } } +QString & StationScheduleModel::code() +{ + return m_code; +} + +void StationScheduleModel::setCode(const QString &code) +{ + if (code != m_code) { + m_code = code; + emit codeChanged(); + } +} + StationScheduleModel::ScheduleType StationScheduleModel::type() { return m_scheduleType; @@ -232,12 +245,13 @@ void StationScheduleModel::parse(const QByteArray &htmlReply, const QUrl &baseUr emit layoutChanged(); } -void StationScheduleModel::fetch(const QString &name) +void StationScheduleModel::fetch(const QString &name, const QString &code) { DataProvider *provider = DataProvider::instance(); - provider->fetchStationSchedule(name); + provider->fetchStationSchedule(name, code); setName(name); + setCode(code); } int StationScheduleModel::rowCount(const QModelIndex &parent) const diff --git a/application/stationschedulemodel.h b/application/stationschedulemodel.h index b2c2805..5b5a985 100644 --- a/application/stationschedulemodel.h +++ b/application/stationschedulemodel.h @@ -32,6 +32,7 @@ class StationScheduleModel : public QAbstractListModel { Q_OBJECT Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) + Q_PROPERTY(QString code READ code WRITE setCode NOTIFY codeChanged) Q_PROPERTY(ScheduleType type READ type WRITE setType NOTIFY typeChanged) Q_ENUMS(ScheduleType) @@ -59,6 +60,9 @@ public: QString &name(); void setName(const QString &name); + QString &code(); + void setCode(const QString &code); + ScheduleType type(); void setType(ScheduleType type); @@ -67,16 +71,18 @@ public: signals: void nameChanged(); + void codeChanged(); void typeChanged(); public slots: - void fetch(const QString &name); + void fetch(const QString &name, const QString &code = QString()); private slots: void parse(const QByteArray &htmlReply, const QUrl &baseUrl); private: QString m_name; + QString m_code; QList m_departureSchedules; QList m_arrivalSchedules; ScheduleType m_scheduleType; -- 1.7.9.5