mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
Fix finding of std. livery for a given airline.
This was ambigous in the past and could show wrong liveries if 2 or more liveries had the same airline code.
This commit is contained in:
@@ -30,19 +30,39 @@ namespace BlackMisc
|
||||
|
||||
CLiveryList CLiveryList::findByAirlineIcaoDesignator(const QString &icao) const
|
||||
{
|
||||
QString i(icao.trimmed().toUpper());
|
||||
if (i.isEmpty()) { return CLiveryList(); }
|
||||
return this->findBy(&CLivery::getAirlineIcaoCodeDesignator, i);
|
||||
QString icaoCode(icao.trimmed().toUpper());
|
||||
if (icaoCode.isEmpty()) { return CLiveryList(); }
|
||||
return this->findBy(&CLivery::getAirlineIcaoCodeDesignator, icaoCode);
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoVDesignator(const CAirlineIcaoCode &icao) const
|
||||
{
|
||||
if (this->isEmpty() || !icao.hasValidDesignator()) { return CLivery(); }
|
||||
CLiveryList candidates;
|
||||
for (const CLivery &livery : *this)
|
||||
{
|
||||
if (!livery.isAirlineStandardLivery()) { continue; }
|
||||
const CAirlineIcaoCode livIcao = livery.getAirlineIcaoCode();
|
||||
if (livIcao.isDbEqual(icao)) { return livery; }
|
||||
if (livIcao.getVDesignator() != icao.getVDesignator()) { continue; }
|
||||
if (icao.getName().size() > 5 && livery.getDescription().contains(icao.getName(), Qt::CaseInsensitive)) { return livery; }
|
||||
candidates.push_back(livery);
|
||||
}
|
||||
|
||||
if (candidates.size() < 2) { return candidates.frontOrDefault(); }
|
||||
const CLiveryList operatingAirlines = candidates.findBy(&CLivery::isAirlineOperating, true);
|
||||
if (!operatingAirlines.isEmpty()) { return operatingAirlines.frontOrDefault(); }
|
||||
return candidates.frontOrDefault();
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoVDesignator(const QString &icao) const
|
||||
{
|
||||
QString i(icao.trimmed().toUpper());
|
||||
if (i.isEmpty()) { return CLivery(); }
|
||||
QString icaoDesignator(icao.trimmed().toUpper());
|
||||
if (icaoDesignator.isEmpty()) { return CLivery(); }
|
||||
return this->findFirstByOrDefault([&](const CLivery & livery)
|
||||
{
|
||||
if (!livery.isAirlineStandardLivery()) { return false; }
|
||||
return livery.getAirlineIcaoCode().matchesVDesignator(i);
|
||||
return livery.getAirlineIcaoCode().matchesVDesignator(icaoDesignator);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,11 +88,6 @@ namespace BlackMisc
|
||||
});
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoVDesignator(const CAirlineIcaoCode &icao) const
|
||||
{
|
||||
return this->findStdLiveryByAirlineIcaoVDesignator(icao.getVDesignator());
|
||||
}
|
||||
|
||||
CLivery CLiveryList::findColorLiveryOrDefault(const CRgbColor &fuselage, const CRgbColor &tail) const
|
||||
{
|
||||
if (!fuselage.isValid() || !tail.isValid()) { return CLivery(); }
|
||||
@@ -127,6 +142,16 @@ namespace BlackMisc
|
||||
return codes;
|
||||
}
|
||||
|
||||
CAirlineIcaoCodeList CLiveryList::getAirlines() const
|
||||
{
|
||||
CAirlineIcaoCodeList icaos;
|
||||
for (const CLivery &livery : * this)
|
||||
{
|
||||
icaos.push_back(livery.getAirlineIcaoCode());
|
||||
}
|
||||
return icaos;
|
||||
}
|
||||
|
||||
CLivery CLiveryList::smartLiverySelector(const CLivery &liveryPattern) const
|
||||
{
|
||||
// multiple searches are slow, maybe we can performance optimize this
|
||||
|
||||
Reference in New Issue
Block a user