mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T472, further utility functions for category handling
This commit is contained in:
committed by
Mat Sutcliffe
parent
c899bfbea7
commit
54adb40329
@@ -57,6 +57,13 @@ namespace BlackMisc
|
||||
return levels;
|
||||
}
|
||||
|
||||
QString CAircraftCategoryList::getLevelsString(const QString &separator) const
|
||||
{
|
||||
const QSet<QString> levels = this->getLevelStrings();
|
||||
if (levels.isEmpty()) {return {}; }
|
||||
return levels.toList().join(separator);
|
||||
}
|
||||
|
||||
QList<int> CAircraftCategoryList::getFirstLevels() const
|
||||
{
|
||||
QSet<int> levels;
|
||||
|
||||
@@ -55,6 +55,9 @@ namespace BlackMisc
|
||||
//! Get all level strings
|
||||
QSet<QString> getLevelStrings() const;
|
||||
|
||||
//! Get all level strings
|
||||
QString getLevelsString(const QString &separator = ", ") const;
|
||||
|
||||
//! All levels sorted
|
||||
QList<int> getFirstLevels() const;
|
||||
|
||||
|
||||
@@ -216,7 +216,7 @@ namespace BlackMisc
|
||||
this->removeIf(&CAircraftIcaoCode::isDbDuplicate, true);
|
||||
}
|
||||
|
||||
QStringList CAircraftIcaoCodeList::toCompleterStrings(bool withIataCodes, bool withFamily, bool sort) const
|
||||
QStringList CAircraftIcaoCodeList::toCompleterStrings(bool withIataCodes, bool withFamily, bool withCategory, bool sort) const
|
||||
{
|
||||
QStringList c;
|
||||
CAircraftIcaoCodeList icaos(*this);
|
||||
@@ -225,7 +225,7 @@ namespace BlackMisc
|
||||
// 3 steps to get a proper sort order of the string list
|
||||
for (const CAircraftIcaoCode &icao : as_const(icaos))
|
||||
{
|
||||
c.append(icao.getCombinedIcaoStringWithKey());
|
||||
c.append(withCategory ? icao.getCombinedIcaoCategoryStringWithKey() : icao.getCombinedIcaoStringWithKey());
|
||||
}
|
||||
|
||||
if (withFamily)
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace BlackMisc
|
||||
void removeDuplicates();
|
||||
|
||||
//! For selection completion
|
||||
QStringList toCompleterStrings(bool withIataCodes = false, bool withFamily = false, bool sort = true) const;
|
||||
QStringList toCompleterStrings(bool withIataCodes = false, bool withFamily = false, bool withCategory = true, bool sort = true) const;
|
||||
|
||||
//! All ICAO codes, no duplicates
|
||||
QSet<QString> allDesignators(bool noUnspecified = true) const;
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace BlackMisc
|
||||
if (this->hasValidDbKey())
|
||||
{
|
||||
return this->hasModelString() ?
|
||||
QString(this->getModelString() + this->getDbKeyAsStringInParentheses(" ")) :
|
||||
this->getModelString() % this->getDbKeyAsStringInParentheses(" ") :
|
||||
this->getDbKeyAsString();
|
||||
}
|
||||
else
|
||||
@@ -390,6 +390,11 @@ namespace BlackMisc
|
||||
return m_aircraftIcao.hasKnownDesignator();
|
||||
}
|
||||
|
||||
bool CAircraftModel::hasCategory() const
|
||||
{
|
||||
return m_aircraftIcao.hasCategory();
|
||||
}
|
||||
|
||||
bool CAircraftModel::hasAirlineDesignator() const
|
||||
{
|
||||
return m_livery.hasValidAirlineDesignator();
|
||||
|
||||
@@ -242,6 +242,9 @@ namespace BlackMisc
|
||||
//! Has known aircraft designator?
|
||||
bool hasKnownAircraftDesignator() const;
|
||||
|
||||
//! Assigned a category?
|
||||
bool hasCategory() const;
|
||||
|
||||
//! Airline designator?
|
||||
bool hasAirlineDesignator() const;
|
||||
|
||||
|
||||
@@ -276,6 +276,17 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::findByDesignatorsOrFamilyWithColorLivery(const QStringList &designators) const
|
||||
{
|
||||
return this->findBy([ & ](const CAircraftModel & model)
|
||||
{
|
||||
if (!model.getLivery().isColorLivery()) { return false; }
|
||||
const CAircraftIcaoCode modelIcao(model.getAircraftIcaoCode());
|
||||
if (designators.contains(modelIcao.getDesignator())) { return true; }
|
||||
return modelIcao.hasFamily() && designators.contains(modelIcao.getFamily());
|
||||
});
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::findByCombinedType(const QString &combinedType) const
|
||||
{
|
||||
const QString cc(combinedType.trimmed().toUpper());
|
||||
@@ -356,6 +367,33 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::findByCategoryFirstLevel(int firstLevel) const
|
||||
{
|
||||
if (firstLevel < 0) { return CAircraftModelList(); }
|
||||
return this->findBy([ = ](const CAircraftModel & model)
|
||||
{
|
||||
return (model.hasCategory() && model.getAircraftIcaoCode().getCategory().getFirstLevel() == firstLevel);
|
||||
});
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::findByCategory(const CAircraftCategory &category) const
|
||||
{
|
||||
if (category.isNull()) { return CAircraftModelList(); }
|
||||
return this->findBy([ = ](const CAircraftModel & model)
|
||||
{
|
||||
return (model.hasCategory() && model.getAircraftIcaoCode().getCategory() == category);
|
||||
});
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::findByCategories(const CAircraftCategoryList &categories) const
|
||||
{
|
||||
if (categories.isEmpty()) { return CAircraftModelList(); }
|
||||
return this->findBy([ = ](const CAircraftModel & model)
|
||||
{
|
||||
return (model.hasCategory() && categories.contains(model.getAircraftIcaoCode().getCategory()));
|
||||
});
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::findFsFamilyModels() const
|
||||
{
|
||||
return this->findBy([](const CAircraftModel & model)
|
||||
@@ -545,6 +583,23 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
bool CAircraftModelList::containsCategory() const
|
||||
{
|
||||
return this->containsBy([ & ](const CAircraftModel & model)
|
||||
{
|
||||
return model.hasCategory();
|
||||
});
|
||||
}
|
||||
|
||||
bool CAircraftModelList::containsCategory(int firstLevel) const
|
||||
{
|
||||
if (firstLevel < 0) { return false; }
|
||||
return this->containsBy([ & ](const CAircraftModel & model)
|
||||
{
|
||||
return model.hasCategory() && model.getAircraftIcaoCode().getCategory().getFirstLevel() == firstLevel;
|
||||
});
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::findByDistributors(const CDistributorList &distributors) const
|
||||
{
|
||||
if (distributors.isEmpty()) { return CAircraftModelList(); }
|
||||
|
||||
@@ -106,6 +106,12 @@ namespace BlackMisc
|
||||
//! Contains VTOL models?
|
||||
bool containsVtol() const;
|
||||
|
||||
//! Contains any categorized model?
|
||||
bool containsCategory() const;
|
||||
|
||||
//! Contains any model with 1st level?
|
||||
bool containsCategory(int firstLevel) const;
|
||||
|
||||
//! Find by model string
|
||||
//! \remark normally CAircraftModelList::findFirstByModelStringOrDefault would be used
|
||||
CAircraftModelList findByModelString(const QString &modelString, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive) const;
|
||||
@@ -176,6 +182,9 @@ namespace BlackMisc
|
||||
//! Models with aircraft family or designator and color livery
|
||||
CAircraftModelList findByDesignatorOrFamilyWithColorLivery(const Aviation::CAircraftIcaoCode &icao) const;
|
||||
|
||||
//! Models with aircraft family or designators and color livery
|
||||
CAircraftModelList findByDesignatorsOrFamilyWithColorLivery(const QStringList &designators) const;
|
||||
|
||||
//! Find by combined code, wildcards possible, e.g. L*P, *2J
|
||||
CAircraftModelList findByCombinedType(const QString &combinedType) const;
|
||||
|
||||
@@ -208,6 +217,15 @@ namespace BlackMisc
|
||||
//! Find by model mode
|
||||
CAircraftModelList findByModelMode(CAircraftModel::ModelMode mode) const;
|
||||
|
||||
//! Find by first level of category
|
||||
CAircraftModelList findByCategoryFirstLevel(int firstLevel) const;
|
||||
|
||||
//! Find by category
|
||||
CAircraftModelList findByCategory(const Aviation::CAircraftCategory &category) const;
|
||||
|
||||
//! Find by categories
|
||||
CAircraftModelList findByCategories(const Aviation::CAircraftCategoryList &categories) const;
|
||||
|
||||
//! Model icon path
|
||||
QString findModelIconPathByModelString(const QString &modelString) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user