Gimmick and formatting

* flags for VATSIM servers
* improved country resolution
This commit is contained in:
Klaus Basan
2016-07-01 14:29:27 +02:00
parent 18112a0394
commit 663b161b0c
7 changed files with 70 additions and 25 deletions

View File

@@ -119,8 +119,7 @@ namespace BlackMisc
if (this->m_designator.length() > 2)
{
// relative to images
return CIcon("airlines/" + m_designator.toLower() + ".png",
this->convertToQString());
return CIcon("airlines/" + m_designator.toLower() + ".png", this->convertToQString());
}
else
{

View File

@@ -26,8 +26,7 @@ namespace BlackMisc
if (this->m_dbKey.length() == 2)
{
// relative to images
return CIcon("flags/" + m_dbKey.toLower() + ".png",
this->convertToQString());
return CIcon("flags/" + m_dbKey.toLower() + ".png", this->convertToQString());
}
else
{
@@ -73,7 +72,7 @@ namespace BlackMisc
if (name.isEmpty() || m_name.isEmpty()) { return false; }
if (name.length() < 5)
{
return m_name.length() == name.length() && m_name.startsWith(name, Qt::CaseInsensitive);
return m_name.length() == name.length() && (m_name.startsWith(name, Qt::CaseInsensitive) || name.startsWith(m_name, Qt::CaseInsensitive));
}
else
{

View File

@@ -32,17 +32,22 @@ namespace BlackMisc
CCountry CCountryList::findBestMatchByCountryName(const QString &countryName) const
{
if (countryName.isEmpty()) { return CCountry(); }
static const QRegExp reg("[^a-z]", Qt::CaseInsensitive);
QString cn(countryName);
cn.remove(reg);
CCountryList countries = this->findBy([&](const CCountry & country)
{
return country.matchesCountryName(countryName);
return country.matchesCountryName(cn);
});
if (countries.size() < 2) { return countries.frontOrDefault(); }
// find best match
// find best match by further reducing
for (const CCountry &c : countries)
{
if (c.getName() == countryName) { return c; }
if (c.getName().startsWith(countryName, Qt::CaseInsensitive)) { return c; }
if (c.getName() == cn) { return c; }
if (c.getName().startsWith(cn, Qt::CaseInsensitive)) { return c; }
if (cn.startsWith(c.getName(), Qt::CaseInsensitive)) { return c; }
}
return countries.front();
}