Fix spectacle file
[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     };
43
44     explicit StationListModel(QObject *parent = 0);
45
46     bool load(const QString &filename);
47
48     QHash<int, QByteArray> roleNames() const;
49
50     // Needed to make SectionScroller happy.
51     Q_INVOKABLE int rowCount(const QModelIndex &parent = QModelIndex()) const;
52
53
54 signals:
55
56 public slots:
57
58 private:
59     void readStationsElement();
60     void readStationElement();
61     void readPosElement(QStandardItem *item);
62     void readNameElement(QStandardItem *item);
63     void readCodeElement(QStandardItem *item);
64     void skipUnknownElement(const QString &name = QString());
65
66     QXmlStreamReader m_reader;
67 };
68
69 #endif // STATIONLISTMODEL_H