mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +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:
@@ -184,6 +184,11 @@ namespace BlackMisc
|
||||
return (m_airline.hasValidDesignator());
|
||||
}
|
||||
|
||||
bool CLivery::isAirlineOperating() const
|
||||
{
|
||||
return this->isAirlineLivery() && this->getAirlineIcaoCode().isOperating();
|
||||
}
|
||||
|
||||
bool CLivery::isAirlineStandardLivery() const
|
||||
{
|
||||
if (isColorLivery()) { return false; }
|
||||
|
||||
@@ -158,10 +158,13 @@ namespace BlackMisc
|
||||
//! Livery representing airline
|
||||
bool isAirlineLivery() const;
|
||||
|
||||
//! Is airline operating?
|
||||
bool isAirlineOperating() const;
|
||||
|
||||
//! Livery representing airline standard livery
|
||||
bool isAirlineStandardLivery() const;
|
||||
|
||||
//! Color livery
|
||||
//! Color livery?
|
||||
bool isColorLivery() const;
|
||||
|
||||
//! Color distance 0..1 (0 is best)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
#ifndef BLACKMISC_AVIATION_LIVERYLIST_H
|
||||
#define BLACKMISC_AVIATION_LIVERYLIST_H
|
||||
|
||||
#include "blackmisc/aviation/airlineicaocode.h"
|
||||
#include "blackmisc/aviation/airlineicaocodelist.h"
|
||||
#include "blackmisc/aviation/livery.h"
|
||||
#include "blackmisc/db/datastoreobjectlist.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/collection.h"
|
||||
#include "blackmisc/db/datastoreobjectlist.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
@@ -44,9 +44,11 @@ namespace BlackMisc
|
||||
CLiveryList(const CSequence<CLivery> &other);
|
||||
|
||||
//! Find livery by airline
|
||||
//! \remark try to use the version with CAirlineIcaoCode as it resolves ambiguities betters
|
||||
CLiveryList findByAirlineIcaoDesignator(const QString &icao) const;
|
||||
|
||||
//! Find livery by airline
|
||||
//! \remark try to use the version with CAirlineIcaoCode as it resolves ambiguities betters
|
||||
CLivery findStdLiveryByAirlineIcaoVDesignator(const QString &icao) const;
|
||||
|
||||
//! Find livery by airline
|
||||
@@ -73,6 +75,9 @@ namespace BlackMisc
|
||||
//! All combined codes plus more info
|
||||
QStringList getCombinedCodesPlusInfo(bool sort = false) const;
|
||||
|
||||
//! All aircraft codes
|
||||
CAirlineIcaoCodeList getAirlines() const;
|
||||
|
||||
//! Find by multiple criteria
|
||||
CLivery smartLiverySelector(const CLivery &liveryPattern) const;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user