mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +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
@@ -13,8 +13,9 @@
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include <tuple>
|
||||
#include <QThreadStorage>
|
||||
#include <QRegularExpression>
|
||||
|
||||
#include "blackmisc/logmessage.h"
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
@@ -22,13 +23,12 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
|
||||
CAirlineIcaoCode::CAirlineIcaoCode(const QString &airlineDesignator)
|
||||
: m_designator(airlineDesignator.trimmed().toUpper())
|
||||
{}
|
||||
|
||||
CAirlineIcaoCode::CAirlineIcaoCode(const QString &airlineDesignator, const QString &airlineName, const QString &countryIso, const QString &country, const QString &telephony, bool virtualAirline)
|
||||
: m_designator(airlineDesignator.trimmed().toUpper()), m_name(airlineName), m_countryIso(countryIso.trimmed().toUpper()), m_country(country), m_telephonyDesignator(telephony), m_isVa(virtualAirline)
|
||||
CAirlineIcaoCode::CAirlineIcaoCode(const QString &airlineDesignator, const QString &airlineName, const BlackMisc::CCountry &country, const QString &telephony, bool virtualAirline, bool operating)
|
||||
: m_designator(airlineDesignator.trimmed().toUpper()), m_name(airlineName), m_country(country), m_telephonyDesignator(telephony), m_isVa(virtualAirline), m_isOperating(operating)
|
||||
{}
|
||||
|
||||
const QString CAirlineIcaoCode::getVDesignator() const
|
||||
@@ -37,15 +37,60 @@ namespace BlackMisc
|
||||
return QString("V").append(this->m_designator);
|
||||
}
|
||||
|
||||
QString CAirlineIcaoCode::getDesignatorNameCountry() const
|
||||
{
|
||||
QString s(this->getDesignator());
|
||||
if (this->hasName()) { s = s.append(" ").append(this->getName()); }
|
||||
if (this->hasValidCountry()) { s = s.append(" ").append(this->getCountryIso()); }
|
||||
return s.trimmed();
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::hasValidCountry() const
|
||||
{
|
||||
return this->m_country.isValid();
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::hasValidDesignator() const
|
||||
{
|
||||
return isValidAirlineDesignator(m_designator);
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::matchesDesignator(const QString &designator) const
|
||||
{
|
||||
if (designator.isEmpty()) { return false; }
|
||||
return designator.trimmed().toUpper() == this->m_designator;
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::matchesVDesignator(const QString &designator) const
|
||||
{
|
||||
if (designator.isEmpty()) { return false; }
|
||||
return designator.trimmed().toUpper() == this->getVDesignator();
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::hasCompleteData() const
|
||||
{
|
||||
return this->hasDesignator() && this->hasCountryIso() && this->hasName();
|
||||
return this->hasValidDesignator() && this->hasValidCountry() && this->hasName();
|
||||
}
|
||||
|
||||
CIcon CAirlineIcaoCode::toIcon() const
|
||||
{
|
||||
if (this->m_designator.length() > 2)
|
||||
{
|
||||
return CIcon("images/airlines/" + m_designator.toLower() + ".png",
|
||||
this->convertToQString());
|
||||
}
|
||||
else
|
||||
{
|
||||
return CIcon::iconByIndex(CIcons::StandardIconEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
QString CAirlineIcaoCode::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
QString s(this->m_designator);
|
||||
if (this->m_name.isEmpty()) { return ""; }
|
||||
if (!this->m_name.isEmpty()) { s.append(" (").append(this->m_name).append(")"); }
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -59,15 +104,19 @@ namespace BlackMisc
|
||||
case IndexAirlineDesignator:
|
||||
return CVariant::fromValue(this->m_designator);
|
||||
case IndexAirlineCountryIso:
|
||||
return CVariant::fromValue(this->m_countryIso);
|
||||
return CVariant::fromValue(this->getCountryIso());
|
||||
case IndexAirlineCountry:
|
||||
return CVariant::fromValue(this->m_country);
|
||||
return this->m_country.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexAirlineName:
|
||||
return CVariant::fromValue(this->m_name);
|
||||
case IndexTelephonyDesignator:
|
||||
return CVariant::fromValue(this->m_telephonyDesignator);
|
||||
case IndexIsVirtualAirline:
|
||||
return CVariant::fromValue(this->m_isVa);
|
||||
case IndexIsOperating:
|
||||
return CVariant::fromValue(this->m_isOperating);
|
||||
case IndexDesignatorNameCountry:
|
||||
return CVariant::fromValue(this->getDesignatorNameCountry());
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
@@ -83,11 +132,8 @@ namespace BlackMisc
|
||||
case IndexAirlineDesignator:
|
||||
this->setDesignator(variant.value<QString>());
|
||||
break;
|
||||
case IndexAirlineCountryIso:
|
||||
this->setCountryIso(variant.value<QString>());
|
||||
break;
|
||||
case IndexAirlineCountry:
|
||||
this->setCountry(variant.value<QString>());
|
||||
this->setCountry(variant.value<CCountry>());
|
||||
break;
|
||||
case IndexAirlineName:
|
||||
this->setName(variant.value<QString>());
|
||||
@@ -98,12 +144,25 @@ namespace BlackMisc
|
||||
case IndexIsVirtualAirline:
|
||||
this->setVirtualAirline(variant.toBool());
|
||||
break;
|
||||
case IndexIsOperating:
|
||||
this->setOperating(variant.toBool());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
CStatusMessageList CAirlineIcaoCode::validate() const
|
||||
{
|
||||
static const CLogCategoryList cats( { CLogCategory(this->getClassName()), CLogCategory::validation()});
|
||||
CStatusMessageList msgs;
|
||||
if (!hasValidDesignator()) { msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, "Airline: missing designator")); }
|
||||
if (!hasValidCountry()) { msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, "Airline: missing country")); }
|
||||
if (!hasName()) { msgs.push_back(CStatusMessage(cats, CStatusMessage::SeverityError, "Airline: no name")); }
|
||||
return msgs;
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::isValidAirlineDesignator(const QString &airline)
|
||||
{
|
||||
if (airline.length() < 2 || airline.length() > 5) return false;
|
||||
@@ -114,27 +173,47 @@ namespace BlackMisc
|
||||
return (regexp.match(airline).hasMatch());
|
||||
}
|
||||
|
||||
CAirlineIcaoCode CAirlineIcaoCode::fromDatabaseJson(const QJsonObject &json)
|
||||
QString CAirlineIcaoCode::getCombinedStringWithKey() const
|
||||
{
|
||||
// https://ubuntu12/vatrep/public/service/allairlineicao.php?rows=10
|
||||
QJsonArray inner = json["cell"].toArray();
|
||||
Q_ASSERT_X(!inner.isEmpty(), Q_FUNC_INFO, "Missing JSON");
|
||||
if (inner.isEmpty()) { return CAirlineIcaoCode(); }
|
||||
QString s(getVDesignator());
|
||||
if (hasName()) { s = s.append(" ").append(getName()); }
|
||||
return s.append(" ").append(getDbKeyAsStringInParentheses());
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
int dbKey = inner.at(i++).toInt(-1);
|
||||
QString designator(inner.at(i++).toString());
|
||||
QString vDesignator(inner.at(i++).toString());
|
||||
Q_UNUSED(vDesignator);
|
||||
QString telephony(inner.at(i++).toString());
|
||||
QString name(inner.at(i++).toString());
|
||||
QString countryIso(inner.at(i++).toString());
|
||||
QString country(inner.at(i++).toString());
|
||||
bool va = inner.at(i++).toString().startsWith("Y", Qt::CaseInsensitive); // VA
|
||||
void CAirlineIcaoCode::updateMissingParts(const CAirlineIcaoCode &otherIcaoCode)
|
||||
{
|
||||
if (!this->hasValidDesignator()) { this->setDesignator(otherIcaoCode.getDesignator()); }
|
||||
if (!this->hasValidCountry()) { this->setCountry(otherIcaoCode.getCountry()); }
|
||||
if (!this->hasName()) { this->setName(otherIcaoCode.getName()); }
|
||||
if (!this->hasTelephonyDesignator()) { this->setTelephonyDesignator(otherIcaoCode.getTelephonyDesignator()); }
|
||||
if (!this->hasValidDbKey())
|
||||
{
|
||||
this->setDbKey(otherIcaoCode.getDbKey());
|
||||
this->setUtcTimestamp(otherIcaoCode.getUtcTimestamp());
|
||||
}
|
||||
}
|
||||
|
||||
CAirlineIcaoCode CAirlineIcaoCode::fromDatabaseJson(const QJsonObject &json, const QString &prefix)
|
||||
{
|
||||
if (!existsKey(json, prefix))
|
||||
{
|
||||
// when using relationship, this can be null
|
||||
return CAirlineIcaoCode();
|
||||
}
|
||||
|
||||
QString designator(json.value(prefix + "designator").toString());
|
||||
QString telephony(json.value(prefix + "callsign").toString());
|
||||
QString name(json.value(prefix + "name").toString());
|
||||
QString countryIso(json.value(prefix + "country").toString());
|
||||
QString countryName(json.value(prefix + "countryname").toString());
|
||||
bool va = json.value(prefix + "va").toString().startsWith("Y", Qt::CaseInsensitive); // VA
|
||||
bool operating = json.value(prefix + "operating").toString().startsWith("Y", Qt::CaseInsensitive); // operating
|
||||
CAirlineIcaoCode code(
|
||||
designator, name, countryIso, country, telephony, va
|
||||
designator, name,
|
||||
CCountry(countryIso, countryName),
|
||||
telephony, va, operating
|
||||
);
|
||||
code.setDbKey(dbKey);
|
||||
code.setKeyAndTimestampFromDatabaseJson(json, prefix);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user