Enroute Flight Navigation
A navigation app for VFR pilots
GeoMaps::WaypointLibrary Class Reference

Library of user-defined waypoints. More...

#include <WaypointLibrary.h>

Public Types

enum  Role : int { WaypointRole = Qt::UserRole + 1 , NameRole }
 Model roles. More...

Signals

void waypointsChanged ()
 Notification signal for the property with the same name.

Public Member Functions

 WaypointLibrary (QObject *parent=nullptr)
 Creates a new waypoint library.
QList< GeoMaps::Waypointwaypoints () const
 Getter function for property with the same name.
QByteArray GeoJSON () const
 Getter function for property with the same name.
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 Re-implemented from QAbstractListModel.
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 Re-implemented from QAbstractListModel.
QHash< int, QByteArray > roleNames () const override
 Re-implemented from QAbstractListModel.
Q_INVOKABLE void add (const GeoMaps::Waypoint &waypoint)
 Adds a waypoint to the library.
Q_INVOKABLE void clear ()
 Clears the waypoint library.
Q_INVOKABLE bool contains (const GeoMaps::Waypoint &waypoint) const
 Checks if library contains an given waypoint.
Q_INVOKABLE bool hasNearbyEntry (const GeoMaps::Waypoint &waypoint) const
 Check if the library contains a waypoint near to a given one.
Q_INVOKABLE QString import (const QString &fileName, bool skip)
 Import waypoints into the library.
Q_INVOKABLE QString loadFromGeoJSON (QString fileName={})
 Read from file.
Q_INVOKABLE bool remove (const GeoMaps::Waypoint &waypoint)
 Remove waypoint.
Q_INVOKABLE bool replace (const GeoMaps::Waypoint &oldWaypoint, const GeoMaps::Waypoint &newWaypoint)
 Replace waypoint.
Q_INVOKABLE QString save (QString fileName={}) const
 Save to file.
Q_INVOKABLE QByteArray toGpx () const
 Serialize into GPX document.

Properties

QList< GeoMaps::Waypointwaypoints
 List of waypoints.
QByteArray GeoJSON
 List of waypoints.

Detailed Description

Library of user-defined waypoints.

This class holds the list of user-defined waypoints, sorted by name, and exposes it as a list model with the roles 'waypoint' and 'name'. The library is loaded from a GeoJSON file on construction and saved every time that a change is made.

Changes are announced with row-granular model signals, so that views bound to this model update incrementally, and with the coarse signal waypointsChanged() for consumers of the property 'waypoints'. In QML, bind a view to this singleton through a NameFilterProxyModel.

Definition at line 46 of file WaypointLibrary.h.

Member Enumeration Documentation

◆ Role

Model roles.

Enumerator
WaypointRole 

The waypoint, of type GeoMaps::Waypoint.

NameRole 

Name of the waypoint, a QString.

Definition at line 75 of file WaypointLibrary.h.

Constructor & Destructor Documentation

◆ WaypointLibrary()

GeoMaps::WaypointLibrary::WaypointLibrary ( QObject * parent = nullptr)
explicit

Creates a new waypoint library.

This constructor creates a new WaypointLibrary instance. The library is loaded from a GeoJSON file whose name is found in the private member stdFileName.

Parameters
parentThe standard QObject parent

Member Function Documentation

◆ add()

Q_INVOKABLE void GeoMaps::WaypointLibrary::add ( const GeoMaps::Waypoint & waypoint)

Adds a waypoint to the library.

Parameters
waypointWaypoint to be added. If that waypoint is invalid, this method will not do anything

◆ contains()

Q_INVOKABLE bool GeoMaps::WaypointLibrary::contains ( const GeoMaps::Waypoint & waypoint) const
inlinenodiscard

Checks if library contains an given waypoint.

Parameters
waypointWaypoint
Returns
True if an exact copy of the waypoint is found in the library

Definition at line 171 of file WaypointLibrary.h.

◆ data()

QVariant GeoMaps::WaypointLibrary::data ( const QModelIndex & index,
int role = Qt::DisplayRole ) const
nodiscardoverride

Re-implemented from QAbstractListModel.

Parameters
indexModel index
roleOne of the roles in WaypointLibrary::Role
Returns
Data for the role, or an invalid QVariant

◆ GeoJSON()

QByteArray GeoMaps::WaypointLibrary::GeoJSON ( ) const
nodiscard

Getter function for property with the same name.

Returns
Property GeoJSON

