1 #ifndef STATIONLISTMODEL_H
2 #define STATIONLISTMODEL_H
6 Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
25 #include <QAbstractItemModel>
27 #include <QXmlStreamReader>
29 #include "stationitem.h"
32 class StationListModel;
34 class StationListModel : public QAbstractListModel
37 Q_ENUMS(StationListRole)
38 Q_PROPERTY(int count READ rowCount)
41 enum StationListRole {
42 PositionRole = Qt::UserRole + 1, //< QGeoCoordinate - Station coordinate
43 StationCodeRole, //< QString - Station Code (Precise name if the Display name is known to fail)
44 RecentIndicatorRole, //<bool - If the station has been recently looked up
45 FavoriteIndicatorRole, //<bool - If the station has been marked as favorite
46 LongitudeRole, //< double - Longitude of the station
47 LatitudeRole, //< double - Latitude of the station
48 SectionRole //< Qstring - The section the station belongs to (depends on the sorting mode)
51 explicit StationListModel(QObject *parent = 0);
53 bool load(const QString &filename);
55 QHash<int, QByteArray> roleNames() const;
57 Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const;
58 Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const;
59 Q_INVOKABLE QVariant data(const QModelIndex &index, int role) const;
60 Q_INVOKABLE bool setData(const QModelIndex &index, QVariant &value, int role = Qt::EditRole);
67 void readStationsElement();
68 void readStationElement();
69 void readPosElement(StationItem &item);
70 void readNameElement(StationItem &item);
71 void readCodeElement(StationItem &item);
72 void skipUnknownElement(const QString &name = QString());
74 QXmlStreamReader m_reader;
75 QList<StationItem> m_stations;
76 QSet<QString> m_favorites;
79 #endif // STATIONLISTMODEL_H