refs #358, changes of MS' review

https://dev.vatsim-germany.org/issues/358#note-11
This commit is contained in:
Klaus Basan
2014-12-29 23:11:23 +01:00
parent 8fce90065d
commit 4f0bf6d62c
4 changed files with 52 additions and 28 deletions

View File

@@ -17,8 +17,9 @@ namespace BlackMisc
/*
* Convert to string
*/
QString CCallsign::convertToQString(bool /** i18n **/) const
QString CCallsign::convertToQString(bool i18n) const
{
Q_UNUSED(i18n);
return this->m_callsign;
}
@@ -37,19 +38,18 @@ namespace BlackMisc
*/
const CIcon &CCallsign::convertToIcon(const CCallsign &callsign)
{
QString t = callsign.asString().toUpper();
if (t.length() < 3) return CIconList::iconByIndex(CIcons::NetworkRoleUnknown);
t = t.right(3);
if (callsign.getStringAsSet().contains("_"))
if (callsign.hasSuffix())
{
if ("APP" == t) return CIconList::iconByIndex(CIcons::NetworkRoleApproach);
if ("GND" == t) return CIconList::iconByIndex(CIcons::NetworkRoleGround);
if ("TWR" == t) return CIconList::iconByIndex(CIcons::NetworkRoleTower);
if ("DEL" == t) return CIconList::iconByIndex(CIcons::NetworkRoleDelivery);
if ("CTR" == t) return CIconList::iconByIndex(CIcons::NetworkRoleCenter);
if ("SUP" == t) return CIconList::iconByIndex(CIcons::NetworkRoleSup);
if ("OBS" == t) return CIconList::iconByIndex(CIcons::NetworkRoleApproach);
QString t = callsign.getSuffix();
if (t.length() < 3) { return CIconList::iconByIndex(CIcons::NetworkRoleUnknown); }
if ("APP" == t) { return CIconList::iconByIndex(CIcons::NetworkRoleApproach); }
if ("GND" == t) { return CIconList::iconByIndex(CIcons::NetworkRoleGround); }
if ("TWR" == t) { return CIconList::iconByIndex(CIcons::NetworkRoleTower); }
if ("DEL" == t) { return CIconList::iconByIndex(CIcons::NetworkRoleDelivery); }
if ("CTR" == t) { return CIconList::iconByIndex(CIcons::NetworkRoleCenter); }
if ("SUP" == t) { return CIconList::iconByIndex(CIcons::NetworkRoleSup); }
if ("OBS" == t) { return CIconList::iconByIndex(CIcons::NetworkRoleApproach); }
if ("ATIS" == t) { return CIconList::iconByIndex(CIcons::AviationAtis); }
return CIconList::iconByIndex(CIcons::NetworkRoleUnknown);
}
else
@@ -63,13 +63,9 @@ namespace BlackMisc
*/
bool CCallsign::isAtcCallsign() const
{
if (this->m_callsignAsSet.contains('_'))
if (this->hasSuffix())
{
if (this->m_callsignAsSet.size() >= 3)
{
QString app = this->m_callsignAsSet.right(3);
return atcCallsignAppendixes().contains(app, Qt::CaseInsensitive);
}
return atcCallsignSuffixes().contains(this->getSuffix(), Qt::CaseInsensitive);
}
return false;
}
@@ -79,13 +75,34 @@ namespace BlackMisc
*/
QString CCallsign::getAsObserverCallsignString() const
{
if (this->isEmpty()) return "";
if (this->isEmpty()) { return ""; }
QString obs = this->getStringAsSet();
if (obs.endsWith("_OBS", Qt::CaseInsensitive)) return obs;
if (obs.contains('_')) obs = obs.left(obs.lastIndexOf('_'));
if (obs.endsWith("_OBS", Qt::CaseInsensitive)) { return obs; }
if (obs.contains('_')) { obs = obs.left(obs.lastIndexOf('_')); }
return obs.append("_OBS").toUpper();
}
/*
* Suffix
*/
QString CCallsign::getSuffix() const
{
QString s;
if (this->hasSuffix())
{
s = this->getStringAsSet().section('_', -1).toUpper();
}
return s;
}
/*
* Suffix?
*/
bool CCallsign::hasSuffix() const
{
return this->getStringAsSet().contains('_');
}
/*
* Equals callsign?
*/
@@ -153,11 +170,11 @@ namespace BlackMisc
}
/*
* Appendixes
* Suffixes
*/
const QStringList &CCallsign::atcCallsignAppendixes()
const QStringList &CCallsign::atcCallsignSuffixes()
{
static const QStringList a( { "APP", "GND", "TWR", "DEL", "CTR", "SUP", "FSS" });
static const QStringList a( { "ATIS", "APP", "GND", "TWR", "DEL", "CTR", "SUP", "FSS" });
return a;
}

View File

@@ -66,6 +66,12 @@ namespace BlackMisc
//! Makes this callsign looking like an observer callsign (DAMBZ -> DAMBZ_OBS)
QString getAsObserverCallsignString() const;
//! Get the callsign suffix ("TWR", "ATIS" ...) if any ("_" is removed)
QString getSuffix() const;
//! Suffix such as "_TWR"?
bool hasSuffix() const;
//! Equals callsign string?
bool equalsString(const QString &callsignString) const;
@@ -81,8 +87,8 @@ namespace BlackMisc
//! Valid callsign?
static bool isValidCallsign(const QString &callsign);
//! List of ATC appendixes (e.g. TWR);
static const QStringList &atcCallsignAppendixes();
//! List of ATC suffixes (e.g. TWR);
static const QStringList &atcCallsignSuffixes();
protected:
//! \copydoc CValueObject::convertToQString()

View File

@@ -96,6 +96,7 @@ namespace BlackMisc
//! Compare with index given by enum
template<class EnumType> bool equalsPropertyIndexEnum(EnumType ev)
{
static_assert(std::is_enum<EnumType>::value, "Argument must be an enum");
if (this->m_indexes.size() != 1) { return false; }
return static_cast<int>(ev) == m_indexes.first();
}

View File

@@ -31,7 +31,7 @@ namespace BlackSim
//! Thereafter all existing models and mappings can be obtained from here.
//! \sa CAircraftCfgEntries
//! \sa CAircraftCfgEntriesList
class CAircraftMapper : QObject
class CAircraftMapper : public QObject
{
Q_OBJECT