◆ hasNearbyEntry()

Q_INVOKABLE bool GeoMaps::WaypointLibrary::hasNearbyEntry ( const GeoMaps::Waypoint & waypoint) const
nodiscard

Check if the library contains a waypoint near to a given one.

The method checks proximity with the method GeoMaps::Waypoint::isNear

Parameters
waypointWaypoint
Returns
True if yes

◆ import()

Q_INVOKABLE QString GeoMaps::WaypointLibrary::import ( const QString & fileName,
bool skip )
nodiscard

Import waypoints into the library.

This method reads waypoints from a file and adds them to the library.

Parameters
fileNameName of file to import. Must be in CUP, GPX or GeoJSON format.
skipIf true, skip over waypoints that already exist in the library
Returns
Human-readable error message, or an empty string on success

◆ loadFromGeoJSON()

Q_INVOKABLE QString GeoMaps::WaypointLibrary::loadFromGeoJSON ( QString fileName = {})
nodiscard

Read from file.

Reads the library from a file in GeoJSON format. On sucess, the current library is replaced in full. On error, the current library is not touched at all.

Parameters
fileNameFile name. If emty, a standard file name will be used, in QStandardPaths::AppDataLocation. See the private member stdFileName for details.
Returns
An empty string on success and a human-readable tranlated error message otherwise.

◆ remove()

Q_INVOKABLE bool GeoMaps::WaypointLibrary::remove ( const GeoMaps::Waypoint & waypoint)

Remove waypoint.

Removes the first waypoint from the list that matches the given waypoint exactly. If no waypoint matches, this method does nothing.

Parameters
waypointWaypoint to be removed
Returns
True if a waypoint has indeed been removed.

◆ replace()

Q_INVOKABLE bool GeoMaps::WaypointLibrary::replace ( const GeoMaps::Waypoint & oldWaypoint,
const GeoMaps::Waypoint & newWaypoint )

Replace waypoint.

Replaces the first waypoint from the list that matches the given oldWaypoint exactly. If no waypoint matches, this method does nothing.

Parameters
oldWaypointWaypoint that shall be replaced
newWaypointWaypoint replacement. If this waypoint is invalid, the method returns immediately and does nothing.
Returns
True if a waypoint has indeed been replaced.

◆ roleNames()

QHash< int, QByteArray > GeoMaps::WaypointLibrary::roleNames ( ) const
nodiscardoverride

Re-implemented from QAbstractListModel.

Returns
Names of the roles in WaypointLibrary::Role

◆ rowCount()

int GeoMaps::WaypointLibrary::rowCount ( const QModelIndex & parent = QModelIndex()) const
nodiscardoverride

Re-implemented from QAbstractListModel.

Parameters
parentParent index, invalid for the list itself
Returns
Number of waypoints, or zero for a valid parent

◆ save()

Q_INVOKABLE QString GeoMaps::WaypointLibrary::save ( QString fileName = {}) const
nodiscard

Save to file.

Saves the library in GeoJSON format.

Parameters
fileNameFile name. If emty, a standard file name will be used, in QStandardPaths::AppDataLocation. See the private member stdFileName for details.
Returns
An empty string on success and a human-readable tranlated error message otherwise.

◆ toGpx()

Q_INVOKABLE QByteArray GeoMaps::WaypointLibrary::toGpx ( ) const
nodiscard

Serialize into GPX document.

This method serialises the current library as a GPX document. The document conforms to the specification outlined here

Returns
QByteArray containing GPX data describing the flight route

◆ waypoints()

QList< GeoMaps::Waypoint > GeoMaps::WaypointLibrary::waypoints ( ) const
inlinenodiscard

Getter function for property with the same name.

Returns
Property waypoints

Definition at line 109 of file WaypointLibrary.h.

◆ waypointsChanged

void GeoMaps::WaypointLibrary::waypointsChanged ( )
signal

Notification signal for the property with the same name.

This coarse signal is emitted after every change, following the row-granular model signals.

Property Documentation

◆ GeoJSON

QByteArray GeoMaps::WaypointLibrary::GeoJSON
read

List of waypoints.

This property holds the list of waypoints, in alphabetical order.

Definition at line 98 of file WaypointLibrary.h.

◆ waypoints

QList<GeoMaps::Waypoint> GeoMaps::WaypointLibrary::waypoints
read

List of waypoints.

This property holds the list of waypoints, in alphabetical order

Definition at line 92 of file WaypointLibrary.h.


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