Enroute Flight Navigation
A navigation app for VFR pilots
Traffic::TrafficFactor_Abstract Class Reference

Abstract base class for traffic factors. More...

#include <TrafficFactor_Abstract.h>

Inheritance diagram for Traffic::TrafficFactor_Abstract:
Traffic::TrafficFactor_DistanceOnly Traffic::TrafficFactor_WithPosition

Public Types

enum  Type : quint8 {
  unknown , Aircraft , Airship , Balloon ,
  Copter , Drone , Glider , HangGlider ,
  Jet , Paraglider , Skydiver , StaticObstacle ,
  TowPlane
}
 Aircraft type. More...

Public Member Functions

 TrafficFactor_Abstract (QObject *parent=nullptr)
 Default constructor.
bool hasHigherPriorityThan (const TrafficFactor_Abstract &rhs) const
 Estimates if this traffic object has higher priority than other traffic object.
void startLifetime ()
 Starts or extends the lifetime of this object.
int alarmLevel () const
 Getter method for property with the same name.
QBindable< int > bindableAlarmLevel ()
 Getter method for property with the same name.
bool animate () const
 Getter method for property with the same name.
QBindable< bool > bindableAnimate ()
 Getter method for property with the same name.
QString callSign () const
 Getter method for property with the same name.
QBindable< QString > bindableCallSign () const
 Getter method for property with the same name.
QString color () const
 Getter method for property with the same name.
QBindable< QString > bindableColor () const
 Getter method for property with the same name.
QString description () const
 Getter method for property with the same name.
QBindable< QString > bindableDescription () const
 Getter method for property with the same name.
Units::Distance hDist () const
 Getter method for property with the same name.
QBindable< Units::DistancebindableHDist ()
 Getter method for property with the same name.
QString ID () const
 Getter method for property with the same name.
QBindable< QString > bindableID () const
 Getter method for property with the same name.
bool relevant () const
 Getter method for property with the same name.
QBindable< bool > bindableRelevant ()
 Getter method for property with the same name.
QString relevantString () const
 Getter method for property with the same name.
QBindable< QString > bindableRelevantString ()
 Getter method for property with the same name.
TrafficFactor_Abstract::Type type () const
 Getter method for property with the same name.
QBindable< TrafficFactor_Abstract::TypebindableType ()
 Getter method for property with the same name.
QString typeString () const
 Getter method for property with the same name.
QBindable< QString > bindableTypeString ()
 Getter method for property with the same name.
bool valid () const
 Getter method for property with the same name.
QBindable< bool > bindableValid ()
 Getter method for property with the same name.
Units::Distance vDist () const
 Getter method for property with the same name.
QBindable< Units::DistancebindableVDist ()
 Getter method for property with the same name.
void setAlarmLevel (int newAlarmLevel)
 Setter function for property with the same name.
void setCallSign (const QString &newCallSign)
 Setter function for property with the same name.
void setHDist (Units::Distance newHDist)
 Setter function for property with the same name.
void setID (const QString &newID)
 Setter function for property with the same name.
void setType (TrafficFactor_Abstract::Type newType)
 Setter function for property with the same name.
void setVDist (Units::Distance newVDist)
 Setter function for property with the same name.

Static Public Member Functions

static bool isRelevant (Units::Distance hDist, Units::Distance vDist)
 Relevance criterion shared by the "relevant" property and priority logic.

Static Public Attributes

static constexpr auto lifetime = 45s
 Length of lifetime for objects of this class.
static constexpr Units::Distance maxVerticalDistance = Units::Distance::fromM(1500.0)
 Maximal vertical distance for relevant traffic.
static constexpr Units::Distance maxHorizontalDistance = Units::Distance::fromNM(20.0)
 Maximal horizontal distance for relevant traffic.

Protected Member Functions

void updateFrom (const TrafficFactorData &data)
 Update this object with newer data for the same traffic factor.
void replaceBy (const TrafficFactorData &data)
 Replace this object by a different traffic factor.
bool isSameFactorAs (const TrafficFactorData &data) const
 Check whether a data record refers to the same factor as *this.

Static Protected Attributes

static constexpr qsizetype idMatchLength = 6
 Number of characters in ICAO HEX IDs.

Properties

int alarmLevel
 Alarm Level.
bool animate
 Indicates if changes in properties should be animated in the GUI.
QString callSign
 Call sign.
QString color
 Suggested color for GUI representation of the traffic.
QString description
 Description of the traffic, for use in GUI.
Units::Distance hDist
 Horizontal distance from own position to the traffic, at the time of report.
