Enroute Flight Navigation
A navigation app for VFR pilots
PositionProvider.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 <QQmlEngine>
25
26#include "GlobalObject.h"
27#include "positioning/PositionInfoSource_Satellite.h"
28
29
30namespace Positioning {
31
47
48class PositionProvider : public QObject
49{
50 Q_OBJECT
51 QML_ELEMENT
52 QML_SINGLETON
53
54
55public:
60 explicit PositionProvider(QObject* parent = nullptr);
61
62 // No default constructor, important for QML singleton
63 explicit PositionProvider() = delete;
64
66 ~PositionProvider() override = default;
67
68
69 // factory function for QML singleton
70 static Positioning::PositionProvider* create(QQmlEngine* /*unused*/, QJSEngine* /*unused*/)
71 {
73 }
74
75
76 //
77 // PROPERTIES
78 //
79
86
87
95
102 Q_PROPERTY(Units::Angle lastValidTT READ lastValidTT BINDABLE bindableLastValidTT)
103
111 Q_PROPERTY(Positioning::PositionInfo positionInfo READ positionInfo BINDABLE bindablePositionInfo NOTIFY positionInfoChanged)
112
122
130
137 Q_PROPERTY(QString statusString READ statusString BINDABLE bindableStatusString)
138
139
140 //
141 // Getter Methods
142 //
143
148 [[nodiscard]] QGeoCoordinate approximateLastValidCoordinate() const {return m_approximateLastValidCoordinate.value();}
149
154 [[nodiscard]] QBindable<QGeoCoordinate> bindableApproximateLastValidCoordinate() const {return &m_approximateLastValidCoordinate;}
155
160 [[nodiscard]] static QGeoCoordinate lastValidCoordinate();
161
166 [[nodiscard]] QBindable<QGeoCoordinate> bindableLastValidCoordinate() {return &m_lastValidCoordinate;}
167
172 [[nodiscard]] static Units::Angle lastValidTT();
173
178 [[nodiscard]] QBindable<Units::Angle> bindableLastValidTT() {return &m_lastValidTT;}
179
184 [[nodiscard]] Positioning::PositionInfo positionInfo() const {return m_positionInfo.value();}
185
190 [[nodiscard]] QBindable<Positioning::PositionInfo> bindablePositionInfo() const {return &m_positionInfo;}
191
196 [[nodiscard]] Units::Distance pressureAltitude() const {return m_pressureAltitude.value();}
197
202 [[nodiscard]] QBindable<Units::Distance> bindablePressureAltitude() const {return &m_pressureAltitude;}
203
208 [[nodiscard]] bool receivingPositionInfo() const {return m_receivingPositionInfo.value();}
209
214 [[nodiscard]] QBindable<bool> bindableReceivingPositionInfo() {return &m_receivingPositionInfo;}
215
220 [[nodiscard]] QString statusString() const
221 {
222 return m_statusString.value();
223 }
224
229 [[nodiscard]] QBindable<QString> bindableStatusString() const
230 {
231 return &m_statusString;
232 }
233
234
235
236 //
237 // Methods
238 //
239
246 Q_INVOKABLE void startUpdates() { satelliteSource.startUpdates(); }
247
248signals:
249 // Notifier signal
250 void approximateLastValidCoordinateChanged();
251
252 // Notifier signal
253 void positionInfoChanged(const Positioning::PositionInfo& info);
254
255 // Notifier signal
256 void receivingPositionInfoChanged(bool);
257
258private slots:
259 // Intializations that are moved out of the constructor, in order to avoid
260 // nested uses of constructors in Global.
261 void deferredInitialization();
262
263 // Saves last valid position and track
264 void savePositionAndTrack();
265
266private:
267 Q_DISABLE_COPY_MOVE(PositionProvider)
268
269 // Computation method for property with the same name
270 QString computeStatusString();
271
272 // Aircraft is considered flying if speed is at least this high
273 static constexpr double minFlightSpeedInKT = 30.0;
274 // Hysteresis for flight speed
275 static constexpr double flightSpeedHysteresis = 5.0;
276
277 // Coordinates of EDTF airfield
278 static constexpr double EDTF_lat = 48.022653;
279 static constexpr double EDTF_lon = 7.832583;
280 static constexpr double EDTF_ele = 244;
281
282 PositionInfoSource_Satellite satelliteSource;
283
284 // The incoming position info is set by a binding that monitors
285 // the satelliteSource and the TrafficDataSource
286 QProperty<Positioning::PositionInfo> m_incomingPositionInfo;
287 Positioning::PositionInfo computeIncomingPositionInfo();
288
289 // This method updates m_approximateLastValidCoordinate, m_lastValidCoordinate and m_lastValidTT
290 // whenever m_incomingPositionInfo changes.
291 void onIncomingPositionInfoUpdated();
292 QPropertyNotifier m_incomingPositionInfoNotifier;
293
294 Q_OBJECT_BINDABLE_PROPERTY(Positioning::PositionProvider, Positioning::PositionInfo, m_positionInfo, &Positioning::PositionProvider::positionInfoChanged);
295 Q_OBJECT_BINDABLE_PROPERTY(Positioning::PositionProvider, QGeoCoordinate, m_approximateLastValidCoordinate, &Positioning::PositionProvider::approximateLastValidCoordinateChanged);
296 QProperty<QGeoCoordinate> m_lastValidCoordinate {QGeoCoordinate(EDTF_lat, EDTF_lon, EDTF_ele)};
297 QProperty<Units::Angle> m_lastValidTT;
298
299 Q_OBJECT_BINDABLE_PROPERTY(Positioning::PositionProvider, bool, m_receivingPositionInfo, &Positioning::PositionProvider::receivingPositionInfoChanged);
300 QProperty<QString> m_statusString;
301
302 QProperty<Units::Distance> m_pressureAltitude;
303 Units::Distance computePressureAltitude();
304};
305
306} // namespace Positioning
static Q_INVOKABLE Positioning::PositionProvider * positionProvider()
Pointer to appplication-wide static PositionProvider instance.
Geographic position.
Central Position Provider.
QBindable< Positioning::PositionInfo > bindablePositionInfo() const
Getter method for property with the same name.
PositionProvider(QObject *parent=nullptr)
Standard constructor.
Units::Distance pressureAltitude
Pressure altitude.
Positioning::PositionInfo positionInfo() const
Getter method for property with the same name.
QString statusString() const
Getter method for property with the same name.
QBindable< QGeoCoordinate > bindableLastValidCoordinate()
Getter function for the property with the same name.
Units::Angle lastValidTT
Last valid true track.
Units::Distance pressureAltitude() const
Getter method for property with the same name.
QBindable< Units::Angle > bindableLastValidTT()
Getter function for the property with the same name.
static QGeoCoordinate lastValidCoordinate()
Getter function for the property with the same name.
QGeoCoordinate lastValidCoordinate
Last valid coordinate reading.
QBindable< Units::Distance > bindablePressureAltitude() const
Getter method for property with the same name.
QBindable< QString > bindableStatusString() const
Getter method for property with the same name.
QGeoCoordinate approximateLastValidCoordinate
Approximate last valid coordinate.
Positioning::PositionInfo positionInfo
Position information.
~PositionProvider() override=default
Standard destructor.
static Units::Angle lastValidTT()
Getter function for the property with the same name.
QString statusString
Source status.
QBindable< bool > bindableReceivingPositionInfo()
Getter method for property with the same name.
bool receivingPositionInfo() const
Getter method for property with the same name.
QBindable< QGeoCoordinate > bindableApproximateLastValidCoordinate() const
Getter function for the property with the same name.
Q_INVOKABLE void startUpdates()
startUpdates
bool receivingPositionInfo
Indicator that position information is being received.
Convenience class for angle computations.
Definition Angle.h:41
Convenience class for distance computations.
Definition Distance.h:35
Conversion between units used in aviation.
Definition Angle.h:34