Enroute Flight Navigation
A navigation app for VFR pilots
PositionInfo.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 <QGeoPositionInfo>
24#include <QQmlEngine>
25//#include <chrono>
26
27#include "units/Angle.h"
28#include "units/Distance.h"
29#include "units/Speed.h"
30
31using namespace std::chrono_literals;
32
33
34namespace Positioning {
35
43
45{
46 Q_GADGET
47 QML_VALUE_TYPE(positionInfo)
48
49public:
51 PositionInfo() = default;
52
59 explicit PositionInfo(const QGeoPositionInfo& info, const QString& source);
60
68 [[nodiscard]] Q_INVOKABLE QGeoCoordinate coordinate() const
69 {
70 return m_positionInfo.coordinate();
71 }
72
77 [[nodiscard]] Q_INVOKABLE Units::Speed groundSpeed() const;
78
84 [[nodiscard]] Q_INVOKABLE bool isValid() const;
85
90 [[nodiscard]] Q_INVOKABLE Units::Distance positionErrorEstimate() const;
91
96 [[nodiscard]] Q_INVOKABLE QString source() const {return m_source;}
97
103 [[nodiscard]] Q_INVOKABLE Units::Distance terrainElevationAMSL();
104
109 [[nodiscard]] Q_INVOKABLE QDateTime timestamp() const
110 {
111 return m_positionInfo.timestamp().toUTC();
112 }
113
118 [[nodiscard]] Q_INVOKABLE QString timestampString() const
119 {
120 return m_positionInfo.timestamp().toUTC().time().toString(QStringLiteral("HH:mm:ss"))+ " UTC";
121 }
122
128 [[nodiscard]] Q_INVOKABLE Units::Distance trueAltitudeAGL();
129
135 [[nodiscard]] Q_INVOKABLE Units::Distance trueAltitudeAMSL() const;
136
141 [[nodiscard]] Q_INVOKABLE Units::Distance trueAltitudeErrorEstimate() const;
142
147 [[nodiscard]] Q_INVOKABLE Units::Angle trueTrack() const;
148
153 [[nodiscard]] Q_INVOKABLE Units::Angle trueTrackErrorEstimate() const;
154
159 [[nodiscard]] Q_INVOKABLE Units::Angle variation() const;
160
165 [[nodiscard]] Q_INVOKABLE Units::Speed verticalSpeed() const;
166
173 Q_INVOKABLE bool operator==(const Positioning::PositionInfo &rhs) const
174 {
175 return (m_positionInfo == rhs.m_positionInfo);
176 }
177
179 operator QGeoPositionInfo() const
180 {
181 return m_positionInfo;
182 }
183
189#if defined(Q_OS_ANDROID) or defined(Q_OS_IOS)
190 static constexpr auto lifetime = 20s;
191#else
192 static constexpr auto lifetime = 20min;
193#endif
194
195
196private:
197 QGeoPositionInfo m_positionInfo;
198 QString m_source;
199 Units::Distance m_terrainAMSL;
200 Units::Distance m_trueAltitudeAGL;
201};
202
203} // namespace Positioning
204
205Q_DECLARE_METATYPE(Positioning::PositionInfo)
Geographic position.
PositionInfo(const QGeoPositionInfo &info, const QString &source)
Constructor.
Q_INVOKABLE Units::Distance positionErrorEstimate() const
Position error estimate.
Q_INVOKABLE Units::Angle trueTrack() const
True track.
Q_INVOKABLE Units::Distance trueAltitudeErrorEstimate() const
True altitude error estimate.
static constexpr auto lifetime
Liftetime of geographic positioning information.
Q_INVOKABLE Units::Angle variation() const
Magnetic variation.
Q_INVOKABLE QString source() const
Name of source, as set in the constructor.
Q_INVOKABLE QGeoCoordinate coordinate() const
Coordinate.
Q_INVOKABLE bool operator==(const Positioning::PositionInfo &rhs) const
Comparison: equal.
Q_INVOKABLE bool isValid() const
Validity.
Q_INVOKABLE Units::Distance trueAltitudeAMSL() const
True Altitude above main sea level.
PositionInfo()=default
Default Constructor.
Q_INVOKABLE Units::Angle trueTrackErrorEstimate() const
True track error estimate.
Q_INVOKABLE QString timestampString() const
Timestamp string.
Q_INVOKABLE Units::Speed groundSpeed() const
Ground speed.
Q_INVOKABLE QDateTime timestamp() const
Timestamp.
Q_INVOKABLE Units::Speed verticalSpeed() const
Vertical speed.
Q_INVOKABLE Units::Distance terrainElevationAMSL()
Elevation of terrain at a given coordinate, above sea level.
Q_INVOKABLE Units::Distance trueAltitudeAGL()
True Altitude above ground level.
Convenience class for angle computations.
Definition Angle.h:41
Convenience class for distance computations.
Definition Distance.h:35
Convenience class for speed computations.
Definition Speed.h:36