Updated qmake file, bumped version
[quandoparte] / application / stationlistmodel.h
1 #ifndef STATIONLISTMODEL_H
2 #define STATIONLISTMODEL_H
3
4 /*
5
6 Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
7
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.
12
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.
17
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.
22
23 */
24
25 #include <QAbstractItemModel>
26 #include <QSet>
27 #include <QXmlStreamReader>
28
29 #include "stationitem.h"
30
31 class StationItem;
32 class StationListModel;
33
34 class StationListModel : public QAbstractListModel
35 {
36     Q_OBJECT
37     Q_ENUMS(StationListRole)
38     Q_PROPERTY(int count READ rowCount)
39
40 public:
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)
49     };
50
51     explicit StationListModel(QObject *parent = 0);
52
53     bool load(const QString &filename);
54
55     QHash<int, QByteArray> roleNames() const;
56
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, const QVariant &value, int role = Qt::EditRole);
61
62 signals:
63
64 public slots:
65
66 private:
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());
73
74     QXmlStreamReader m_reader;
75     QList<StationItem> m_stations;
76     QSet<QString> m_favorites;
77 };
78
79 #endif // STATIONLISTMODEL_H