6 #include <QRegularExpression>
7 #include <QRegularExpressionMatch>
18 namespace swift::misc::aviation
21 : m_callsignAsSet(callsign.trimmed()), m_callsign(
CCallsign::unifyCallsign(callsign, hint)), m_typeHint(hint)
25 : m_callsignAsSet(callsign.trimmed()), m_callsign(
CCallsign::unifyCallsign(callsign, hint)),
26 m_telephonyDesignator(telephonyDesignator.trimmed()), m_typeHint(hint)
30 : m_callsignAsSet(callsign), m_callsign(
CCallsign::unifyCallsign(callsign, hint)), m_typeHint(hint)
36 qRegisterMetaType<CCallsign::TypeHint>();
61 if (
QStringView(u
"VATGOV") == suffix) {
return 13; }
62 if (
QStringView(u
"VATSIM") == suffix) {
return 14; }
64 return std::numeric_limits<int>::max();
113 if (!log) {
return; }
114 if (message.
isEmpty()) {
return; }
142 if (!this->
hasSuffix()) {
return false; }
148 if (this->
getTypeHint() == Aircraft) {
return false; }
154 return m_callsignAsSet ==
"*" || m_callsign ==
"*" || m_callsignAsSet ==
"BROADCAST";
159 m_callsignAsSet =
"BROADCAST";
160 m_callsign =
"BROADCAST";
165 m_callsignAsSet =
"SUP";
173 m_callsign.
at(m_callsign.
size() - 1) >=
'A' && m_callsign.
at(m_callsign.
size() - 1) <=
'Z';
196 if (this->
getTypeHint() == Aircraft) {
return false; }
197 if (!this->
hasSuffix()) {
return false; }
205 if (this->
isEmpty()) {
return {}; }
236 flightNumber.
clear();
237 if (m_callsign.
length() < 3) {
return {}; }
242 if (!match.
hasMatch()) {
return {}; }
248 if (airline.
length() == 3)
250 flightIdentification = m_callsign.
length() > 3 ? m_callsign.
mid(3) :
QString();
255 flightIdentification = m_callsign.
length() > 4 ? m_callsign.
mid(4) :
QString();
260 if (flightNumber.
length() >= 1 && airline.
length() == 4)
262 flightIdentification = m_callsign.
mid(3);
263 return airline.
left(3);
307 return other == (*this);
335 case IndexCallsignStringAsSet: m_callsignAsSet = variant.
toString();
break;
336 case IndexTelephonyDesignator: m_telephonyDesignator = variant.
toString();
break;
348 case IndexCallsignStringAsSet:
350 case IndexTelephonyDesignator:
355 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Compare failed");
365 default:
return !this->
isEmpty();
371 if (callsign.
length() < 2 || callsign.
length() > 10) {
return false; }
383 if (callsign.
length() < 2 || callsign.
length() > 10) {
return false; }
391 static const QStringList a({
"APP",
"GND",
"DEP",
"TWR",
"DEL",
"CTR" });
397 static const QStringList a({
"ATIS",
"APP",
"GND",
"OBS",
"DEP",
"TWR",
"DEL",
"CTR",
"SUP",
"FSS",
"INS" });
403 if (!callsign.
contains(
"_")) {
return false; }
408 if (uc.
endsWith(r)) {
return true; }
Value object for icons. An icon is stored in the global icon repository and identified by its index....
static const CIcon & iconByIndex(CIcons::IconIndex index)
Icon for given index.
static const QString & aviation()
Aviation specific.
A sequence of log categories.
static CLogCategoryList fromQStringList(const QStringList &stringList)
Convert a string list, such as that returned by toQStringList(), into a CLogCategoryList.
Non-owning reference to a CPropertyIndex with a subset of its features.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
void push_back(const T &value)
Appends an element at the end of the sequence.
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
Value object encapsulating information of a callsign.
int getSuffixSortOrder() const
Sort order by suffix.
void clear()
Clear this callsign.
int comparePropertyByIndex(CPropertyIndexRef index, const CCallsign &compareValue) const
Compare for index.
const QString & asString() const
Get callsign (normalized)
bool isMaybeCopilotCallsign(const CCallsign &pilotCallsign) const
Returns true if this is a co-pilot callsign of pilot. The logic is that the callsign is the same as t...
static int suffixToSortOrder(const QString &suffix)
Index for ATC suffix, if unknown int max value.
QString getSuffix() const
Get the callsign suffix ("TWR", "ATIS" ...) if any ("_" is removed)
TypeHint
Representing what.
bool hasSuffix() const
Suffix such as "_TWR"?
void markAsBroadcastCallsign()
Set a human readable name as "broadcast" callsign.
QString convertToQString(bool i18n=false) const
Cast as QString.
int getFlightNumberInt() const
Flight number as integer.
QString getFlightIndentification() const
Flight number (e.g. DLH1234 -> 1234) if applicable.
static const QStringList & atcCallsignSuffixes()
List of real ATC suffixes (e.g. TWR);.
static bool looksLikeAtcCallsign(const QString &callsign)
Does this look like an ATC callsign.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
void markAsWallopCallsign()
Set a human readable name as "wallop-channel" callsign.
QString getFlightNumber() const
Flight number (e.g. DLH1234 -> 1234) if applicable.
bool isSupervisorCallsign() const
Supervisor?
static void addLogDetailsToList(CStatusMessageList *log, const CCallsign &callsign, const QString &message, const QStringList &extraCategories={}, CStatusMessage::StatusSeverity s=CStatusMessage::SeverityInfo)
Specialized log for matching / reverse lookup.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
bool isObserverCallsign() const
Observer callsign?
bool isAtcAlikeCallsign() const
ATC alike callsign.
static CStatusMessage logMessage(const CCallsign &callsign, const QString &message, const QStringList &extraCategories={}, CStatusMessage::StatusSeverity s=CStatusMessage::SeverityInfo)
Specialized log message for matching / reverse lookup.
static QString unifyCallsign(const QString &callsign, TypeHint hint=NoHint)
Unify the callsign by removing illegal characters.
bool isEmpty() const
Is empty?
static bool isValidAircraftCallsign(const QString &callsign)
Valid callsign?
const QString & getTelephonyDesignator() const
Get callsign telephony designator (how callsign is pronounced)
TypeHint getTypeHint() const
Type hint.
static const CIcon & convertToIcon(const CCallsign &callsign)
Representing icon.
QString getAsObserverCallsignString() const
Makes this callsign looking like an observer callsign (DAMBZ -> DAMBZ_OBS)
bool hasAtcSuffix() const
Has an ATC suffix?
CCallsign()
Default constructor.
QString getIcaoCode() const
Get ICAO code, if this makes sense (EDDF_TWR -> EDDF)
QString getAirlinePrefix() const
Airline suffix (e.g. DLH1234 -> DLH) if applicable.
static const CIcon & atcSuffixToIcon(const QString &suffix)
Suffix to icon.
bool isAtcCallsign() const
ATC callsign.
static void registerMetadata()
Register metadata.
QString getFsdCallsignString() const
The callsign string used with FSD.
bool isSameAsSet() const
Same as set callsign?
bool equalsString(const QString &callsignString) const
Equals callsign string?
bool isBroadcastCallsign() const
Pseudo callsing for broadcast messages.
const QString & getStringAsSet() const
Get callsign.
static bool isValidAtcCallsign(const QString &callsign)
Valid callsign?
bool isValid() const
Valid callsign?
static const QStringList & atcAlikeCallsignSuffixes()
List of real ("TWR") and treated like ATC suffixes (e.g. OBS);.
int comparePropertyByIndex(CPropertyIndexRef index, const Derived &compareValue) const
Compare for index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
QString toQString(bool i18n=false) const
Cast as QString.
QString removeChars(const QString &s, F predicate)
Return a string with characters removed that match the given predicate.
StatusSeverity
Status severities.
bool containsChar(const QString &s, F predicate)
True if any character in the string matches the given predicate.
bool isDigit(char32_t ucs4)
bool isLetterOrNumber(char32_t ucs4)
bool isUpper(char32_t ucs4)
QString captured(QAnyStringView name) const const
bool hasMatch() const const
QString & append(QChar ch)
const QChar at(qsizetype position) const const
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype lastIndexOf(QChar ch, Qt::CaseSensitivity cs) const const
QString left(qsizetype n) &&
qsizetype length() const const
QString mid(qsizetype position, qsizetype n) &&
QString section(QChar sep, qsizetype start, qsizetype end, QString::SectionFlags flags) const const
qsizetype size() const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
int toInt(bool *ok, int base) const const
QString toUpper() const const
QString trimmed() const const
bool contains(QLatin1StringView str, Qt::CaseSensitivity cs) const const
bool endsWith(QChar ch) const const
QVariant fromValue(T &&value)
QString toString() const const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.