785122bab307798c5272e2037dfd455d7fa3ccbd
[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 <QStandardItemModel>
26 #include <QXmlStreamReader>
27
28 class QStandardItem;
29 class StationListModel;
30
31 class StationListModel : public QStandardItemModel
32 {
33     Q_OBJECT
34     Q_ENUMS(StationListRole)
35     Q_PROPERTY(int count READ rowCount)
36
37 public:
38     enum StationListRole {
39         PositionRole = Qt::UserRole + 1, //< QGeoCoordinate - Station coordinate
40         StationCodeRole, //< QString - Station Code (Precise name if the Display name is known to fail)
41         RecentIndicatorRole, //<bool - If the station has been recently looked up
42         FavoriteIndicatorRole, //<bool - If the station has been marked as favorite
43         LongitudeRole, //< double - Longitude of the station
44         LatitudeRole, //< double - Latitude of the station
45         SectionRole //< Qstring - The section the station belongs to (depends on the sorting mode)
46     };
47
48     explicit StationListModel(QObject *parent = 0);
49
50     bool load(const QString &filename);
51
52     QHash<int, QByteArray> roleNames() const;
53
54     // Needed to make SectionScroller happy.
55     Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const;
56
57
58 signals:
59
60 public slots:
61
62 private:
63     void readStationsElement();
64     void readStationElement();
65     void readPosElement(QStandardItem *item);
66     void readNameElement(QStandardItem *item);
67     void readCodeElement(QStandardItem *item);
68     void skipUnknownElement(const QString &name = QString());
69
70     QXmlStreamReader m_reader;
71 };
72
73 #endif // STATIONLISTMODEL_H