Enroute Flight Navigation
A navigation app for VFR pilots
DistanceSortProxyModel.h
1/***************************************************************************
2 * Copyright (C) 2026 by Stefan Kebekus *
3 * stefan.kebekus@gmail.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21#pragma once
22
23#include <QGeoCoordinate>
24
25#include "ui/NameFilterProxyModel.h"
26
27namespace Ui {
28
41
43{
44 Q_OBJECT
45 QML_ELEMENT
46
47public:
52 explicit DistanceSortProxyModel(QObject* parent = nullptr);
53
54 // Default destructor
55 ~DistanceSortProxyModel() override = default;
56
57
58 //
59 // Properties
60 //
61
67
68
74
80
81
82 //
83 // Getter Methods
84 //
85
90 [[nodiscard]] QGeoCoordinate referenceCoordinate() const { return m_referenceCoordinate; }
91
96 [[nodiscard]] QString coordinateRoleName() const { return m_coordinateRoleName; }
97
102 [[nodiscard]] double resortDistance() const { return m_resortDistance; }
103
104
105 //
106 // Setter Methods
107 //
108
113 void setReferenceCoordinate(const QGeoCoordinate& newReferenceCoordinate);
114
119 void setCoordinateRoleName(const QString& newCoordinateRoleName);
120
125 void setResortDistance(double newResortDistance);
126
127
128 //
129 // Methods
130 //
131
138 void setSourceModel(QAbstractItemModel* newSourceModel) override;
139
140signals:
143
146
149
150protected:
160 [[nodiscard]] bool lessThan(const QModelIndex& sourceLeft, const QModelIndex& sourceRight) const override;
161
162private:
163 Q_DISABLE_COPY_MOVE(DistanceSortProxyModel)
164
165 // Distance from the reference coordinate to the coordinate of a source
166 // row. Infinite if the row has no valid coordinate.
167 [[nodiscard]] double distance(const QModelIndex& sourceIndex) const;
168
169 QGeoCoordinate m_referenceCoordinate;
170
171 // Reference coordinate that the current order is based on
172 QGeoCoordinate m_sortReference;
173
174 QString m_coordinateRoleName {QStringLiteral("center")};
175
176 // Role matching m_coordinateRoleName in the current source model, or -1
177 int m_coordinateRole {-1};
178
179 double m_resortDistance {1000.0};
180};
181
182} // namespace Ui
QString coordinateRoleName() const
Getter function for the property with the same name.
void referenceCoordinateChanged()
Notification signal for property with the same name.
void setReferenceCoordinate(const QGeoCoordinate &newReferenceCoordinate)
Setter function for the property with the same name.
bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override
Re-implemented from QSortFilterProxyModel.
QGeoCoordinate referenceCoordinate
Position that distances are measured from.
void resortDistanceChanged()
Notification signal for property with the same name.
void setSourceModel(QAbstractItemModel *newSourceModel) override
Re-implemented from QAbstractProxyModel.
void coordinateRoleNameChanged()
Notification signal for property with the same name.
QString coordinateRoleName
Name of the source model role holding the row's QGeoCoordinate.
DistanceSortProxyModel(QObject *parent=nullptr)
Standard constructor.
double resortDistance
Movement of the reference coordinate, in metres, that triggers a re-sort.
void setResortDistance(double newResortDistance)
Setter function for the property with the same name.
double resortDistance() const
Getter function for the property with the same name.
void setCoordinateRoleName(const QString &newCoordinateRoleName)
Setter function for the property with the same name.
NameFilterProxyModel(QObject *parent=nullptr)
Standard constructor.