QString ID
 Identifier string of the traffic.
bool relevant
 Indicates relevant traffic.
QString relevantString
 Translated string containing the 'relevant' property.
Type type
 Type of aircraft, as reported by the traffic receiver.
QString typeString
 Type of aircraft, as reported by the traffic receiver.
bool valid
 Validity.
Units::Distance vDist
 Vertical distance from own position to the traffic, at the time of report.

Detailed Description

Abstract base class for traffic factors.

This is an abstract base class for traffic factors, as reported by traffic data receivers (e.g. FLARM devices).

Since the real-world traffic situation changes continuously, instances of this class have a limited lifetime. The length of the lifetime is specified in the constant "lifetime". You can (re)start an object's lifetime startLifetime(). Once the lifetime of an object is expired, the property "valid" will always be false, regardless of the object's other properties.

Classes that inherit from TrafficFactor_Abstract need to provide a binding for the properties 'description' and 'valid'.

Definition at line 51 of file TrafficFactor_Abstract.h.

Member Enumeration Documentation

◆ Type

Aircraft type.

This enum defines a few aircraft types. The list is modeled after the FLARM/NMEA specification.

Enumerator
unknown 

Unknown aircraft type

Aircraft 

Fixed wing aircraft

Airship 

Airship, such as a zeppelin or a blimp

Balloon 

Balloon

Copter 

Helicopter, gyrocopter or rotorcraft

Drone 

Drone

Glider 

Glider, including powered gliders and touring motor gliders

HangGlider 

Hang glider

Jet 

Jet aircraft

Paraglider 

Paraglider

Skydiver 

Skydiver

StaticObstacle 

Static obstacle

TowPlane 

Tow plane

Definition at line 61 of file TrafficFactor_Abstract.h.

Constructor & Destructor Documentation

◆ TrafficFactor_Abstract()

Traffic::TrafficFactor_Abstract::TrafficFactor_Abstract ( QObject * parent = nullptr)
explicit

Default constructor.

Parameters
parentThe standard QObject parent pointer

Member Function Documentation

◆ alarmLevel()

int Traffic::TrafficFactor_Abstract::alarmLevel ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property alarmLevel

Definition at line 262 of file TrafficFactor_Abstract.h.

◆ animate()

bool Traffic::TrafficFactor_Abstract::animate ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property animate

Definition at line 274 of file TrafficFactor_Abstract.h.

◆ bindableAlarmLevel()

QBindable< int > Traffic::TrafficFactor_Abstract::bindableAlarmLevel ( )
inlinenodiscard

Getter method for property with the same name.

Returns
Property alarmLevel

Definition at line 268 of file TrafficFactor_Abstract.h.

◆ bindableAnimate()

QBindable< bool > Traffic::TrafficFactor_Abstract::bindableAnimate ( )
inlinenodiscard

Getter method for property with the same name.

Returns
Property animate

Definition at line 280 of file TrafficFactor_Abstract.h.

◆ bindableCallSign()

QBindable< QString > Traffic::TrafficFactor_Abstract::bindableCallSign ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property callSign

Definition at line 292 of file TrafficFactor_Abstract.h.

◆ bindableColor()

QBindable< QString > Traffic::TrafficFactor_Abstract::bindableColor ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property color

Definition at line 304 of file TrafficFactor_Abstract.h.

◆ bindableDescription()

QBindable< QString > Traffic::TrafficFactor_Abstract::bindableDescription ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property description

Definition at line 316 of file TrafficFactor_Abstract.h.

◆ bindableHDist()

QBindable< Units::Distance > Traffic::TrafficFactor_Abstract::bindableHDist ( )
inlinenodiscard

Getter method for property with the same name.

Returns
Property hDist

Definition at line 328 of file TrafficFactor_Abstract.h.

◆ bindableID()

QBindable< QString > Traffic::TrafficFactor_Abstract::bindableID ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property ID

Definition at line 340 of file TrafficFactor_Abstract.h.

◆ bindableRelevant()

QBindable< bool > Traffic::TrafficFactor_Abstract::bindableRelevant ( )
inlinenodiscard

Getter method for property with the same name.

Returns
Property relevant

Definition at line 352 of file TrafficFactor_Abstract.h.

◆ bindableRelevantString()

QBindable< QString > Traffic::TrafficFactor_Abstract::bindableRelevantString ( )
inlinenodiscard

Getter method for property with the same name.

Returns
Property relevantString

Definition at line 364 of file TrafficFactor_Abstract.h.

