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
103 Q_PROPERTY(QGeoCoordinate mapCenter READ mapCenter WRITE setMapCenter BINDABLE bindableMapCenter NOTIFY mapCenterChanged)
104
111 Q_PROPERTY(Units::Angle lastValidTT READ lastValidTT BINDABLE bindableLastValidTT)
112
120 Q_PROPERTY(Positioning::PositionInfo positionInfo READ positionInfo BINDABLE bindablePositionInfo NOTIFY positionInfoChanged)
121
131
139
146 Q_PROPERTY(QString statusString READ statusString BINDABLE bindableStatusString)
147
148
149 //
150 // Getter Methods
151 //
152
157 [[nodiscard]] QGeoCoordinate approximateLastValidCoordinate() const {return m_approximateLastValidCoordinate.value();}
158
163 [[nodiscard]] QBindable<QGeoCoordinate> bindableApproximateLastValidCoordinate() const {return &m_approximateLastValidCoordinate;}
164
169 [[nodiscard]] static QGeoCoordinate lastValidCoordinate();
170
175 [[nodiscard]] QBindable<QGeoCoordinate> bindableLastValidCoordinate() {return &m_lastValidCoordinate;}
176
181 [[nodiscard]] static Units::Angle lastValidTT();
182
187 [[nodiscard]] QBindable<Units::Angle> bindableLastValidTT() {return &m_lastValidTT;}
188
193 [[nodiscard]] QGeoCoordinate mapCenter() const {return m_mapCenter.value();}
194
199 [[nodiscard]] QBindable<QGeoCoordinate> bindableMapCenter() {return &m_mapCenter;}
200
205 void setMapCenter(const QGeoCoordinate& newMapCenter) {m_mapCenter = newMapCenter;}
206
211 [[nodiscard]] Positioning::PositionInfo positionInfo() const {return m_positionInfo.value();}
212
217 [[nodiscard]] QBindable<Positioning::PositionInfo> bindablePositionInfo() const {return &m_positionInfo;}
218
223 [[nodiscard]] Units::Distance pressureAltitude() const {return m_pressureAltitude.value();}
224
229 [[nodiscard]] QBindable<Units::Distance> bindablePressureAltitude() const {return &m_pressureAltitude;}
230
235 [[nodiscard]] bool receivingPositionInfo() const {return m_receivingPositionInfo.value();}
236
241 [[nodiscard]] QBindable<bool> bindableReceivingPositionInfo() {return &m_receivingPositionInfo;}
242
247 [[nodiscard]] QString statusString() const {return m_statusString.value();}
248
253 [[nodiscard]] QBindable<QString> bindableStatusString() const {return &m_statusString;}
254
255
256 //
257 // Methods
258 //
259
266 Q_INVOKABLE void startUpdates() { satelliteSource.startUpdates(); }
267
268signals:
269 // Notifier signal
270 void approximateLastValidCoordinateChanged();
271
272 // Notifier signal
273 void mapCenterChanged();
274
275 // Notifier signal
276 void positionInfoChanged(const Positioning::PositionInfo& info);
277
278 // Notifier signal
279 void receivingPositionInfoChanged(bool);
280
281private slots:
282 // Intializations that are moved out of the constructor, in order to avoid
283 // nested uses of constructors in Global.
284 void deferredInitialization();
285
286 // Saves last valid position and track
287 void savePositionAndTrack();
288
289private:
290 Q_DISABLE_COPY_MOVE(PositionProvider)
291
292 // Computation method for property with the same name
293 QString computeStatusString();
294
295 // Aircraft is considered flying if speed is at least this high
296 static constexpr double minFlightSpeedInKT = 30.0;
297 // Hysteresis for flight speed
298 static constexpr double flightSpeedHysteresis = 5.0;
299
300 // Coordinates of EDTF airfield
301 static constexpr double EDTF_lat = 48.022653;
302 static constexpr double EDTF_lon = 7.832583;
303 static constexpr double EDTF_ele = 244;
304
305 PositionInfoSource_Satellite satelliteSource;
306
307 // The incoming position info is set by a binding that monitors
308 // the satelliteSource and the TrafficDataSource
309 QProperty<Positioning::PositionInfo> m_incomingPositionInfo;
310 Positioning::PositionInfo computeIncomingPositionInfo();
311
312 // This method updates m_approximateLastValidCoordinate, m_lastValidCoordinate and m_lastValidTT
313 // whenever m_incomingPositionInfo changes.
314 void onIncomingPositionInfoUpdated();
315 QPropertyNotifier m_incomingPositionInfoNotifier;
316
317 Q_OBJECT_BINDABLE_PROPERTY(Positioning::PositionProvider, Positioning::PositionInfo, m_positionInfo, &Positioning::PositionProvider::positionInfoChanged);
318 Q_OBJECT_BINDABLE_PROPERTY(Positioning::PositionProvider, QGeoCoordinate, m_approximateLastValidCoordinate, &Positioning::PositionProvider::approximateLastValidCoordinateChanged);
319 QProperty<QGeoCoordinate> m_lastValidCoordinate {QGeoCoordinate(EDTF_lat, EDTF_lon, EDTF_ele)};
320 QProperty<Units::Angle> m_lastValidTT;
321 Q_OBJECT_BINDABLE_PROPERTY(Positioning::PositionProvider, QGeoCoordinate, m_mapCenter, &Positioning::PositionProvider::mapCenterChanged);
322
323 Q_OBJECT_BINDABLE_PROPERTY(Positioning::PositionProvider, bool, m_receivingPositionInfo, &Positioning::PositionProvider::receivingPositionInfoChanged);
324 QProperty<QString> m_statusString;
325
326 QProperty<Units::Distance> m_pressureAltitude;
327 Units::Distance computePressureAltitude();
328};
329
330} // 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.
QBindable< QGeoCoordinate > bindableMapCenter()
Getter function for the property with the same name.
Units::Distance pressureAltitude() const
Getter method for property with the same name.
QGeoCoordinate mapCenter() const
Getter function for the 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 mapCenter
Map center coordinate.
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
void setMapCenter(const QGeoCoordinate &newMapCenter)
Setter function for the property with the same name.
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