Enroute Flight Navigation
A navigation app for VFR pilots
FlightRoute.h
1/***************************************************************************
2 * Copyright (C) 2019-2025 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 <QBindable>
24#include <QFile>
25#include <QGeoRectangle>
26#include <QJsonDocument>
27#include <QLocale>
28#include <QPointer>
29#include <QQmlEngine>
30#include <QXmlStreamReader>
31
32#include "geomaps/Waypoint.h"
33#include "navigation/Leg.h"
34
35namespace GeoMaps
36{
37 class GeoMapProvider;
38 class Waypoint;
39} // namespace GeoMaps
40
41class GlobalSettings;
42
43namespace Navigation
44{
45
58
59 class FlightRoute : public QObject
60 {
61 Q_OBJECT
62 QML_ELEMENT
63
64 public:
65 //
66 // Constructors and destructors
67 //
68
77 explicit FlightRoute(QObject *parent = nullptr);
78
79 // Standard destructor
80 ~FlightRoute() override = default;
81
82 //
83 // PROPERTIES
84 //
85
91 Q_PROPERTY(QGeoRectangle boundingRectangle READ boundingRectangle NOTIFY waypointsChanged)
92
93
98 Q_PROPERTY(QList<QGeoCoordinate> geoPath READ geoPath BINDABLE bindableGeoPath)
99
105 Q_PROPERTY(QList<GeoMaps::Waypoint> midFieldWaypoints READ midFieldWaypoints NOTIFY waypointsChanged)
106
111 Q_PROPERTY(QList<Navigation::Leg> legs READ legs BINDABLE bindableLegs)
112
114 Q_PROPERTY(qsizetype size READ size NOTIFY waypointsChanged)
115
124 Q_PROPERTY(QString summary READ summary NOTIFY summaryChanged)
125
131 Q_PROPERTY(QList<GeoMaps::Waypoint> waypoints READ waypoints NOTIFY waypointsChanged)
132
133
134 //
135 // Getter Methods
136 //
137
142 [[nodiscard]] auto boundingRectangle() const -> QGeoRectangle;
143
148 [[nodiscard]] QList<QGeoCoordinate> geoPath() const {return m_geoPath.value();}
149
154 [[nodiscard]] QBindable<QList<QGeoCoordinate>> bindableGeoPath() const {return &m_geoPath;}
155
160 [[nodiscard]] auto midFieldWaypoints() const -> QList<GeoMaps::Waypoint>;
161
166 [[nodiscard]] QList<Navigation::Leg> legs() const { return m_legs.value(); }
167
172 [[nodiscard]] QBindable<QList<Navigation::Leg>> bindableLegs() const { return &m_legs; }
173
178 [[nodiscard]] auto size() const -> qsizetype { return m_waypoints.value().size(); }
179
184 [[nodiscard]] auto summary() const -> QString;
185
190 [[nodiscard]] auto waypoints() const -> QList<GeoMaps::Waypoint> {return {m_waypoints};}
191
192
193 //
194 // METHODS
195 //
196
201 Q_INVOKABLE void append(const GeoMaps::Waypoint& waypoint);
202
209 Q_INVOKABLE void append(const QGeoCoordinate& position);
210
219 [[nodiscard]] Q_INVOKABLE bool canAppend(const GeoMaps::Waypoint& other) const;
220
227 [[nodiscard]] Q_INVOKABLE bool canInsert(const GeoMaps::Waypoint& other) const;
228
230 Q_INVOKABLE void clear();
231
239 [[nodiscard]] Q_INVOKABLE bool contains(const GeoMaps::Waypoint& waypoint) const;
240
250 [[nodiscard]] Q_INVOKABLE qsizetype currentLeg(const Positioning::PositionInfo& pInfo) const;
251
258 Q_INVOKABLE void directTo(const GeoMaps::Waypoint& target, const Positioning::PositionInfo& pInfo = {});
259
267 Q_INVOKABLE void insert(const GeoMaps::Waypoint& waypoint);
268
279 [[nodiscard]] Q_INVOKABLE qsizetype lastIndexOf(const GeoMaps::Waypoint& waypoint) const;
280
294 Q_INVOKABLE QString load(const QString& fileName);
295
300 Q_INVOKABLE void moveDown(int idx);
301
306 Q_INVOKABLE void moveUp(int idx);
307
315 Q_INVOKABLE void removeWaypoint(int idx);
316
327 Q_INVOKABLE void replaceWaypoint(int idx, const GeoMaps::Waypoint& newWaypoint);
328
330 Q_INVOKABLE void reverse();
331
343 [[nodiscard]] Q_INVOKABLE QString save(const QString& fileName = QString()) const;
344
353 [[nodiscard]] Q_INVOKABLE QString suggestedFilename() const;
354
363 [[nodiscard]] Q_INVOKABLE QByteArray toGeoJSON() const;
364
373 [[nodiscard]] Q_INVOKABLE QByteArray toGpx() const;
374
391 [[nodiscard]] Q_INVOKABLE QString toVfrFlightPlan() const;
392
393 signals:
396
399
400 private slots:
401
402 private:
403 Q_DISABLE_COPY_MOVE(FlightRoute)
404
405 // Helper function for method toGPX
406 [[nodiscard]] auto gpxElements(const QString& indent, const QString& tag) const -> QString;
407
408 QProperty<QList<QGeoCoordinate>> m_geoPath;
409 QList<QGeoCoordinate> computeGeoPath();
410
411 Q_OBJECT_BINDABLE_PROPERTY(Navigation::FlightRoute, QVector<GeoMaps::Waypoint>, m_waypoints, &Navigation::FlightRoute::waypointsChanged);
412
413 QProperty<QVector<Leg>> m_legs;
414 QVector<Leg> computeLegs();
415
416 QLocale myLocale;
417 };
418
419} // namespace Navigation
Provides geographic information.
Waypoint, such as an airfield, a navaid station or a reporting point.
Definition Waypoint.h:41
Global Settings Manager.
Intended flight route.
Definition FlightRoute.h:60
Q_INVOKABLE QString load(const QString &fileName)
Loads the route from a GeoJSON or GPX document.
qsizetype size
Number of waypoints in the route.
auto size() const -> qsizetype
Getter function for the property with the same name.
Q_INVOKABLE qsizetype currentLeg(const Positioning::PositionInfo &pInfo) const
Determines current leg.
Q_INVOKABLE void insert(const GeoMaps::Waypoint &waypoint)
Inserts a waypoint into the route.
Q_INVOKABLE bool canInsert(const GeoMaps::Waypoint &other) const
Checks if waypoint can reasonably be inserted into this route.
Q_INVOKABLE bool contains(const GeoMaps::Waypoint &waypoint) const
Returns true if waypoint is in this route.
Q_INVOKABLE QByteArray toGeoJSON() const
Exports to route to GeoJSON.
void summaryChanged()
Notification signal for the property with the same name.
Q_INVOKABLE void append(const GeoMaps::Waypoint &waypoint)
Adds a waypoint to the end of the route.
Q_INVOKABLE void moveDown(int idx)
Move waypoint one position down in the list of waypoints.
auto summary() const -> QString
Getter function for the property with the same name.
Q_INVOKABLE void clear()
Deletes all waypoints in the current route.
Q_INVOKABLE bool canAppend(const GeoMaps::Waypoint &other) const
Checks if waypoint can be added as the new end of this route.
Q_INVOKABLE void moveUp(int idx)
Move waypoint one position up in the list of waypoints.
QString summary
Human-readable summary of the flight route.
QBindable< QList< Navigation::Leg > > bindableLegs() const
Getter function for the property with the same name.
Q_INVOKABLE QString save(const QString &fileName=QString()) const
Saves flight route to a file.
QBindable< QList< QGeoCoordinate > > bindableGeoPath() const
Getter function for the property with the same name.
QList< GeoMaps::Waypoint > waypoints
List of waypoints in the flight route that are not airfields.
auto midFieldWaypoints() const -> QList< GeoMaps::Waypoint >
Getter function for the property with the same name.
Q_INVOKABLE void append(const QGeoCoordinate &position)
Adds a waypoint to the end of the route.
Q_INVOKABLE void removeWaypoint(int idx)
Remove waypoint from the current route.
QList< QGeoCoordinate > geoPath
List of coordinates for the waypoints.
Definition FlightRoute.h:98
FlightRoute(QObject *parent=nullptr)
Construct a flight route.
QGeoRectangle boundingRectangle
Bounding rectangle.
Definition FlightRoute.h:91
QList< Navigation::Leg > legs
List of legs.
Q_INVOKABLE QString toVfrFlightPlan() const
Exports to route to VFR Flight Plan Format.
Q_INVOKABLE qsizetype lastIndexOf(const GeoMaps::Waypoint &waypoint) const
Index for last occurrence of the waypoint in the flight route.
Q_INVOKABLE void replaceWaypoint(int idx, const GeoMaps::Waypoint &newWaypoint)
Replaces a waypoint.
void waypointsChanged()
Notification signal for the property with the same name.
Q_INVOKABLE QByteArray toGpx() const
Exports to route to GPX.
Q_INVOKABLE QString suggestedFilename() const
Suggests a name for saving this route.
QList< GeoMaps::Waypoint > midFieldWaypoints
List of waypoints in the flight route that are not airfields.
Q_INVOKABLE void reverse()
Reverse the route.
Q_INVOKABLE void directTo(const GeoMaps::Waypoint &target, const Positioning::PositionInfo &pInfo={})
Modifies the current route, to make 'target' the next waypoint.
Leg in a flight route.
Definition Leg.h:37
Geographic position.