X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=application%2Fstationlistproxymodel.cpp;h=295942e37a7e8d65a2c84341eb9eadb2d63ba12e;hb=ecf45a96ded5b8f4cbd6af4cd14e23767ac11bc6;hp=9b38b16d0689da97a9c81bb51a72d1547ef2f554;hpb=61d204d6b9510ee35840f7bd638ebd2a1c00d42d;p=quandoparte diff --git a/application/stationlistproxymodel.cpp b/application/stationlistproxymodel.cpp index 9b38b16..295942e 100644 --- a/application/stationlistproxymodel.cpp +++ b/application/stationlistproxymodel.cpp @@ -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 second = right.data(role).value(); - //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; +}