dd786bb508e0cc4670c8e67a739cfabdbb0d6625
[quandoparte] / application / stationlistproxymodel.cpp
1 #include "stationlistproxymodel.h"
2 #include "stationlistmodel.h"
3
4 #include <QDebug>
5 #include <QGeoCoordinate>
6
7 QTM_USE_NAMESPACE
8
9 Q_DECLARE_METATYPE(QGeoCoordinate)
10
11 StationListProxyModel::StationListProxyModel(QObject *parent) :
12     QSortFilterProxyModel(parent),
13     m_here(44.5, 9.0)
14 {
15 }
16
17 bool StationListProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
18 {
19     int role = sortRole();
20
21     qDebug() << "lessThan called";
22
23     if (role == StationListModel::PositionRole) {
24         QGeoCoordinate first = left.data(role).value<QGeoCoordinate>();
25         QGeoCoordinate second = right.data(role).value<QGeoCoordinate>();
26         qDebug() << "PositionRole" << left.data(Qt::DisplayRole) << first << right.data(Qt::DisplayRole) << second << "Here" << m_here;
27        return first.distanceTo(m_here) < second.distanceTo(m_here);
28     } else {
29         qDebug() << "OtherRole";
30         return QString::compare(left.data(role).toString(),
31                                 right.data(role).toString(),
32                                 sortCaseSensitivity()) < 0;
33     }
34 }
35
36 void StationListProxyModel::setUserPosition(const QtMobility::QGeoCoordinate &pos)
37 {
38     m_here = pos;
39 }