◆ bindableType()

QBindable< TrafficFactor_Abstract::Type > Traffic::TrafficFactor_Abstract::bindableType ( )
inlinenodiscard

Getter method for property with the same name.

Returns
Property type

Definition at line 376 of file TrafficFactor_Abstract.h.

◆ bindableTypeString()

QBindable< QString > Traffic::TrafficFactor_Abstract::bindableTypeString ( )
inlinenodiscard

Getter method for property with the same name.

Returns
Property typeString

Definition at line 388 of file TrafficFactor_Abstract.h.

◆ bindableValid()

QBindable< bool > Traffic::TrafficFactor_Abstract::bindableValid ( )
inlinenodiscard

Getter method for property with the same name.

Returns
Property valid

Definition at line 400 of file TrafficFactor_Abstract.h.

◆ bindableVDist()

QBindable< Units::Distance > Traffic::TrafficFactor_Abstract::bindableVDist ( )
inlinenodiscard

Getter method for property with the same name.

Returns
Property vDist

Definition at line 412 of file TrafficFactor_Abstract.h.

◆ callSign()

QString Traffic::TrafficFactor_Abstract::callSign ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property callSign

Definition at line 286 of file TrafficFactor_Abstract.h.

◆ color()

QString Traffic::TrafficFactor_Abstract::color ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property color

Definition at line 298 of file TrafficFactor_Abstract.h.

◆ description()

QString Traffic::TrafficFactor_Abstract::description ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property description

Definition at line 310 of file TrafficFactor_Abstract.h.

◆ hasHigherPriorityThan()

bool Traffic::TrafficFactor_Abstract::hasHigherPriorityThan ( const TrafficFactor_Abstract & rhs) const
nodiscard

Estimates if this traffic object has higher priority than other traffic object.

The following criteria are applied in order.

  • Valid traffic objects have higher priority than invalid objects.
  • Traffic objects with higher alarm level have higher priority.
  • Relevant traffic objects have higher priority than irrelevant ones.
  • Traffic objects that are closer have higher priority.
Parameters
rhsRight hand side of the comparison
Returns
Boolean with the result

◆ hDist()

Units::Distance Traffic::TrafficFactor_Abstract::hDist ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property hDist

Definition at line 322 of file TrafficFactor_Abstract.h.

◆ ID()

QString Traffic::TrafficFactor_Abstract::ID ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property ID

Definition at line 334 of file TrafficFactor_Abstract.h.

◆ isRelevant()

bool Traffic::TrafficFactor_Abstract::isRelevant ( Units::Distance hDist,
Units::Distance vDist )
staticnodiscard

Relevance criterion shared by the "relevant" property and priority logic.

This helper holds the rule that decides whether traffic at the given distances is relevant, i.e. close enough to be worth showing. It is used both by the binding of the "relevant" property and by the free function hasHigherPriorityThan(const TrafficFactorData&, const TrafficFactor_Abstract&), so that both share a single definition.

Parameters
hDistHorizontal distance to the traffic
vDistVertical distance to the traffic
Returns
True if traffic at these distances is considered relevant

◆ isSameFactorAs()

bool Traffic::TrafficFactor_Abstract::isSameFactorAs ( const TrafficFactorData & data) const
nodiscardprotected

Check whether a data record refers to the same factor as *this.

Two records describe the same factor exactly if the last idMatchLength characters of their IDs agree. This is the single identity rule shared by the updateFrom() overloads of all subclasses.

Parameters
dataData record to compare against
Returns
True if data refers to the same factor as *this

◆ relevant()

bool Traffic::TrafficFactor_Abstract::relevant ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property relevant

Definition at line 346 of file TrafficFactor_Abstract.h.

◆ relevantString()

QString Traffic::TrafficFactor_Abstract::relevantString ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property relevant

Definition at line 358 of file TrafficFactor_Abstract.h.

◆ replaceBy()

void Traffic::TrafficFactor_Abstract::replaceBy ( const TrafficFactorData & data)
protected

Replace this object by a different traffic factor.

This method is for the case where this is repurposed to represent a *different traffic factor, namely the one described by data. All properties are overwritten unconditionally and the "animate" property is set to false, since animating a transition between two unrelated factors would be meaningless.

The lifetime of *this is (re)started, so the caller does not need to call startLifetime() separately.

Parameters
dataData record whose contents replace the data of *this

◆ setAlarmLevel()

void Traffic::TrafficFactor_Abstract::setAlarmLevel ( int newAlarmLevel)
inline

Setter function for property with the same name.

