mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +08:00
refs #720, finder by Telephony designator (aka callsign) and name
This commit is contained in:
committed by
Mathew Sutcliffe
parent
dbdea2d846
commit
009bfc3ed1
@@ -125,6 +125,13 @@ namespace BlackMisc
|
|||||||
return this->matchesVDesignator(candidate) || this->matchesIataCode(candidate);
|
return this->matchesVDesignator(candidate) || this->matchesIataCode(candidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CAirlineIcaoCode::matchesNamesOrTelephonyDesignator(const QString &candidate) const
|
||||||
|
{
|
||||||
|
const QString cand(candidate.toUpper().trimmed());
|
||||||
|
if (this->getName().contains(cand, Qt::CaseInsensitive) || this->getTelephonyDesignator().contains(cand, Qt::CaseInsensitive)) { return true; }
|
||||||
|
return this->isContainedInSimplifiedName(candidate);
|
||||||
|
}
|
||||||
|
|
||||||
bool CAirlineIcaoCode::isContainedInSimplifiedName(const QString &candidate) const
|
bool CAirlineIcaoCode::isContainedInSimplifiedName(const QString &candidate) const
|
||||||
{
|
{
|
||||||
if (candidate.isEmpty() || !this->hasName()) { return false; }
|
if (candidate.isEmpty() || !this->hasName()) { return false; }
|
||||||
|
|||||||
@@ -149,6 +149,9 @@ namespace BlackMisc
|
|||||||
//! Matches IATA code or v-designator?
|
//! Matches IATA code or v-designator?
|
||||||
bool matchesVDesignatorOrIataCode(const QString &candidate) const;
|
bool matchesVDesignatorOrIataCode(const QString &candidate) const;
|
||||||
|
|
||||||
|
//! Relaxed check by name or telephony designator (aka callsign, not to be confused with CCallsign)
|
||||||
|
bool matchesNamesOrTelephonyDesignator(const QString &candidate) const;
|
||||||
|
|
||||||
//! Does simplified name contain the candidate
|
//! Does simplified name contain the candidate
|
||||||
bool isContainedInSimplifiedName(const QString &candidate) const;
|
bool isContainedInSimplifiedName(const QString &candidate) const;
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,15 @@ namespace BlackMisc
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAirlineIcaoCodeList CAirlineIcaoCodeList::findByNamesOrTelephonyDesignator(const QString &candidate) const
|
||||||
|
{
|
||||||
|
if (candidate.isEmpty()) { return CAirlineIcaoCodeList(); }
|
||||||
|
return this->findBy([&](const CAirlineIcaoCode & code)
|
||||||
|
{
|
||||||
|
return code.matchesNamesOrTelephonyDesignator(candidate);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::findByMilitary(bool military) const
|
CAirlineIcaoCodeList CAirlineIcaoCodeList::findByMilitary(bool military) const
|
||||||
{
|
{
|
||||||
return this->findBy([&](const CAirlineIcaoCode & code)
|
return this->findBy([&](const CAirlineIcaoCode & code)
|
||||||
@@ -99,33 +108,44 @@ namespace BlackMisc
|
|||||||
|
|
||||||
CAirlineIcaoCode CAirlineIcaoCodeList::smartAirlineIcaoSelector(const CAirlineIcaoCode &icaoPattern, const CCallsign &callsign) const
|
CAirlineIcaoCode CAirlineIcaoCodeList::smartAirlineIcaoSelector(const CAirlineIcaoCode &icaoPattern, const CCallsign &callsign) const
|
||||||
{
|
{
|
||||||
|
if (icaoPattern.hasValidDbKey()) { return icaoPattern; }
|
||||||
const CAirlineIcaoCode patternUsed = icaoPattern.thisOrCallsignCode(callsign);
|
const CAirlineIcaoCode patternUsed = icaoPattern.thisOrCallsignCode(callsign);
|
||||||
if (patternUsed.hasValidDbKey())
|
|
||||||
{
|
|
||||||
return this->findByKey(icaoPattern.getDbKey(), icaoPattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
// search by parts
|
// search by parts
|
||||||
CAirlineIcaoCodeList codes;
|
CAirlineIcaoCodeList codesFound;
|
||||||
if (patternUsed.hasValidDesignator())
|
if (patternUsed.hasValidDesignator())
|
||||||
{
|
{
|
||||||
codes = this->findByVDesignator(patternUsed.getVDesignator());
|
codesFound = this->findByVDesignator(patternUsed.getVDesignator());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
codes = this->findByIataCode(patternUsed.getIataCode());
|
codesFound = this->findByIataCode(patternUsed.getIataCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codes.size() == 1) { return codes.front(); }
|
if (codesFound.size() == 1) { return codesFound.front(); }
|
||||||
|
if (codesFound.isEmpty())
|
||||||
|
{
|
||||||
|
codesFound = this->findByNamesOrTelephonyDesignator(patternUsed.getName());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// further reduce
|
||||||
|
if (patternUsed.hasName())
|
||||||
|
{
|
||||||
|
CAirlineIcaoCodeList backup(codesFound);
|
||||||
|
codesFound = this->findByNamesOrTelephonyDesignator(patternUsed.getName());
|
||||||
|
if (codesFound.isEmpty()) { codesFound = backup; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// further reduce
|
// further reduce
|
||||||
if (patternUsed.hasValidCountry())
|
if (patternUsed.hasValidCountry())
|
||||||
{
|
{
|
||||||
CAirlineIcaoCodeList countryCodes = codes.findByCountryIsoCode(patternUsed.getCountry().getIsoCode());
|
CAirlineIcaoCodeList countryCodes = codesFound.findByCountryIsoCode(patternUsed.getCountry().getIsoCode());
|
||||||
if (!countryCodes.isEmpty()) { return countryCodes.front(); }
|
if (!countryCodes.isEmpty()) { return countryCodes.front(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!codes.isEmpty()) { return codes.front(); }
|
if (!codesFound.isEmpty()) { return codesFound.front(); }
|
||||||
return patternUsed;
|
return patternUsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,5 +225,5 @@ namespace BlackMisc
|
|||||||
if (sort) { c.sort(); }
|
if (sort) { c.sort(); }
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
} // namespace
|
} // ns
|
||||||
} // namespace
|
} // ns
|
||||||
|
|||||||
@@ -69,6 +69,9 @@ namespace BlackMisc
|
|||||||
//! Find if simplified name contains search string
|
//! Find if simplified name contains search string
|
||||||
CAirlineIcaoCodeList findBySimplifiedNameContaining(const QString &containedString) const;
|
CAirlineIcaoCodeList findBySimplifiedNameContaining(const QString &containedString) const;
|
||||||
|
|
||||||
|
//! Find by names or telephony designator (aka callsign, not to be confused with CCallsign)
|
||||||
|
CAirlineIcaoCodeList findByNamesOrTelephonyDesignator(const QString &candidate) const;
|
||||||
|
|
||||||
//! Find by military flag
|
//! Find by military flag
|
||||||
CAirlineIcaoCodeList findByMilitary(bool military) const;
|
CAirlineIcaoCodeList findByMilitary(bool military) const;
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,17 @@ namespace BlackMisc
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CLiveryList CLiveryList::findStdLiveriesByNamesOrTelephonyDesignator(const QString &candidate) const
|
||||||
|
{
|
||||||
|
if (candidate.isEmpty()) { return CLiveryList(); }
|
||||||
|
return this->findBy([&](const CLivery & livery)
|
||||||
|
{
|
||||||
|
// keep isAirlineStandardLivery first (faster)
|
||||||
|
return livery.isAirlineStandardLivery() &&
|
||||||
|
livery.getAirlineIcaoCode().matchesNamesOrTelephonyDesignator(candidate);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
CLivery CLiveryList::findStdLiveryByAirlineIcaoVDesignator(const CAirlineIcaoCode &icao) const
|
CLivery CLiveryList::findStdLiveryByAirlineIcaoVDesignator(const CAirlineIcaoCode &icao) const
|
||||||
{
|
{
|
||||||
return this->findStdLiveryByAirlineIcaoVDesignator(icao.getVDesignator());
|
return this->findStdLiveryByAirlineIcaoVDesignator(icao.getVDesignator());
|
||||||
@@ -92,15 +103,10 @@ namespace BlackMisc
|
|||||||
CLivery CLiveryList::smartLiverySelector(const CLivery &liveryPattern) const
|
CLivery CLiveryList::smartLiverySelector(const CLivery &liveryPattern) const
|
||||||
{
|
{
|
||||||
// multiple searches are slow, maybe we can performance optimize this
|
// multiple searches are slow, maybe we can performance optimize this
|
||||||
// in the futuew
|
// in the future
|
||||||
|
|
||||||
// first try on id, that would be perfect
|
// first try on id, that would be perfect
|
||||||
if (liveryPattern.hasValidDbKey())
|
if (liveryPattern.hasValidDbKey()) { return liveryPattern; }
|
||||||
{
|
|
||||||
int k = liveryPattern.getDbKey();
|
|
||||||
const CLivery l(this->findByKey(k));
|
|
||||||
if (l.hasCompleteData()) { return l; }
|
|
||||||
}
|
|
||||||
|
|
||||||
// by combined code
|
// by combined code
|
||||||
if (liveryPattern.hasCombinedCode())
|
if (liveryPattern.hasCombinedCode())
|
||||||
@@ -122,7 +128,7 @@ namespace BlackMisc
|
|||||||
if (liveryPattern.getAirlineIcaoCode().hasName())
|
if (liveryPattern.getAirlineIcaoCode().hasName())
|
||||||
{
|
{
|
||||||
const QString search(liveryPattern.getAirlineIcaoCode().getSimplifiedName());
|
const QString search(liveryPattern.getAirlineIcaoCode().getSimplifiedName());
|
||||||
const CLiveryList liveries(this->findStdLiveriesBySimplifiedAirlineName(search));
|
const CLiveryList liveries(this->findStdLiveriesByNamesOrTelephonyDesignator(search));
|
||||||
if (!liveries.isEmpty())
|
if (!liveries.isEmpty())
|
||||||
{
|
{
|
||||||
return liveries.front();
|
return liveries.front();
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ namespace BlackMisc
|
|||||||
//! By simplified name
|
//! By simplified name
|
||||||
CLiveryList findStdLiveriesBySimplifiedAirlineName(const QString &containedString) const;
|
CLiveryList findStdLiveriesBySimplifiedAirlineName(const QString &containedString) const;
|
||||||
|
|
||||||
|
//! By names or telephony designator(aka callsign)
|
||||||
|
CLiveryList findStdLiveriesByNamesOrTelephonyDesignator(const QString &candidate) const;
|
||||||
|
|
||||||
//! Find livery by combined code
|
//! Find livery by combined code
|
||||||
CLivery findByCombinedCode(const QString &combinedCode) const;
|
CLivery findByCombinedCode(const QString &combinedCode) const;
|
||||||
|
|
||||||
@@ -64,7 +67,7 @@ namespace BlackMisc
|
|||||||
//! All combined codes plus more info
|
//! All combined codes plus more info
|
||||||
QStringList getCombinedCodesPlusInfo(bool sort = false) const;
|
QStringList getCombinedCodesPlusInfo(bool sort = false) const;
|
||||||
|
|
||||||
//! Find
|
//! Find by multiple criteria
|
||||||
CLivery smartLiverySelector(const CLivery &liveryPattern) const;
|
CLivery smartLiverySelector(const CLivery &liveryPattern) const;
|
||||||
};
|
};
|
||||||
} //namespace
|
} //namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user