mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 21:56:43 +08:00
refs #452, adjusted aircraft/aviation classes
* support for loading from datastore * improved timestamp handling * new color and country classes * new attributes * updates for missing parts in CUser
This commit is contained in:
committed by
Mathew Sutcliffe
parent
c5f7179588
commit
ae24700299
91
src/blackmisc/countrylist.cpp
Normal file
91
src/blackmisc/countrylist.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "countrylist.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
CCountryList::CCountryList(const CSequence<CCountry> &other) :
|
||||
CSequence<CCountry>(other)
|
||||
{ }
|
||||
|
||||
CCountry CCountryList::findByIsoCode(const QString &isoCode) const
|
||||
{
|
||||
QString iso(isoCode.trimmed().toUpper());
|
||||
if (!CCountry::isValidIsoCode(iso)) { return CCountry(); }
|
||||
return IDatastoreObjectListWithStringKey::findByKey(isoCode);
|
||||
}
|
||||
|
||||
CCountry CCountryList::findBestMatchByCountryName(const QString &countryName) const
|
||||
{
|
||||
if (countryName.isEmpty()) { return CCountry(); }
|
||||
CCountryList countries = this->findBy([&](const CCountry & country)
|
||||
{
|
||||
return country.matchesCountryName(countryName);
|
||||
});
|
||||
if (countries.size() < 2) { return countries.frontOrDefault(); }
|
||||
|
||||
// find best match
|
||||
for (const CCountry &c : countries)
|
||||
{
|
||||
if (c.getName() == countryName) { return c; }
|
||||
if (c.getName().startsWith(countryName, Qt::CaseInsensitive)) { return c; }
|
||||
}
|
||||
return countries.front();
|
||||
}
|
||||
|
||||
QStringList CCountryList::toIsoNameList() const
|
||||
{
|
||||
QStringList sl;
|
||||
for (const CCountry &country : (*this))
|
||||
{
|
||||
QString s = country.getCombinedStringIsoName();
|
||||
if (s.isEmpty()) { continue; }
|
||||
sl.append(s);
|
||||
}
|
||||
return sl;
|
||||
}
|
||||
|
||||
QStringList CCountryList::toNameIsoList() const
|
||||
{
|
||||
QStringList sl;
|
||||
for (const CCountry &country : (*this))
|
||||
{
|
||||
QString s = country.getCombinedStringNameIso();
|
||||
if (s.isEmpty()) { continue; }
|
||||
sl.append(s);
|
||||
}
|
||||
return sl;
|
||||
}
|
||||
|
||||
QStringList CCountryList::toNameList() const
|
||||
{
|
||||
QStringList sl;
|
||||
for (const CCountry &country : (*this))
|
||||
{
|
||||
QString s = country.getName();
|
||||
if (s.isEmpty()) { continue; }
|
||||
sl.append(s);
|
||||
}
|
||||
return sl;
|
||||
}
|
||||
|
||||
|
||||
CCountryList CCountryList::fromDatabaseJson(const QJsonArray &array)
|
||||
{
|
||||
CCountryList countries;
|
||||
for (const QJsonValue &value : array)
|
||||
{
|
||||
CCountry country(CCountry::fromDatabaseJson(value.toObject()));
|
||||
countries.push_back(country);
|
||||
}
|
||||
return countries;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user