Parameters
newAlarmLevelProperty alarmLevel

Definition at line 423 of file TrafficFactor_Abstract.h.

◆ setCallSign()

void Traffic::TrafficFactor_Abstract::setCallSign ( const QString & newCallSign)
inline

Setter function for property with the same name.

Parameters
newCallSignProperty callSign

Definition at line 437 of file TrafficFactor_Abstract.h.

◆ setHDist()

void Traffic::TrafficFactor_Abstract::setHDist ( Units::Distance newHDist)
inline

Setter function for property with the same name.

Parameters
newHDistProperty hDist

Definition at line 443 of file TrafficFactor_Abstract.h.

◆ setID()

void Traffic::TrafficFactor_Abstract::setID ( const QString & newID)
inline

Setter function for property with the same name.

Parameters
newIDProperty ID

Definition at line 449 of file TrafficFactor_Abstract.h.

◆ setType()

void Traffic::TrafficFactor_Abstract::setType ( TrafficFactor_Abstract::Type newType)
inline

Setter function for property with the same name.

Parameters
newTypeProperty type

Definition at line 455 of file TrafficFactor_Abstract.h.

◆ setVDist()

void Traffic::TrafficFactor_Abstract::setVDist ( Units::Distance newVDist)
inline

Setter function for property with the same name.

Parameters
newVDistProperty vDist

Definition at line 461 of file TrafficFactor_Abstract.h.

◆ startLifetime()

void Traffic::TrafficFactor_Abstract::startLifetime ( )

Starts or extends the lifetime of this object.

Traffic information is volatile, and is considered valid only for "lifetime" seconds. This method starts or extends the object's lifetime.

◆ type()

TrafficFactor_Abstract::Type Traffic::TrafficFactor_Abstract::type ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property type

Definition at line 370 of file TrafficFactor_Abstract.h.

◆ typeString()

QString Traffic::TrafficFactor_Abstract::typeString ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property typeString

Definition at line 382 of file TrafficFactor_Abstract.h.

◆ updateFrom()

void Traffic::TrafficFactor_Abstract::updateFrom ( const TrafficFactorData & data)
protected

Update this object with newer data for the same traffic factor.

This method is for the case where data describes the same traffic factor as *this, observed again with (typically newer) data. The caller is responsible for establishing that the two refer to the same factor.

Identity data that is already established here is preserved, and the transition is animated:

  • the "animate" property of *this is set to true, so that the GUI animates the transition from the old to the new data;
  • the callsign in data is taken over only if the callsign of *this is still empty (an established callsign is never overwritten);
  • the type in data is taken over only if the type of *this is still unknown (an established type is never overwritten).

If there is nothing to continue from — *this is no longer valid, i.e. its track had expired — there is no established identity to preserve and no meaningful transition to animate. The call then degrades to replaceBy().

In all cases the lifetime of *this is (re)started, so the caller does not need to call startLifetime() separately.

Parameters
dataData record whose contents are used to update *this

◆ valid()

bool Traffic::TrafficFactor_Abstract::valid ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property valid

Definition at line 394 of file TrafficFactor_Abstract.h.

◆ vDist()

Units::Distance Traffic::TrafficFactor_Abstract::vDist ( ) const
inlinenodiscard

Getter method for property with the same name.

Returns
Property vDist

Definition at line 406 of file TrafficFactor_Abstract.h.

Member Data Documentation

◆ idMatchLength

qsizetype Traffic::TrafficFactor_Abstract::idMatchLength = 6
staticconstexprprotected

Number of characters in ICAO HEX IDs.

Number of trailing ID characters compared to decide whether two records describe the same factor: the last six hex digits are the ICAO/FLARM device-address suffix.

Definition at line 548 of file TrafficFactor_Abstract.h.

◆ maxHorizontalDistance

Units::Distance Traffic::TrafficFactor_Abstract::maxHorizontalDistance = Units::Distance::fromNM(20.0)
staticconstexpr

Maximal horizontal distance for relevant traffic.

Traffic whose horizontal distance to the own aircraft is larger than this number will be considered irrelevant.

Note
This threshold is currently not applied because isRelevant() is overridden for debugging.

Definition at line 489 of file TrafficFactor_Abstract.h.

◆ maxVerticalDistance

Units::Distance Traffic::TrafficFactor_Abstract::maxVerticalDistance = Units::Distance::fromM(1500.0)
staticconstexpr

Maximal vertical distance for relevant traffic.

Traffic whose vertical distance to the own aircraft is larger than this number will be considered irrelevant.

