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
85 [[nodiscard]] bool updateFrom(const TrafficFactorData_WithPosition& data)
86 {
87 // Decline records that belong to a different factor.
88 if (!isSameFactorAs(data.data))
89 {
90 return false;
91 }
92
93 // Same factor: adopt the record if it is newer than what we already
94 // hold.
95 if (positionInfo().timestamp() < data.positionInfo.timestamp())
96 {
97 const QScopedPropertyUpdateGroup updateGroup;
100 }
101 return true;
102 }
103
114 {
115 const QScopedPropertyUpdateGroup updateGroup;
116 // Order matters here. The deferred change notifications fire in the order
117 // the properties are written, and the GUI gates its position/heading
118 // animations on "animate". Update the scalar fields first, because
119 // TrafficFactor_Abstract::replaceBy() sets animate=false: that disables
120 // the animation gate before the positionInfo change (which alone drives
121 // the extrapolated coordinate) is processed. Writing positionInfo first
122 // would let QML animate the coordinate jump while "animate" is still
123 // stale (true), gliding the icon across the map instead of snapping.
126 }
127
128
129 //
130 // PROPERTIES
131 //
132
144
145
149 [[nodiscard]] QGeoCoordinate extrapolatedCoordinate() const {return m_extrapolatedCoordinate.value();}
150
155 [[nodiscard]] QBindable<QGeoCoordinate> bindableExtrapolatedCoordinate() const {return &m_extrapolatedCoordinate;}
156
168
169
173 [[nodiscard]] Units::Angle extrapolatedTrueTrack() const {return m_extrapolatedTrueTrack.value();}
174
179 [[nodiscard]] QBindable<Units::Angle> bindableExtrapolatedTrueTrack() const {return &m_extrapolatedTrueTrack;}
180
186 Q_PROPERTY(QString icon READ icon BINDABLE bindableIcon)
187
188
192 [[nodiscard]] QString icon() const {return m_icon.value();}
193
198 [[nodiscard]] QBindable<QString> bindableIcon() const {return &m_icon;}
199
202
203
207 [[nodiscard]] Positioning::PositionInfo positionInfo() const {return m_positionInfo.value();}
208
213 [[nodiscard]] QBindable<Positioning::PositionInfo> bindablePositionInfo() const {return &m_positionInfo;}
214
222 void setPositionInfo(const Positioning::PositionInfo& newPositionInfo) {m_positionInfo = newPositionInfo;}
223
234
235
239 [[nodiscard]] Units::Distance uncertaintyRadius() const {return m_uncertaintyRadius.value();}
240
245 [[nodiscard]] QBindable<Units::Distance> bindableUncertaintyRadius() const {return &m_uncertaintyRadius;}
246
247signals:
250
251public slots:
258
259private:
260 Q_DISABLE_COPY_MOVE(TrafficFactor_WithPosition)
261
262 //
263 // Property values
264 //
265 QProperty<QGeoCoordinate> m_extrapolatedCoordinate;
266 QProperty<Units::Angle> m_extrapolatedTrueTrack;
267 QProperty<Units::Distance> m_uncertaintyRadius;
268 QProperty<QString> m_icon;
270};
271
272} // 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.