Enroute Flight Navigation
A navigation app for VFR pilots
Navigator.h
1/***************************************************************************
2 * Copyright (C) 2019-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 <QQmlEngine>
24#include <QStandardPaths>
25
26#include "FlightRoute.h"
27#include "GlobalObject.h"
28#include "navigation/FlightRoute.h"
29#include "navigation/RemainingRouteInfo.h"
30
31using namespace Qt::Literals::StringLiterals;
32
33namespace Navigation {
34
41
42class Navigator : public GlobalObject
43{
44 Q_OBJECT
45 QML_ELEMENT
46 QML_SINGLETON
47
48public:
50 enum FlightStatus : quint8
51 {
55 };
56 Q_ENUM(FlightStatus)
57
58
59
60 //
61 // Constructors and Destructors
62 //
63
64
68 explicit Navigator(QObject* parent = nullptr);
69
70 // deferred initialization
71 void deferredInitialization() override;
72
73 // No default constructor, important for QML singleton
74 explicit Navigator() = delete;
75
77 ~Navigator() override = default;
78
79 // factory function for QML singleton
80 static Navigation::Navigator* create(QQmlEngine* /*unused*/, QJSEngine* /*unused*/)
81 {
83 }
84
85
86 //
87 // PROPERTIES
88 //
89
95 Q_PROPERTY(Navigation::Aircraft aircraft READ aircraft BINDABLE bindableAircraft WRITE setAircraft NOTIFY aircraftChanged)
96 [[nodiscard]] Navigation::Aircraft aircraft() const { return m_aircraft.value(); }
97 [[nodiscard]] QBindable<Navigation::Aircraft> bindableAircraft() { return &m_aircraft; }
98 void setAircraft(const Navigation::Aircraft& newAircraft);
99
105 Q_PROPERTY(bool hasAviationMapForCurrentLocation READ hasAviationMapForCurrentLocation BINDABLE bindableHasAviationMapForCurrentLocation)
106 [[nodiscard]] bool hasAviationMapForCurrentLocation() const {return m_hasAviationMapForCurrentLocation.value();}
107 [[nodiscard]] QBindable<bool> bindableHasAviationMapForCurrentLocation() {return &m_hasAviationMapForCurrentLocation;}
108
115 [[nodiscard]] Navigation::FlightRoute* flightRoute();
116
123 [[nodiscard]] FlightStatus flightStatus() const { return m_flightStatus; }
124
126 Q_PROPERTY(Navigation::RemainingRouteInfo remainingRouteInfo READ remainingRouteInfo BINDABLE bindableRemainingRouteInfo)
127 [[nodiscard]] Navigation::RemainingRouteInfo remainingRouteInfo() const {return m_remainingRouteInfo.value();}
128 [[nodiscard]] QBindable<Navigation::RemainingRouteInfo> bindableRemainingRouteInfo() {return &m_remainingRouteInfo;}
129
131 Q_PROPERTY(Weather::Wind wind READ wind WRITE setWind NOTIFY windChanged)
132 [[nodiscard]] Weather::Wind wind() const { return m_wind; }
133 void setWind(Weather::Wind newWind);
134
135signals:
138
149
152
155
156private slots:
157 // Check if altitude limit for flight maps needs to be lifted. Connected to positioning source.
158 void updateAltitudeLimit();
159
160 // Update flight status. Connected to positioning source.
161 void updateFlightStatus();
162
163 // Re-computes the Remaining Route Info. The argument must be the current position info of the own aircraft.
164 void updateRemainingRouteInfo();
165
166private:
167 Q_DISABLE_COPY_MOVE(Navigator)
168
169 // Updater function for the property with the same name
170 void setFlightStatus(FlightStatus newFlightStatus);
171
172 QProperty<bool> m_hasAviationMapForCurrentLocation {false};
173 bool computeHasAviationMapForCurrentLocation();
174
175
176 // Hysteresis for flight speed
177 static constexpr auto flightSpeedHysteresis = Units::Speed::fromKN(5.0);
178
179 FlightStatus m_flightStatus {Unknown};
180
181 QProperty<Aircraft> m_aircraft {};
182
183 QPointer<FlightRoute> m_flightRoute {nullptr};
184 const QString m_flightRouteFileName {QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + u"/flight route.geojson"_s};
185
186 Weather::Wind m_wind {};
187
188 QString m_aircraftFileName;
189
190 QProperty<RemainingRouteInfo> m_remainingRouteInfo;
191};
192
193} // namespace Navigation
static Q_INVOKABLE Navigation::Navigator * navigator()
Pointer to appplication-wide static Navigation::Navigator instance.
GlobalObject(QObject *parent=nullptr)
Standard constructor.
This extremely simple class holds a few numbers that describe an aircraft.
Definition Aircraft.h:35
Intended flight route.
Definition FlightRoute.h:60
FlightStatus flightStatus
Estimate whether the device is flying or on the ground.
Definition Navigator.h:122
bool hasAviationMapForCurrentLocation
Indicates whether an aviation map is installed for the current location.
Definition Navigator.h:105
Navigator(QObject *parent=nullptr)
Standard constructor.
void flightStatusChanged()
Notifier signal.
FlightStatus
FlightStatus.
Definition Navigator.h:51
void aircraftChanged()
Notifier signal.
void deferredInitialization() override
Non-constructor initialization.
Weather::Wind wind
Current wind.
Definition Navigator.h:131
Navigation::RemainingRouteInfo remainingRouteInfo
Up-to-date information about the remaining route.
Definition Navigator.h:126
Navigation::FlightRoute * flightRoute
Current flight route.
Definition Navigator.h:114
Navigation::Aircraft aircraft
Current aircraft.
Definition Navigator.h:95
void airspaceAltitudeLimitAdjusted()
Emitted when the airspaceAltitudeLimit is adjusted.
void windChanged()
Notifier signal.
Info about remaining route.
static Q_INVOKABLE constexpr Units::Speed fromKN(double speedInKT)
Constructs a speed.
Definition Speed.h:87
This extremely simple class holds the wind speed and direction.
Definition Wind.h:32