mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
refs #720, improved distributor and airline/livery detection
* mark data read from DB (req. for string key where existing key value is not reliable indicator for DB data) * detect distributors by part of model string * use a simplified name (no spaces, no special characters) to find a match * allow to obtain model strings (=keys) as set and list
This commit is contained in:
committed by
Mathew Sutcliffe
parent
39dae7ed45
commit
f9922353c4
@@ -37,21 +37,31 @@ namespace BlackMisc
|
||||
return this->findBy(&CLivery::getAirlineIcaoCodeDesignator, i);
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoDesignator(const QString &icao) const
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoVDesignator(const QString &icao) const
|
||||
{
|
||||
QString i(icao.trimmed().toUpper());
|
||||
if (i.isEmpty()) { return CLivery(); }
|
||||
return this->findFirstByOrDefault([&](const CLivery & livery)
|
||||
{
|
||||
return livery.getAirlineIcaoCodeDesignator() == icao &&
|
||||
livery.isAirlineStandardLivery();
|
||||
|
||||
if (!livery.isAirlineStandardLivery()) { return false; }
|
||||
return livery.getAirlineIcaoCode().matchesVDesignator(i);
|
||||
});
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoDesignator(const CAirlineIcaoCode &icao) const
|
||||
CLiveryList CLiveryList::findStdLiveriesBySimplifiedAirlineName(const QString &containedString) const
|
||||
{
|
||||
return this->findStdLiveryByAirlineIcaoDesignator(icao.getDesignator());
|
||||
if (containedString.isEmpty()) { return CLiveryList(); }
|
||||
return this->findBy([&](const CLivery & livery)
|
||||
{
|
||||
// keep isAirlineStandardLivery first (faster)
|
||||
return livery.isAirlineStandardLivery() &&
|
||||
livery.isContainedInSimplifiedAirlineName(containedString);
|
||||
});
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoVDesignator(const CAirlineIcaoCode &icao) const
|
||||
{
|
||||
return this->findStdLiveryByAirlineIcaoVDesignator(icao.getVDesignator());
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findByCombinedCode(const QString &combinedCode) const
|
||||
@@ -81,6 +91,9 @@ namespace BlackMisc
|
||||
|
||||
CLivery CLiveryList::smartLiverySelector(const CLivery &liveryPattern) const
|
||||
{
|
||||
// multiple searches are slow, maybe we can performance optimize this
|
||||
// in the futuew
|
||||
|
||||
// first try on id, that would be perfect
|
||||
if (liveryPattern.hasValidDbKey())
|
||||
{
|
||||
@@ -97,14 +110,25 @@ namespace BlackMisc
|
||||
if (l.hasCompleteData()) { return l; }
|
||||
}
|
||||
|
||||
// by airline
|
||||
if (liveryPattern.hasValidAirlineDesignator())
|
||||
{
|
||||
const QString icao(liveryPattern.getAirlineIcaoCodeDesignator());
|
||||
const CLivery l(this->findStdLiveryByAirlineIcaoDesignator(icao));
|
||||
const CLivery l(this->findStdLiveryByAirlineIcaoVDesignator(icao));
|
||||
if (l.hasCompleteData()) { return l; }
|
||||
}
|
||||
|
||||
// lenient search by name contained (slow)
|
||||
if (liveryPattern.getAirlineIcaoCode().hasName())
|
||||
{
|
||||
const QString search(liveryPattern.getAirlineIcaoCode().getSimplifiedName());
|
||||
const CLiveryList liveries(this->findStdLiveriesBySimplifiedAirlineName(search));
|
||||
if (!liveries.isEmpty())
|
||||
{
|
||||
return liveries.front();
|
||||
}
|
||||
}
|
||||
return CLivery();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user