mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 08:45:36 +08:00
refs #614, formatting and new functions for list/value objects
* find by aircraft family * name completer sorting
This commit is contained in:
@@ -149,6 +149,31 @@ namespace BlackMisc
|
||||
return c;
|
||||
}
|
||||
|
||||
bool CAircraftIcaoCode::matchesCombinedCode(const QString &combinedCode) const
|
||||
{
|
||||
const QString cc(combinedCode.toUpper().trimmed().replace(' ', '*').replace('-', '*'));
|
||||
if (combinedCode.length() != 3) { return false; }
|
||||
if (cc == this->getCombinedType()) { return true; }
|
||||
|
||||
const bool wildcard = cc.contains('*');
|
||||
if (!wildcard) { return false; }
|
||||
QChar at = cc.at(0);
|
||||
QChar c = cc.at(1);
|
||||
QChar et = cc.at(2);
|
||||
if (at != '*')
|
||||
{
|
||||
const QString cat = getAircraftType();
|
||||
if (cat.isEmpty() || cat.at(0) != at) { return false; }
|
||||
}
|
||||
if (c != '*')
|
||||
{
|
||||
if (getEngineCount() != c.digitValue()) { return false; }
|
||||
}
|
||||
if (et == '*') { return true; }
|
||||
const QString cet = getEngineType();
|
||||
return cet.length() == 1 && cet.at(0) == et;
|
||||
}
|
||||
|
||||
QString CAircraftIcaoCode::getDesignatorManufacturer() const
|
||||
{
|
||||
QString d(getDesignator());
|
||||
|
||||
@@ -128,6 +128,10 @@ namespace BlackMisc
|
||||
//! Get model description, e.g. "A-330-200"
|
||||
const QString &getModelDescription() const { return m_modelDescription; }
|
||||
|
||||
//! Matches given combined code
|
||||
//! \remark * can be used as wildcard, e.g. L*J, L**
|
||||
bool matchesCombinedCode(const QString &combinedCode) const;
|
||||
|
||||
//! Designator + Manufacturer
|
||||
QString getDesignatorManufacturer() const;
|
||||
|
||||
|
||||
@@ -96,21 +96,42 @@ namespace BlackMisc
|
||||
this->sortBy(&CAircraftIcaoCode::getRank);
|
||||
}
|
||||
|
||||
QStringList CAircraftIcaoCodeList::toCompleterStrings(bool withIataCodes, bool withFamily) const
|
||||
void CAircraftIcaoCodeList::sortByDesignatorAndRank()
|
||||
{
|
||||
this->sortBy(&CAircraftIcaoCode::getDesignator, &CAircraftIcaoCode::getRank);
|
||||
}
|
||||
|
||||
QStringList CAircraftIcaoCodeList::toCompleterStrings(bool withIataCodes, bool withFamily, bool sort) const
|
||||
{
|
||||
QStringList c;
|
||||
for (const CAircraftIcaoCode &icao : *this)
|
||||
CAircraftIcaoCodeList icaos(*this);
|
||||
if (sort) { icaos.sortByDesignatorAndRank(); }
|
||||
|
||||
// 3 steps to get a proper sort order
|
||||
for (const CAircraftIcaoCode &icao : as_const(icaos))
|
||||
{
|
||||
c.append(icao.getCombinedIcaoStringWithKey());
|
||||
if (withIataCodes && icao.hasIataCode() && !icao.isIataSameAsDesignator())
|
||||
{
|
||||
c.append(icao.getCombinedIataStringWithKey());
|
||||
}
|
||||
if (withFamily && icao.hasFamily() && !icao.isFamilySameAsDesignator())
|
||||
}
|
||||
|
||||
if (withFamily)
|
||||
{
|
||||
icaos = this->findWithFamily(true);
|
||||
for (const CAircraftIcaoCode &icao : as_const(icaos))
|
||||
{
|
||||
c.append(icao.getCombinedFamilyStringWithKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (withIataCodes)
|
||||
{
|
||||
icaos = icaos.findWithIataCode(true);
|
||||
if (sort) { icaos.sortBy(&CAircraftIcaoCode::getIataCode, &CAircraftIcaoCode::getRank); }
|
||||
for (const CAircraftIcaoCode &icao : as_const(icaos))
|
||||
{
|
||||
c.append(icao.getCombinedIataStringWithKey());
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace BlackMisc
|
||||
void sortByRank();
|
||||
|
||||
//! For selection completion
|
||||
QStringList toCompleterStrings(bool withIataCodes = false, bool withFamily = false) const;
|
||||
QStringList toCompleterStrings(bool withIataCodes = false, bool withFamily = false, bool sort = true) const;
|
||||
|
||||
//! All ICAO codes, no duplicates
|
||||
QStringList allIcaoCodes(bool noUnspecified = true) const;
|
||||
|
||||
@@ -123,20 +123,30 @@ namespace BlackMisc
|
||||
return codes;
|
||||
}
|
||||
|
||||
QStringList CAirlineIcaoCodeList::toIcaoDesignatorCompleterStrings() const
|
||||
QStringList CAirlineIcaoCodeList::toIcaoDesignatorCompleterStrings(bool combinedString, bool sort) const
|
||||
{
|
||||
QStringList c;
|
||||
for (const CAirlineIcaoCode &icao : *this)
|
||||
{
|
||||
if (!icao.hasValidDbKey()) { continue; }
|
||||
const QString cs(icao.getCombinedStringWithKey());
|
||||
if (cs.isEmpty()) { continue; }
|
||||
c.append(cs);
|
||||
if (combinedString)
|
||||
{
|
||||
if (!icao.hasValidDbKey()) { continue; }
|
||||
const QString cs(icao.getCombinedStringWithKey());
|
||||
if (cs.isEmpty()) { continue; }
|
||||
c.append(cs);
|
||||
}
|
||||
else
|
||||
{
|
||||
const QString d(icao.getDesignator());
|
||||
if (c.contains(d)) { continue; }
|
||||
c.append(d);
|
||||
}
|
||||
}
|
||||
if (sort) { c.sort(); }
|
||||
return c;
|
||||
}
|
||||
|
||||
QStringList CAirlineIcaoCodeList::toNameCompleterStrings() const
|
||||
QStringList CAirlineIcaoCodeList::toNameCompleterStrings(bool sort) const
|
||||
{
|
||||
QStringList c;
|
||||
for (const CAirlineIcaoCode &icao : *this)
|
||||
@@ -146,6 +156,7 @@ namespace BlackMisc
|
||||
if (cs.isEmpty()) { continue; }
|
||||
c.append(cs);
|
||||
}
|
||||
if (sort) { c.sort(); }
|
||||
return c;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -66,10 +66,10 @@ namespace BlackMisc
|
||||
CAirlineIcaoCode smartAirlineIcaoSelector(const CAirlineIcaoCode &icaoPattern) const;
|
||||
|
||||
//! String list for completion by ICAO designator
|
||||
QStringList toIcaoDesignatorCompleterStrings() const;
|
||||
QStringList toIcaoDesignatorCompleterStrings(bool combinedString = true, bool sort = true) const;
|
||||
|
||||
//! String list for completion by name
|
||||
QStringList toNameCompleterStrings() const;
|
||||
QStringList toNameCompleterStrings(bool sort = true) const;
|
||||
|
||||
//! From our DB JSON
|
||||
static CAirlineIcaoCodeList fromDatabaseJson(const QJsonArray &array, bool ignoreIncomplete = true);
|
||||
|
||||
@@ -151,19 +151,19 @@ namespace BlackMisc
|
||||
//! Valid combined code string?
|
||||
static bool isValidCombinedCode(const QString &candidate);
|
||||
|
||||
//! Standard livery marker
|
||||
//! Standard livery marker string
|
||||
static const QString &standardLiveryMarker();
|
||||
|
||||
//! Color livery marker
|
||||
static const QString &colorLiveryMarker();
|
||||
|
||||
private:
|
||||
CAirlineIcaoCode m_airline; //!< corresponding airline, if any
|
||||
QString m_combinedCode; //!< livery code and pseudo airline ICAO code
|
||||
QString m_description; //!< describes the livery
|
||||
CAirlineIcaoCode m_airline; //!< corresponding airline, if any
|
||||
QString m_combinedCode; //!< livery code and pseudo airline ICAO code
|
||||
QString m_description; //!< describes the livery
|
||||
BlackMisc::CRgbColor m_colorFuselage; //! color of fuselage
|
||||
BlackMisc::CRgbColor m_colorTail; //! color of tail
|
||||
bool m_military = false; //! Military livery?
|
||||
bool m_military = false; //! Military livery?
|
||||
|
||||
BLACK_METACLASS(
|
||||
CLivery,
|
||||
|
||||
Reference in New Issue
Block a user