Enroute Flight Navigation
A navigation app for VFR pilots
TrafficFactor_WithPosition.h
1/***************************************************************************
2 * Copyright (C) 2021-2026 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 "positioning/PositionInfo.h"
24#include "traffic/TrafficFactor_Abstract.h"
25#include "traffic/TrafficFactorData.h"
26
27
28namespace Traffic {
29
30
39
41 Q_OBJECT
42 QML_ELEMENT
43
44public:
49 explicit TrafficFactor_WithPosition(QObject *parent = nullptr);
50
51 // Standard destructor
53
54 //
55 // Methods
56 //
57
87 [[nodiscard]] bool updateFrom(const TrafficFactorData_WithPosition& data)
88 {
89 // Decline records that belong to a different factor.
90 if (!isSameFactorAs(data.data))
91 {
92 return false;
93 }
94
95 // Same factor: adopt the record if it is newer than what we already
96 // hold. An expired slot holds nothing worth keeping, so it takes the
97 // record regardless of its timestamp: records are stamped with the
98 // system clock at receipt, and a clock step backwards would otherwise
99 // keep the slot frozen until the clock has caught up.
100 if (!valid() || (positionInfo().timestamp() < data.positionInfo.timestamp()))
101 {
102 const QScopedPropertyUpdateGroup updateGroup;
105 }
106 return true;
107 }
108
119 {
120 const QScopedPropertyUpdateGroup updateGroup;
121 // Order matters here. The deferred change notifications fire in the order
122 // the properties are written, and the GUI gates its position/heading
123 // animations on "animate". Update the scalar fields first, because
124 // TrafficFactor_Abstract::replaceBy() sets animate=false: that disables
125 // the animation gate before the positionInfo change (which alone drives
126 // the extrapolated coordinate) is processed. Writing positionInfo first
127 // would let QML animate the coordinate jump while "animate" is still
128 // stale (true), gliding the icon across the map instead of snapping.
131 }
132
133
134 //
135 // PROPERTIES
136 //
137
149
150
154 [[nodiscard]] QGeoCoordinate extrapolatedCoordinate() const {return m_extrapolatedCoordinate.value();}
155
160 [[nodiscard]] QBindable<QGeoCoordinate> bindableExtrapolatedCoordinate() const {return &m_extrapolatedCoordinate;}
161
173
174
178 [[nodiscard]] Units::Angle extrapolatedTrueTrack() const {return m_extrapolatedTrueTrack.value();}
179
184 [[nodiscard]] QBindable<Units::Angle> bindableExtrapolatedTrueTrack() const {return &m_extrapolatedTrueTrack;}
185
191 Q_PROPERTY(QString icon READ icon BINDABLE bindableIcon)
192
193
197 [[nodiscard]] QString icon() const {return m_icon.value();}
198
203 [[nodiscard]] QBindable<QString> bindableIcon() const {return &m_icon;}
204
207
208
212 [[nodiscard]] Positioning::PositionInfo positionInfo() const {return m_positionInfo.value();}
213
218 [[nodiscard]] QBindable<Positioning::PositionInfo> bindablePositionInfo() const {return &m_positionInfo;}
219
227 void setPositionInfo(const Positioning::PositionInfo& newPositionInfo) {m_positionInfo = newPositionInfo;}
228
239
240
244 [[nodiscard]] Units::Distance uncertaintyRadius() const {return m_uncertaintyRadius.value();}
245
250 [[nodiscard]] QBindable<Units::Distance> bindableUncertaintyRadius() const {return &m_uncertaintyRadius;}
251
252signals:
255
256public slots:
263
264private:
265 Q_DISABLE_COPY_MOVE(TrafficFactor_WithPosition)
266
267 //
268 // Property values
269 //
270 QProperty<QGeoCoordinate> m_extrapolatedCoordinate;
271 QProperty<Units::Angle> m_extrapolatedTrueTrack;
272 QProperty<Units::Distance> m_uncertaintyRadius;
273 QProperty<QString> m_icon;
275};
276
277} // namespace Traffic
Geographic position.
Q_INVOKABLE QDateTime timestamp() const
Timestamp.
bool isSameFactorAs(const TrafficFactorData &data) const
Check whether a data record refers to the same factor as *this.
void replaceBy(const TrafficFactorData &data)
Replace this object by a different traffic factor.
TrafficFactor_Abstract(QObject *parent=nullptr)
Default constructor.
void updateFrom(const TrafficFactorData &data)
Update this object with newer data for the same traffic factor.
Traffic factor whose precise position is known.
bool updateFrom(const TrafficFactorData_WithPosition &data)
Offer a data record to this object, for the same traffic factor.
QGeoCoordinate extrapolatedCoordinate
Extrapolated Coordinate.
QBindable< Units::Distance > bindableUncertaintyRadius() const
Getter method for property with the same name.
QBindable< Positioning::PositionInfo > bindablePositionInfo() const
Getter method for property with the same name.
QGeoCoordinate extrapolatedCoordinate() const
Getter method for property with the same name.
void positionInfoChanged()
Notifier signal.
QBindable< QString > bindableIcon() const
Getter method for property with the same name.
Units::Distance uncertaintyRadius() const
Getter method for property with the same name.
Positioning::PositionInfo positionInfo
PositionInfo of the traffic.
void setPositionInfo(const Positioning::PositionInfo &newPositionInfo)
Setter function for property with the same name.
QString icon() const
Getter method for property with the same name.
QBindable< QGeoCoordinate > bindableExtrapolatedCoordinate() const
Getter method for property with the same name.
QBindable< Units::Angle > bindableExtrapolatedTrueTrack() const
Getter method for property with the same name.
void updateExtrapolatedData()
Update extrapolated data.
TrafficFactor_WithPosition(QObject *parent=nullptr)
Default constructor.
Positioning::PositionInfo positionInfo() const
Getter method for property with the same name.
Units::Angle extrapolatedTrueTrack() const
Getter method for property with the same name.
void replaceBy(const TrafficFactorData_WithPosition &data)
Replace this object by a different traffic factor.
Units::Distance uncertaintyRadius
Uncertainty radius.
Units::Angle extrapolatedTrueTrack
Extrapolated True Track.
Convenience class for angle computations.
Definition Angle.h:41
Convenience class for distance computations.
Definition Distance.h:35
Plain-data record of a traffic factor whose precise position is known.
TrafficFactorData data
Position-independent data.
Positioning::PositionInfo positionInfo
PositionInfo of the traffic.