Bump version to 0.9.0
[quandoparte] / application / stationlistproxymodel.h
index 3ebf861..f07bf13 100644 (file)
@@ -1,22 +1,47 @@
 #ifndef STATIONLISTPROXYMODEL_H
 #define STATIONLISTPROXYMODEL_H
 
+/*
+
+Copyright (C) 2011 Luciano Montanaro <mikelima@cirulla.net>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; see the file COPYING.  If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.
+
+*/
+
+#include <QtGlobal>
 #include <QSortFilterProxyModel>
 #include <QGeoCoordinate>
+#include <QGeoPositionInfoSource>
+#include <QMetaType>
 #include <QStringList>
 
+#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
 QTM_USE_NAMESPACE
+#endif
 
 class StationListProxyModel : public QSortFilterProxyModel
 {
     Q_OBJECT
     Q_PROPERTY(QString searchPattern READ searchPattern WRITE setSearchPattern)
-    Q_PROPERTY(SortingMode sortingMode READ sortingMode WRITE setSortingMode)
+    Q_PROPERTY(SortingMode sortingMode READ sortingMode WRITE setSortingMode NOTIFY sortingModeChanged)
     Q_ENUMS(SortingMode)
 public:
 
     enum SortingMode {
-        NoSorting,
         AlphaSorting,
         DistanceSorting,
         RecentUsageSorting
@@ -24,6 +49,9 @@ public:
 
     explicit StationListProxyModel(QObject *parent = 0);
 
+    Q_INVOKABLE Qt::ItemFlags flags(const QModelIndex &index) const;
+    Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
+
     QString searchPattern() const;
     void setSearchPattern(const QString &pattern);
 
@@ -33,6 +61,10 @@ public:
     Q_INVOKABLE void setUserPosition(const QGeoCoordinate &pos);
     Q_INVOKABLE void setRecentStations(const QStringList &stations);
     Q_INVOKABLE void setRecentOnlyFilter(bool);
+    Q_INVOKABLE void setFavoriteStations(const QStringList &stations);
+
+signals:
+    void sortingModeChanged(SortingMode mode);
 
 protected:
     virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const;
@@ -40,11 +72,21 @@ protected:
             const QModelIndex &sourceParent) const;
 
 private:
+    void forceSortingMode(SortingMode mode);
+
+private slots:
+    void updatePosition(const QGeoPositionInfo &update);
+    void updateRecentStations(void);
+    void updateFavoriteStations(void);
+private:
     QString m_searchPattern;
+    QGeoPositionInfoSource *positionInfoSource;
     QGeoCoordinate m_here;
     QStringList m_stations;
     SortingMode m_sortingMode;
     bool m_filterRecentOnly;
 };
 
+Q_DECLARE_METATYPE(StationListProxyModel::SortingMode)
+
 #endif // STATIONLISTPROXYMODEL_H