mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-18 03:15:34 +08:00
Moved smart selector functions to lists
This commit is contained in:
committed by
Mathew Sutcliffe
parent
5e42aa0b95
commit
955b8bafea
@@ -82,5 +82,49 @@ namespace BlackMisc
|
||||
return codes;
|
||||
}
|
||||
|
||||
CAircraftIcaoCode CAircraftIcaoCodeList::smartAircraftIcaoSelector(const CAircraftIcaoCode &icaoPattern) const
|
||||
{
|
||||
if (icaoPattern.hasValidDbKey())
|
||||
{
|
||||
int k = icaoPattern.getDbKey();
|
||||
CAircraftIcaoCode c(this->findByKey(k));
|
||||
if (c.hasCompleteData()) { return c; }
|
||||
}
|
||||
|
||||
CAircraftIcaoCodeList codes(*this); // copy and reduce
|
||||
if (icaoPattern.hasKnownDesignator())
|
||||
{
|
||||
const QString d(icaoPattern.getDesignator());
|
||||
codes = codes.findByDesignator(d);
|
||||
if (codes.size() == 1) { return codes.front(); }
|
||||
if (codes.isEmpty()) { return icaoPattern; }
|
||||
codes.sortByRank();
|
||||
|
||||
// intentionally continue here
|
||||
}
|
||||
|
||||
// further reduce by manufacturer
|
||||
if (icaoPattern.hasManufacturer())
|
||||
{
|
||||
const QString m(icaoPattern.getManufacturer());
|
||||
codes = codes.findByManufacturer(m);
|
||||
if (codes.size() == 1) { return codes.front(); }
|
||||
if (codes.isEmpty()) { return icaoPattern; }
|
||||
|
||||
// intentionally continue here
|
||||
}
|
||||
|
||||
// lucky punch on description?
|
||||
if (icaoPattern.hasModelDescription())
|
||||
{
|
||||
// do not affect codes here, it might return no results
|
||||
const QString d(icaoPattern.getModelDescription());
|
||||
CAircraftIcaoCodeList cm(codes.findByDescription(d));
|
||||
if (cm.size() == 1) { return cm.front(); }
|
||||
if (cm.size() > 1 && cm.size() < codes.size()) { return codes.front(); }
|
||||
}
|
||||
return codes.frontOrDefault(); // sorted by rank
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user