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();
- qDebug() << "lessThan called";
-
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;
{
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;
+}