Enroute Flight Navigation
A navigation app for VFR pilots
Ui::DistanceSortProxyModel Class Reference

NameFilterProxyModel that orders rows by distance to a reference position. More...

#include <DistanceSortProxyModel.h>

Inheritance diagram for Ui::DistanceSortProxyModel:
Ui::NameFilterProxyModel

Signals

void referenceCoordinateChanged ()
 Notification signal for property with the same name.
void coordinateRoleNameChanged ()
 Notification signal for property with the same name.
void resortDistanceChanged ()
 Notification signal for property with the same name.
Signals inherited from Ui::NameFilterProxyModel
void filterChanged ()
 Notification signal for property with the same name.
void filterRoleNameChanged ()
 Notification signal for property with the same name.

Public Member Functions

 DistanceSortProxyModel (QObject *parent=nullptr)
 Standard constructor.
QGeoCoordinate referenceCoordinate () const
 Getter function for the property with the same name.
QString coordinateRoleName () const
 Getter function for the property with the same name.
double resortDistance () const
 Getter function for the property with the same name.
void setReferenceCoordinate (const QGeoCoordinate &newReferenceCoordinate)
 Setter function for the property with the same name.
void setCoordinateRoleName (const QString &newCoordinateRoleName)
 Setter function for the property with the same name.
void setResortDistance (double newResortDistance)
 Setter function for the property with the same name.
void setSourceModel (QAbstractItemModel *newSourceModel) override
 Re-implemented from QAbstractProxyModel.
Public Member Functions inherited from Ui::NameFilterProxyModel
 NameFilterProxyModel (QObject *parent=nullptr)
 Standard constructor.
QString filter () const
 Getter function for the property with the same name.
QString filterRoleName () const
 Getter function for the property with the same name.
void setFilter (const QString &newFilter)
 Setter function for the property with the same name.
void setFilterRoleName (const QString &newFilterRoleName)
 Setter function for the property with the same name.
void setSourceModel (QAbstractItemModel *newSourceModel) override
 Re-implemented from QAbstractProxyModel.

Protected Member Functions

bool lessThan (const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override
 Re-implemented from QSortFilterProxyModel.
Protected Member Functions inherited from Ui::NameFilterProxyModel
bool filterAcceptsRow (int sourceRow, const QModelIndex &sourceParent) const override
 Re-implemented from QSortFilterProxyModel.
int roleForName (const QString &roleName) const
 Looks up a role by name in the source model.

Properties

QGeoCoordinate referenceCoordinate
 Position that distances are measured from.
QString coordinateRoleName
 Name of the source model role holding the row's QGeoCoordinate.
double resortDistance
 Movement of the reference coordinate, in metres, that triggers a re-sort.
Properties inherited from Ui::NameFilterProxyModel
QString filter
 Filter string.
QString filterRoleName
 Name of the source model role that the filter is matched against.

Detailed Description

NameFilterProxyModel that orders rows by distance to a reference position.

This proxy model filters like NameFilterProxyModel and, in addition, orders the accepted rows by distance to the property 'referenceCoordinate', closest first. The distance is computed from the source model role 'coordinateRoleName', which must hold a QGeoCoordinate.

Position feeds update at a high rate. To avoid re-sorting the list on every update, the order is recomputed only when the reference coordinate has moved by more than 'resortDistance' since the last sort. While the reference coordinate is invalid, the order of the source model is kept.

Definition at line 42 of file DistanceSortProxyModel.h.

Constructor & Destructor Documentation

◆ DistanceSortProxyModel()

Ui::DistanceSortProxyModel::DistanceSortProxyModel ( QObject * parent = nullptr)
explicit

Standard constructor.

Parameters
parentThe standard QObject parent pointer

Member Function Documentation

◆ coordinateRoleName()

QString Ui::DistanceSortProxyModel::coordinateRoleName ( ) const
inlinenodiscard

Getter function for the property with the same name.

Returns
Property coordinateRoleName

Definition at line 96 of file DistanceSortProxyModel.h.

◆ lessThan()

bool Ui::DistanceSortProxyModel::lessThan ( const QModelIndex & sourceLeft,
const QModelIndex & sourceRight ) const
nodiscardoverrideprotected

Re-implemented from QSortFilterProxyModel.

Parameters
sourceLeftIndex in the source model
sourceRightIndex in the source model
Returns
True if the row of sourceLeft is closer to the reference coordinate than the row of sourceRight

◆ referenceCoordinate()

QGeoCoordinate Ui::DistanceSortProxyModel::referenceCoordinate ( ) const
inlinenodiscard

Getter function for the property with the same name.

Returns
Property referenceCoordinate

Definition at line 90 of file DistanceSortProxyModel.h.

◆ resortDistance()

double Ui::DistanceSortProxyModel::resortDistance ( ) const
inlinenodiscard

Getter function for the property with the same name.

Returns
Property resortDistance

Definition at line 102 of file DistanceSortProxyModel.h.

◆ setCoordinateRoleName()

void Ui::DistanceSortProxyModel::setCoordinateRoleName ( const QString & newCoordinateRoleName)

Setter function for the property with the same name.

Parameters
newCoordinateRoleNameProperty coordinateRoleName

◆ setReferenceCoordinate()

void Ui::DistanceSortProxyModel::setReferenceCoordinate ( const QGeoCoordinate & newReferenceCoordinate)

Setter function for the property with the same name.

Parameters
newReferenceCoordinateProperty referenceCoordinate

◆ setResortDistance()

void Ui::DistanceSortProxyModel::setResortDistance ( double newResortDistance)

Setter function for the property with the same name.

Parameters
newResortDistanceProperty resortDistance

◆ setSourceModel()

void Ui::DistanceSortProxyModel::setSourceModel ( QAbstractItemModel * newSourceModel)
override

Re-implemented from QAbstractProxyModel.

Sets the source model and activates sorting.

Parameters
newSourceModelSource model

Property Documentation

◆ coordinateRoleName

QString Ui::DistanceSortProxyModel::coordinateRoleName
readwrite

Name of the source model role holding the row's QGeoCoordinate.

Defaults to "center". Rows keep the source order if the source model has no role of this name.

Definition at line 73 of file DistanceSortProxyModel.h.

◆ referenceCoordinate

QGeoCoordinate Ui::DistanceSortProxyModel::referenceCoordinate
readwrite

Position that distances are measured from.

Invalid coordinates are accepted and leave the current order unchanged.

Definition at line 66 of file DistanceSortProxyModel.h.

◆ resortDistance

double Ui::DistanceSortProxyModel::resortDistance
readwrite

Movement of the reference coordinate, in metres, that triggers a re-sort.

Defaults to 1000 metres.

Definition at line 79 of file DistanceSortProxyModel.h.


The documentation for this class was generated from the following file: