Fix recent list filtering
[quandoparte] / application / stationlistproxymodel.cpp
index 9b38b16..295942e 100644 (file)
@@ -10,21 +10,21 @@ Q_DECLARE_METATYPE(QGeoCoordinate)
 
 StationListProxyModel::StationListProxyModel(QObject *parent) :
     QSortFilterProxyModel(parent),
-    m_here(44.5, 9.0)
+    m_here(44.5, 9.0),
+    m_filterRecentOnly(false)
 {
 }
 
-bool StationListProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
+bool StationListProxyModel::lessThan(const QModelIndex &left,
+                                     const QModelIndex &right) const
 {
     int role = sortRole();
 
     if (role == StationListModel::PositionRole) {
         QGeoCoordinate first = left.data(role).value<QGeoCoordinate>();
         QGeoCoordinate second = right.data(role).value<QGeoCoordinate>();
-        //qDebug() << "PositionRole" << left.data(Qt::DisplayRole) << first << right.data(Qt::DisplayRole) << second << "Here" << m_here;
        return first.distanceTo(m_here) < second.distanceTo(m_here);
     } else {
-        //qDebug() << "OtherRole";
         return QString::compare(left.data(role).toString(),
                                 right.data(role).toString(),
                                 sortCaseSensitivity()) < 0;
@@ -35,3 +35,23 @@ void StationListProxyModel::setUserPosition(const QtMobility::QGeoCoordinate &po
 {
     m_here = pos;
 }
+
+void StationListProxyModel::setRecentStations(const QStringList &stations)
+{
+    m_stations = stations;
+}
+
+bool StationListProxyModel::filterAcceptsRow(int sourceRow,
+                                             const QModelIndex &sourceParent) const
+{
+    if (m_filterRecentOnly) {
+        QModelIndex i = sourceModel()->index(sourceRow, 0, sourceParent);
+        return m_stations.contains(sourceModel()->data(i).toString());
+    }
+    return true;
+}
+
+void StationListProxyModel::setRecentOnlyFilter(bool activation)
+{
+    m_filterRecentOnly = activation;
+}