1 #ifndef STATIONLISTPROXYMODEL_H
2 #define STATIONLISTPROXYMODEL_H
6 Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
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.
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.
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.
26 #include <QSortFilterProxyModel>
27 #include <QGeoCoordinate>
28 #include <QGeoPositionInfoSource>
30 #include <QStringList>
32 #if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
36 class StationListProxyModel : public QSortFilterProxyModel
39 Q_PROPERTY(QString searchPattern READ searchPattern WRITE setSearchPattern)
40 Q_PROPERTY(SortingMode sortingMode READ sortingMode WRITE setSortingMode NOTIFY sortingModeChanged)
50 explicit StationListProxyModel(QObject *parent = 0);
52 Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const;
53 Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
55 QString searchPattern() const;
56 void setSearchPattern(const QString &pattern);
58 SortingMode sortingMode();
59 void setSortingMode(SortingMode mode);
61 Q_INVOKABLE void setUserPosition(const QGeoCoordinate &pos);
62 Q_INVOKABLE void setRecentStations(const QStringList &stations);
63 Q_INVOKABLE void setRecentOnlyFilter(bool);
64 Q_INVOKABLE void setFavoriteStations(const QStringList &stations);
67 void sortingModeChanged(SortingMode mode);
70 virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
71 virtual bool filterAcceptsRow(int sourceRow,
72 const QModelIndex &sourceParent) const;
75 void forceSortingMode(SortingMode mode);
78 void updatePosition(const QGeoPositionInfo &update);
79 void updateRecentStations(void);
80 void updateFavoriteStations(void);
82 QString m_searchPattern;
83 QGeoPositionInfoSource *positionInfoSource;
84 QGeoCoordinate m_here;
85 QStringList m_stations;
86 SortingMode m_sortingMode;
87 bool m_filterRecentOnly;
90 Q_DECLARE_METATYPE(StationListProxyModel::SortingMode)
92 #endif // STATIONLISTPROXYMODEL_H