Register needed metatypes
[quandoparte] / application / stationlistproxymodel.h
1 #ifndef STATIONLISTPROXYMODEL_H
2 #define STATIONLISTPROXYMODEL_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 <QSortFilterProxyModel>
26 #include <QGeoCoordinate>
27 #include <QGeoPositionInfoSource>
28 #include <QMetaType>
29 #include <QStringList>
30
31 QTM_USE_NAMESPACE
32
33 class StationListProxyModel : public QSortFilterProxyModel
34 {
35     Q_OBJECT
36     Q_PROPERTY(QString searchPattern READ searchPattern WRITE setSearchPattern)
37     Q_PROPERTY(SortingMode sortingMode READ sortingMode WRITE setSortingMode NOTIFY sortingModeChanged)
38     Q_ENUMS(SortingMode)
39 public:
40
41     enum SortingMode {
42         AlphaSorting,
43         DistanceSorting,
44         RecentUsageSorting
45     };
46
47     explicit StationListProxyModel(QObject *parent = 0);
48
49     QString searchPattern() const;
50     void setSearchPattern(const QString &pattern);
51
52     SortingMode sortingMode();
53     void setSortingMode(SortingMode mode);
54
55     Q_INVOKABLE void setUserPosition(const QGeoCoordinate &pos);
56     Q_INVOKABLE void setRecentStations(const QStringList &stations);
57     Q_INVOKABLE void setRecentOnlyFilter(bool);
58
59 signals:
60     void sortingModeChanged(SortingMode mode);
61
62 protected:
63     virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
64     virtual bool filterAcceptsRow(int sourceRow,
65             const QModelIndex &sourceParent) const;
66
67 private slots:
68     void updatePosition(const QGeoPositionInfo &update);
69
70 private:
71     QString m_searchPattern;
72     QGeoPositionInfoSource *positionInfoSource;
73     QGeoCoordinate m_here;
74     QStringList m_stations;
75     SortingMode m_sortingMode;
76     bool m_filterRecentOnly;
77 };
78
79 Q_DECLARE_METATYPE(StationListProxyModel::SortingMode)
80
81 #endif // STATIONLISTPROXYMODEL_H