Note
This threshold is currently not applied because isRelevant() is overridden for debugging.

Definition at line 479 of file TrafficFactor_Abstract.h.

Property Documentation

◆ alarmLevel

int Traffic::TrafficFactor_Abstract::alarmLevel
readwrite

Alarm Level.

This is the alarm level associated with the traffic object. The alarm level is an integer in the range 0 (no alarm), …, 3 (maximal alarm). The values are not computed by this class, but reported by the traffic receiver that reports the traffic. The precise meaning depends on the type of traffic receiver used.

FLARM

  • 0 = no alarm (also used for no-alarm traffic information)
  • 1 = alarm, 13-18 seconds to impact
  • 2 = alarm, 9-12 seconds to impact
  • 3 = alarm, 0-8 seconds to impact

Other

  • 0 = no alarm
  • 1 = alarm

Definition at line 158 of file TrafficFactor_Abstract.h.

◆ animate

bool Traffic::TrafficFactor_Abstract::animate
read

Indicates if changes in properties should be animated in the GUI.

This boolen properts is used to indicate if changes in properties should be animated in the GUI. This property is typically set to "true" before gradual changes are applied, such as the position change of an aircraft. It is typically set to "false" before data of a new aircraft set.

Definition at line 167 of file TrafficFactor_Abstract.h.

◆ callSign

QString Traffic::TrafficFactor_Abstract::callSign
readwrite

Call sign.

If known, this property holds the call sign of the traffic. Otherwise, it contains an empty string

Definition at line 174 of file TrafficFactor_Abstract.h.

◆ color

QString Traffic::TrafficFactor_Abstract::color
read

Suggested color for GUI representation of the traffic.

This propery suggests a color, depending on the alarmLevel.

  • alarmLevel == 0: green
  • alarmLevel == 1: yellow
  • alarmLevel >= 2: red

Definition at line 184 of file TrafficFactor_Abstract.h.

◆ description

QString Traffic::TrafficFactor_Abstract::description
read

Description of the traffic, for use in GUI.

This method holds a human-readable, translated description of the traffic. This is a rich-text string of the form "Glider<br>+15 0m" or "Airship<br>Position unknown<br>-45 ft".

Definition at line 192 of file TrafficFactor_Abstract.h.

◆ hDist

Units::Distance Traffic::TrafficFactor_Abstract::hDist
readwrite

Horizontal distance from own position to the traffic, at the time of report.

If known, this property holds the horizontal distance from the own position to the traffic, at the time of report. Otherwise, it contains an invalid distance.

Definition at line 200 of file TrafficFactor_Abstract.h.

◆ ID

QString Traffic::TrafficFactor_Abstract::ID
readwrite

Identifier string of the traffic.

This property holds an identifier string for the traffic, as assigned by the FLARM device that reported the traffic. This can be the FLARM ID, or an empty string if no meaningful ID can be assigned.

Definition at line 208 of file TrafficFactor_Abstract.h.

◆ relevant

bool Traffic::TrafficFactor_Abstract::relevant
read

Indicates relevant traffic.

This property holds 'true' if the traffic is valid, and closer than maxVerticalDistance and maxHorizontalDistance specified below.

Note
For debugging, isRelevant() is currently overridden to return true for any valid traffic, so the distance thresholds below are temporarily ignored.

Definition at line 219 of file TrafficFactor_Abstract.h.

◆ relevantString

QString Traffic::TrafficFactor_Abstract::relevantString
read

Translated string containing the 'relevant' property.

The content of the string is a translated version of "Relevant Traffic" or "Irrelevant Traffic".

Definition at line 226 of file TrafficFactor_Abstract.h.

◆ typeString

QString Traffic::TrafficFactor_Abstract::typeString
read

Type of aircraft, as reported by the traffic receiver.

This property holds a translated, human-readable string.

Definition at line 235 of file TrafficFactor_Abstract.h.

◆ valid

bool Traffic::TrafficFactor_Abstract::valid
read

Validity.

A traffic object is considered valid if the data is meaningful and if the lifetime is not expired. Only valid traffic objects should be shown in the GUI.

Definition at line 243 of file TrafficFactor_Abstract.h.

◆ vDist

Units::Distance Traffic::TrafficFactor_Abstract::vDist
readwrite

Vertical distance from own position to the traffic, at the time of report.

If known, this property holds the vertical distance from the own position to the traffic, at the time of report. Otherwise, it contains NaN.

Definition at line 251 of file TrafficFactor_Abstract.h.


The documentation for this class was generated from the following file: