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