Enroute Flight Navigation
A navigation app for VFR pilots
Navigator.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 <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
96
97
102 Q_PROPERTY(Navigation::FlightRoute* flightRoute READ flightRoute CONSTANT)
103
110
113
115 Q_PROPERTY(Weather::Wind wind READ wind WRITE setWind NOTIFY windChanged)
116
117
118 //
119 // Getter Methods
120 //
121
126 [[nodiscard]] auto aircraft() const -> Navigation::Aircraft { return m_aircraft; }
127
133
138 [[nodiscard]] auto flightStatus() const -> FlightStatus { return m_flightStatus; }
139
144 [[nodiscard]] Navigation::RemainingRouteInfo remainingRouteInfo() const {return m_remainingRouteInfo.value();}
145
150 [[nodiscard]] QBindable<Navigation::RemainingRouteInfo> bindableRemainingRouteInfo() const {return &m_remainingRouteInfo;}
151
156 [[nodiscard]] auto wind() const -> Weather::Wind { return m_wind; }
157
158
159 //
160 // Setter Methods
161 //
162
167 void setAircraft(const Navigation::Aircraft& newAircraft);
168
173 void setWind(Weather::Wind newWind);
174
175signals:
178
189
192
195
196private slots:
197 // Check if altitude limit for flight maps needs to be lifted. Connected to positioning source.
198 void updateAltitudeLimit();
199
200 // Update flight status. Connected to positioning source.
201 void updateFlightStatus();
202
203 // Re-computes the Remaining Route Info. The argument must be the current position info of the own aircraft.
204 void updateRemainingRouteInfo();
205
206private:
207 Q_DISABLE_COPY_MOVE(Navigator)
208
209 // Updater function for the property with the same name
210 void setFlightStatus(FlightStatus newFlightStatus);
211
212 // Hysteresis for flight speed
213 static constexpr auto flightSpeedHysteresis = Units::Speed::fromKN(5.0);
214
215 FlightStatus m_flightStatus {Unknown};
216
217 Aircraft m_aircraft {};
218
219 QPointer<FlightRoute> m_flightRoute {nullptr};
220 const QString m_flightRouteFileName {QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + u"/flight route.geojson"_s};
221
222 Weather::Wind m_wind {};
223
224 QString m_aircraftFileName;
225
226 QProperty<RemainingRouteInfo> m_remainingRouteInfo;
227};
228
229} // 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
auto flightStatus() const -> FlightStatus
Getter function for the property with the same name.
Definition Navigator.h:138
FlightStatus flightStatus
Estimate whether the device is flying or on the ground.
Definition Navigator.h:109
Navigation::RemainingRouteInfo remainingRouteInfo() const
Getter function for the property with the same name.
Definition Navigator.h:144
void setWind(Weather::Wind newWind)
Setter function for property of the same name.
Navigator(QObject *parent=nullptr)
Standard constructor.
void flightStatusChanged()
Notifier signal.
void setAircraft(const Navigation::Aircraft &newAircraft)
Setter function for property of the same name.
FlightStatus
FlightStatus.
Definition Navigator.h:51
auto wind() const -> Weather::Wind
Getter function for the property with the same name.
Definition Navigator.h:156
void aircraftChanged()
Notifier signal.
void deferredInitialization() override
Non-constructor initialization.
Weather::Wind wind
Current wind.
Definition Navigator.h:115
auto flightRoute() -> Navigation::FlightRoute *
Getter function for the property with the same name.
Navigation::RemainingRouteInfo remainingRouteInfo
Up-to-date information about the remaining route.
Definition Navigator.h:112
Navigation::FlightRoute * flightRoute
Current flight route.
Definition Navigator.h:102
Navigation::Aircraft aircraft
Current aircraft.
Definition Navigator.h:95
void airspaceAltitudeLimitAdjusted()
Emitted when the airspaceAltitudeLimit is adjusted.
void windChanged()
Notifier signal.
QBindable< Navigation::RemainingRouteInfo > bindableRemainingRouteInfo() const
Getter function for the property with the same name.
Definition Navigator.h:150
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