Enroute Flight Navigation
A navigation app for VFR pilots
PositionProvider.h
1/***************************************************************************
2 * Copyright (C) 2019-2023 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
120
127 Q_PROPERTY(QString statusString READ statusString BINDABLE bindableStatusString)
128
129
130 //
131 // Getter Methods
132 //
133
138 [[nodiscard]] QGeoCoordinate approximateLastValidCoordinate() const {return m_approximateLastValidCoordinate.value();}
139
144 [[nodiscard]] QBindable<QGeoCoordinate> bindableApproximateLastValidCoordinate() const {return &m_approximateLastValidCoordinate;}
145
150 [[nodiscard]] static QGeoCoordinate lastValidCoordinate();
151
156 [[nodiscard]] QBindable<QGeoCoordinate> bindableLastValidCoordinate() {return &m_lastValidCoordinate;}
157
162 [[nodiscard]] static Units::Angle lastValidTT();
163
168 [[nodiscard]] QBindable<Units::Angle> bindableLastValidTT() {return &m_lastValidTT;}
169
174 [[nodiscard]] Positioning::PositionInfo positionInfo() const {return m_positionInfo.value();}
175
180 [[nodiscard]] QBindable<Positioning::PositionInfo> bindablePositionInfo() const {return &m_positionInfo;}
181
186 [[nodiscard]] bool receivingPositionInfo() const {return m_receivingPositionInfo.value();}
187
192 [[nodiscard]] QBindable<bool> bindableReceivingPositionInfo() {return &m_receivingPositionInfo;}
193
198 [[nodiscard]] QString statusString() const
199 {
200 return m_statusString.value();
201 }
202
207 [[nodiscard]] QBindable<QString> bindableStatusString() const
208 {
209 return &m_statusString;
210 }
211
212
213
214 //
215 // Methods
216 //
217
224 Q_INVOKABLE void startUpdates() { satelliteSource.startUpdates(); }
225
226signals:
227 // Notifier signal
228 void approximateLastValidCoordinateChanged();
229
230 // Notifier signal
231 void positionInfoChanged();
232
233 // Notifier signal
234 void receivingPositionInfoChanged(bool);
235
236private slots:
237 // Intializations that are moved out of the constructor, in order to avoid
238 // nested uses of constructors in Global.
239 void deferredInitialization();
240
241 // Saves last valid position and track
242 void savePositionAndTrack();
243
244private:
245 Q_DISABLE_COPY_MOVE(PositionProvider)
246
247 // Computation method for property with the same name
248 QString computeStatusString();
249
250 // Aircraft is considered flying if speed is at least this high
251 static constexpr double minFlightSpeedInKT = 30.0;
252 // Hysteresis for flight speed
253 static constexpr double flightSpeedHysteresis = 5.0;
254
255 // Coordinates of EDTF airfield
256 static constexpr double EDTF_lat = 48.022653;
257 static constexpr double EDTF_lon = 7.832583;
258 static constexpr double EDTF_ele = 244;
259
260 PositionInfoSource_Satellite satelliteSource;
261
262 // The incoming position info is set by a binding that monitors
263 // the satelliteSource and the TrafficDataSource
264 QProperty<Positioning::PositionInfo> m_incomingPositionInfo;
265 Positioning::PositionInfo computeIncomingPositionInfo();
266
267 // This method updates m_approximateLastValidCoordinate, m_lastValidCoordinate and m_lastValidTT
268 // whenever m_incomingPositionInfo changes.
269 void onIncomingPositionInfoUpdated();
270 QPropertyNotifier m_incomingPositionInfoNotifier;
271
272 Q_OBJECT_BINDABLE_PROPERTY(Positioning::PositionProvider, Positioning::PositionInfo, m_positionInfo, &Positioning::PositionProvider::positionInfoChanged);
273 Q_OBJECT_BINDABLE_PROPERTY(Positioning::PositionProvider, QGeoCoordinate, m_approximateLastValidCoordinate, &Positioning::PositionProvider::approximateLastValidCoordinateChanged);
274 QProperty<QGeoCoordinate> m_lastValidCoordinate {QGeoCoordinate(EDTF_lat, EDTF_lon, EDTF_ele)};
275 QProperty<Units::Angle> m_lastValidTT;
276
277 Q_OBJECT_BINDABLE_PROPERTY(Positioning::PositionProvider, bool, m_receivingPositionInfo, &Positioning::PositionProvider::receivingPositionInfoChanged);
278 QProperty<QString> m_statusString;
279
280};
281
282} // 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.
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< 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< 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
Conversion between units used in aviation.
Definition Angle.h:34