mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
refs #445, value objects and containers
* common base class for DB based classes * common base class for DB based containers * Livery, distributor value class * adjusted value classes to livery * utility functions for DB values (blackmisc free functions) * register new objects with metadata system
This commit is contained in:
committed by
Mathew Sutcliffe
parent
99b7c52383
commit
25fd0f4f2d
@@ -212,6 +212,8 @@ namespace BlackMisc
|
||||
return this->m_situation.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexIcao:
|
||||
return this->m_icao.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexLivery:
|
||||
return this->m_livery.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexParts:
|
||||
return this->m_parts.propertyByIndex(index.copyFrontRemoved());
|
||||
case IndexIsVtol:
|
||||
@@ -250,6 +252,9 @@ namespace BlackMisc
|
||||
case IndexIcao:
|
||||
this->m_icao.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||
break;
|
||||
case IndexLivery:
|
||||
this->m_livery.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||
break;
|
||||
case IndexSituation:
|
||||
this->m_situation.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||
break;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "blackmisc/aviation/transponder.h"
|
||||
#include "blackmisc/aviation/comsystem.h"
|
||||
#include "blackmisc/aviation/aircraftparts.h"
|
||||
#include "blackmisc/aviation/livery.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/namevariantpairlist.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
@@ -47,6 +48,7 @@ namespace BlackMisc
|
||||
IndexTransponder,
|
||||
IndexSituation,
|
||||
IndexIcao,
|
||||
IndexLivery,
|
||||
IndexParts,
|
||||
IndexIsVtol
|
||||
};
|
||||
@@ -93,6 +95,12 @@ namespace BlackMisc
|
||||
//! Set ICAO info
|
||||
virtual void setIcaoInfo(const CAircraftIcaoData &icao) { m_icao = icao; }
|
||||
|
||||
//! Get livery
|
||||
const BlackMisc::Aviation::CLivery &getLivery() const { return m_livery; }
|
||||
|
||||
//! Livery
|
||||
virtual void setLivery(const BlackMisc::Aviation::CLivery &livery) { this->m_livery = livery; }
|
||||
|
||||
//! Set aircraft ICAO designator
|
||||
virtual void setAircraftIcaoDesignator(const QString &designator) { m_icao.setAircraftDesignator(designator); }
|
||||
|
||||
@@ -289,6 +297,7 @@ namespace BlackMisc
|
||||
CAircraftParts m_parts;
|
||||
CSelcal m_selcal;
|
||||
CAircraftIcaoData m_icao;
|
||||
CLivery m_livery;
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
@@ -302,6 +311,7 @@ BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAircraft, (
|
||||
o.m_transponder,
|
||||
o.m_parts,
|
||||
o.m_icao,
|
||||
o.m_livery,
|
||||
o.m_distanceToOwnAircraft,
|
||||
o.m_bearingToOwnAircraft
|
||||
))
|
||||
|
||||
@@ -11,10 +11,12 @@
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
#include "blackmisc/datastoreutility.h"
|
||||
#include <tuple>
|
||||
#include <QRegularExpression>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
@@ -23,9 +25,9 @@ namespace BlackMisc
|
||||
m_designator(designator), m_combinedType(combinedType)
|
||||
{}
|
||||
|
||||
CAircraftIcaoCode::CAircraftIcaoCode(const QString &icao, const QString &combinedType, const QString &manufacturer, const QString &model, const QString &wtc, bool military, bool realworld, bool legacy)
|
||||
CAircraftIcaoCode::CAircraftIcaoCode(const QString &icao, const QString &combinedType, const QString &manufacturer, const QString &model, const QString &wtc, bool realworld, bool legacy, bool military)
|
||||
: m_designator(icao.trimmed().toUpper()), m_combinedType(combinedType.trimmed().toUpper()), m_manufacturer(manufacturer.trimmed()),
|
||||
m_modelDescription(model.trimmed()), m_wtc(wtc.trimmed().toUpper()), m_military(military), m_realworld(realworld), m_legacy(legacy)
|
||||
m_modelDescription(model.trimmed()), m_wtc(wtc.trimmed().toUpper()), m_realworld(realworld), m_legacy(legacy), m_military(military)
|
||||
{}
|
||||
|
||||
QString CAircraftIcaoCode::convertToQString(bool i18n) const
|
||||
@@ -77,9 +79,15 @@ namespace BlackMisc
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CAircraftIcaoCode::hasCompleteData() const
|
||||
{
|
||||
return hasCombinedType() && hasDesignator() && hasValidWtc();
|
||||
}
|
||||
|
||||
CVariant CAircraftIcaoCode::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::propertyByIndex(index); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
@@ -109,6 +117,7 @@ namespace BlackMisc
|
||||
void CAircraftIcaoCode::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CAircraftIcaoCode>(); return; }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { IDatastoreObjectWithIntegerKey::setPropertyByIndex(variant, index); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
@@ -156,24 +165,69 @@ namespace BlackMisc
|
||||
CAircraftIcaoCode CAircraftIcaoCode::fromDatabaseJson(const QJsonObject &json)
|
||||
{
|
||||
QJsonArray inner = json["cell"].toArray();
|
||||
Q_ASSERT_X(!inner.isEmpty(), Q_FUNC_INFO, "Missing JSON");
|
||||
if (inner.isEmpty()) { return CAircraftIcaoCode(); }
|
||||
QString combined(
|
||||
inner.at(4).toString() +
|
||||
inner.at(6).toString() +
|
||||
inner.at(5).toString()
|
||||
);
|
||||
|
||||
int i = 0;
|
||||
int dbKey(inner.at(i++).toInt(-1));
|
||||
QString designator(inner.at(i++).toString());
|
||||
QString manufacturer(inner.at(i++).toString());
|
||||
QString model(inner.at(i++).toString());
|
||||
QString type(inner.at(i++).toString());
|
||||
QString engine(inner.at(i++).toString());
|
||||
QString engineCount(inner.at(i++).toString());
|
||||
QString combined(createdCombinedString(type, engineCount, engine));
|
||||
QString wtc(inner.at(i++).toString());
|
||||
if (wtc.length() > 1 && wtc.contains("/"))
|
||||
{
|
||||
// "L/M" -> "M"
|
||||
wtc = wtc.right(1);
|
||||
}
|
||||
bool real = CDatastoreUtility::dbBoolStringToBool(inner.at(i++).toString());
|
||||
bool legacy = CDatastoreUtility::dbBoolStringToBool(inner.at(i++).toString());
|
||||
bool military = CDatastoreUtility::dbBoolStringToBool(inner.at(i++).toString());
|
||||
|
||||
Q_ASSERT_X(wtc.length() < 2, Q_FUNC_INFO, "WTC too long");
|
||||
|
||||
CAircraftIcaoCode code(
|
||||
inner.at(1).toString(),
|
||||
designator,
|
||||
combined,
|
||||
inner.at(2).toString(), // manufacturer
|
||||
inner.at(3).toString(), // model
|
||||
inner.at(7).toString(), // WTC
|
||||
false, // mil
|
||||
inner.at(8).toString().startsWith("Y"), // real
|
||||
inner.at(9).toString().startsWith("Y") // legacy
|
||||
manufacturer,
|
||||
model,
|
||||
wtc,
|
||||
real,
|
||||
legacy,
|
||||
military
|
||||
);
|
||||
code.setDbKey(dbKey);
|
||||
return code;
|
||||
}
|
||||
|
||||
QString CAircraftIcaoCode::createdCombinedString(const QString &type, const QString &engineCount, const QString &engine)
|
||||
{
|
||||
Q_ASSERT_X(engineCount.length() < 2, Q_FUNC_INFO, "Wrong engine count");
|
||||
|
||||
QString c(type.trimmed().toUpper().left(1));
|
||||
if (c.isEmpty()) { c.append("-"); }
|
||||
if (engineCount.isEmpty())
|
||||
{
|
||||
c.append("-");
|
||||
}
|
||||
else
|
||||
{
|
||||
c.append(engineCount);
|
||||
}
|
||||
if (engine.isEmpty())
|
||||
{
|
||||
c.append("-");
|
||||
}
|
||||
else
|
||||
{
|
||||
c.append(engine.left(1));
|
||||
}
|
||||
Q_ASSERT_X(c.length() == 3, Q_FUNC_INFO, "Wrong combined length");
|
||||
return c;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -16,13 +16,16 @@
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/datastore.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
//! Value object for ICAO classification
|
||||
class BLACKMISC_EXPORT CAircraftIcaoCode : public CValueObject<CAircraftIcaoCode>
|
||||
class BLACKMISC_EXPORT CAircraftIcaoCode :
|
||||
public CValueObject<CAircraftIcaoCode>,
|
||||
public BlackMisc::IDatastoreObjectWithIntegerKey
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
@@ -36,7 +39,7 @@ namespace BlackMisc
|
||||
IndexIsRealworld,
|
||||
IndexIsMilitary,
|
||||
IndexIsLegacy,
|
||||
IndexIsVtol
|
||||
IndexIsVtol,
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
@@ -47,7 +50,7 @@ namespace BlackMisc
|
||||
|
||||
//! Constructor
|
||||
CAircraftIcaoCode(const QString &icao, const QString &combinedType, const QString &manufacturer,
|
||||
const QString &model, const QString &wtc, bool military, bool realworld, bool legacy);
|
||||
const QString &model, const QString &wtc, bool realworld, bool legacy, bool military);
|
||||
|
||||
//! Get ICAO designator, e.g. "B737"
|
||||
const QString &getDesignator() const { return m_designator; }
|
||||
@@ -97,6 +100,9 @@ namespace BlackMisc
|
||||
//! Is VTOL aircraft (helicopter, tilt wing)
|
||||
bool isVtol() const;
|
||||
|
||||
//! All data set?
|
||||
bool hasCompleteData() const;
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
@@ -122,9 +128,12 @@ namespace BlackMisc
|
||||
QString m_manufacturer; //!< "Airbus"
|
||||
QString m_modelDescription; //!< "A-330-200"
|
||||
QString m_wtc; //!< wake turbulence "M","H" "L/M", "L"
|
||||
bool m_military = false;
|
||||
bool m_realworld = true; //!< real world aircraft
|
||||
bool m_legacy = false; //!< legacy code
|
||||
bool m_military = false; //!< military aircraft?
|
||||
|
||||
//! Create a combined string like L2J
|
||||
static QString createdCombinedString(const QString &type, const QString &engineCount, const QString &engine);
|
||||
|
||||
};
|
||||
} // namespace
|
||||
@@ -132,6 +141,7 @@ namespace BlackMisc
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CAircraftIcaoCode)
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAircraftIcaoCode, (
|
||||
o.m_dbKey,
|
||||
o.m_designator,
|
||||
o.m_combinedType,
|
||||
o.m_manufacturer,
|
||||
|
||||
@@ -18,12 +18,14 @@ namespace BlackMisc
|
||||
CSequence<CAircraftIcaoCode>(other)
|
||||
{ }
|
||||
|
||||
CAircraftIcaoCodeList CAircraftIcaoCodeList::fromDatabaseJson(const QJsonArray &array)
|
||||
CAircraftIcaoCodeList CAircraftIcaoCodeList::fromDatabaseJson(const QJsonArray &array, bool ignoreIncomplete)
|
||||
{
|
||||
CAircraftIcaoCodeList codes;
|
||||
for (const QJsonValue &value : array)
|
||||
{
|
||||
codes.push_back(CAircraftIcaoCode::fromDatabaseJson(value.toObject()));
|
||||
CAircraftIcaoCode icao(CAircraftIcaoCode::fromDatabaseJson(value.toObject()));
|
||||
if (ignoreIncomplete && !icao.hasCompleteData()) { continue; }
|
||||
codes.push_back(icao);
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace BlackMisc
|
||||
CAircraftIcaoCodeList(const CSequence<CAircraftIcaoCode> &other);
|
||||
|
||||
//! From our database JSON format
|
||||
static CAircraftIcaoCodeList fromDatabaseJson(const QJsonArray &array);
|
||||
static CAircraftIcaoCodeList fromDatabaseJson(const QJsonArray &array, bool ignoreIncomplete = true);
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
@@ -20,12 +20,12 @@ namespace BlackMisc
|
||||
namespace Aviation
|
||||
{
|
||||
|
||||
CAircraftIcaoData::CAircraftIcaoData(const QString &icao, const QString &airline)
|
||||
: m_aircraftIcao(icao), m_airlineIcao(airline)
|
||||
CAircraftIcaoData::CAircraftIcaoData(const QString &aircraftIcao, const QString &airlineIcao)
|
||||
: m_aircraftIcao(aircraftIcao), m_airlineIcao(airlineIcao)
|
||||
{}
|
||||
|
||||
CAircraftIcaoData::CAircraftIcaoData(const CAircraftIcaoCode &icaoAircraft, const CAirlineIcaoCode &icaoAirline, const QString &color)
|
||||
: m_aircraftIcao(icaoAircraft), m_airlineIcao(icaoAirline), m_aircraftColor(color)
|
||||
CAircraftIcaoData::CAircraftIcaoData(const CAircraftIcaoCode &aircraftIcao, const CAirlineIcaoCode &airlineIcao)
|
||||
: m_aircraftIcao(aircraftIcao), m_airlineIcao(airlineIcao)
|
||||
{}
|
||||
|
||||
QString CAircraftIcaoData::convertToQString(bool i18n) const
|
||||
@@ -33,8 +33,6 @@ namespace BlackMisc
|
||||
Q_UNUSED(i18n);
|
||||
QString s(this->m_aircraftIcao.toQString(i18n));
|
||||
s.append(" ").append(this->m_airlineIcao.toQString(i18n));
|
||||
if (this->hasLivery()) { s.append(" ").append(this->m_livery); }
|
||||
if (this->hasAircraftColor()) { s.append(" ").append(this->m_aircraftColor); }
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -47,11 +45,6 @@ namespace BlackMisc
|
||||
s.append(" (").append(this->getAirlineDesignator()).append(")");
|
||||
return s;
|
||||
}
|
||||
if (!this->m_aircraftColor.isEmpty())
|
||||
{
|
||||
s.append(" (").append(this->m_aircraftColor).append(")");
|
||||
return s;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -60,18 +53,14 @@ namespace BlackMisc
|
||||
if (!this->hasAircraftDesignator()) { this->setAircraftDesignator(icao.getAircraftDesignator()); }
|
||||
if (!this->hasAirlineDesignator()) { this->setAirlineDesignator(icao.getAirlineDesignator()); }
|
||||
if (!this->hasAircraftCombinedType()) { this->setAircraftCombinedType(icao.getAircraftCombinedType()); }
|
||||
if (this->m_aircraftColor.isEmpty()) { this->setAircraftColor(icao.getAircraftColor()); }
|
||||
if (this->m_livery.isEmpty()) { this->setLivery(icao.getLivery()); }
|
||||
}
|
||||
|
||||
bool CAircraftIcaoData::matchesWildcardIcao(const CAircraftIcaoData &otherIcao) const
|
||||
{
|
||||
if ((*this) == otherIcao) return true;
|
||||
if ((*this) == otherIcao) { return true; }
|
||||
if (otherIcao.hasAircraftDesignator() && otherIcao.getAircraftDesignator() != this->getAircraftDesignator()) { return false; }
|
||||
if (otherIcao.hasAirlineDesignator() && otherIcao.getAirlineDesignator() != this->getAirlineDesignator()) { return false; }
|
||||
if (otherIcao.hasAircraftCombinedType() && otherIcao.getAircraftCombinedType() != this->getAircraftCombinedType()) { return false; }
|
||||
if (otherIcao.hasLivery() && otherIcao.getLivery() != this->getLivery()) { return false; }
|
||||
if (otherIcao.hasAircraftColor() && otherIcao.getAircraftColor() != this->getAircraftColor()) { return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -85,8 +74,6 @@ namespace BlackMisc
|
||||
return CVariant::fromValue(this->m_aircraftIcao);
|
||||
case IndexAirlineIcao:
|
||||
return CVariant::fromValue(this->m_airlineIcao);
|
||||
case IndexAircraftColor:
|
||||
return CVariant::fromValue(this->m_aircraftColor);
|
||||
case IndexAsString:
|
||||
return CVariant::fromValue(this->asString());
|
||||
default:
|
||||
@@ -106,9 +93,6 @@ namespace BlackMisc
|
||||
case IndexAirlineIcao:
|
||||
this->m_airlineIcao.setPropertyByIndex(variant, index.copyFrontRemoved());
|
||||
break;
|
||||
case IndexAircraftColor:
|
||||
this->setAircraftColor(variant.value<QString>());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
//! Value object for ICAO classification (airline ICAO, aircraft ICAO, livery ..)
|
||||
//! Value object for ICAO classification (airline ICAO, aircraft ICAO)
|
||||
class BLACKMISC_EXPORT CAircraftIcaoData : public CValueObject<CAircraftIcaoData>
|
||||
{
|
||||
public:
|
||||
@@ -32,7 +32,6 @@ namespace BlackMisc
|
||||
{
|
||||
IndexAircraftIcao = BlackMisc::CPropertyIndex::GlobalIndexCAircraftIcaoData,
|
||||
IndexAirlineIcao,
|
||||
IndexAircraftColor,
|
||||
IndexAsString,
|
||||
};
|
||||
|
||||
@@ -40,12 +39,12 @@ namespace BlackMisc
|
||||
CAircraftIcaoData() = default;
|
||||
|
||||
//! Constructor.
|
||||
//! \param icao "B737"
|
||||
//! \param airline "DLH"
|
||||
CAircraftIcaoData(const QString &icao, const QString &airline = "");
|
||||
//! \param aircraftIcao "B737"
|
||||
//! \param airlineIcao "DLH"
|
||||
CAircraftIcaoData(const QString &aircraftIcao, const QString &airlineIcao = "");
|
||||
|
||||
//! Constructor.
|
||||
CAircraftIcaoData(const BlackMisc::Aviation::CAircraftIcaoCode &icaoAircraft, const BlackMisc::Aviation::CAirlineIcaoCode &icaoAirline, const QString &color = "");
|
||||
//! Constructor
|
||||
CAircraftIcaoData(const CAircraftIcaoCode &aircraftIcao, const CAirlineIcaoCode &airlineIcao);
|
||||
|
||||
//! Get ICAO designator, e.g. "B737"
|
||||
const QString &getAircraftDesignator() const { return m_aircraftIcao.getDesignator(); }
|
||||
@@ -77,27 +76,6 @@ namespace BlackMisc
|
||||
//! Airline and Aircraft designator?
|
||||
bool hasAircraftAndAirlineDesignator() const { return this->hasAirlineDesignator() && this->hasAircraftDesignator(); }
|
||||
|
||||
//! Get livery
|
||||
const QString &getLivery() const { return this->m_livery; }
|
||||
|
||||
//! Set livery
|
||||
void setLivery(const QString &livery) { this->m_livery = livery.trimmed().toUpper(); }
|
||||
|
||||
//! has livery?
|
||||
bool hasLivery() const { return !this->m_livery.isEmpty(); }
|
||||
|
||||
//! Get livery or color
|
||||
const QString &getLiveryOrColor() const { return this->hasLivery() ? this->m_livery : this->m_aircraftColor; }
|
||||
|
||||
//! Get color (RGB hex)
|
||||
const QString &getAircraftColor() const { return this->m_aircraftColor; }
|
||||
|
||||
//! Set color (RGB hex)
|
||||
void setAircraftColor(const QString &color) { this->m_aircraftColor = color.trimmed().toUpper(); }
|
||||
|
||||
//! Color available?
|
||||
bool hasAircraftColor() const { return !this->m_aircraftColor.isEmpty(); }
|
||||
|
||||
//! Get type, e.g. "L2J"
|
||||
const QString &getAircraftCombinedType() const { return this->m_aircraftIcao.getCombinedType(); }
|
||||
|
||||
@@ -136,8 +114,6 @@ namespace BlackMisc
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CAircraftIcaoData)
|
||||
BlackMisc::Aviation::CAircraftIcaoCode m_aircraftIcao; //!< "B737", ...
|
||||
BlackMisc::Aviation::CAirlineIcaoCode m_airlineIcao; //!< "DLH", ...
|
||||
QString m_livery;
|
||||
QString m_aircraftColor; //!< RGB Hex "330044"
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
@@ -145,9 +121,7 @@ namespace BlackMisc
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CAircraftIcaoData)
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAircraftIcaoData, (
|
||||
o.m_aircraftIcao,
|
||||
o.m_airlineIcao,
|
||||
o.m_livery,
|
||||
o.m_aircraftColor
|
||||
o.m_airlineIcao
|
||||
))
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
#include <tuple>
|
||||
#include <QRegularExpression>
|
||||
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
@@ -24,10 +27,21 @@ namespace BlackMisc
|
||||
: m_designator(airlineDesignator.trimmed().toUpper())
|
||||
{}
|
||||
|
||||
CAirlineIcaoCode::CAirlineIcaoCode(const QString &airlineDesignator, const QString &airlineName, const QString &country, const QString &telephony, bool virtualAirline)
|
||||
: m_designator(airlineDesignator), m_name(airlineName), m_country(country), m_telephonyDesignator(telephony), m_isVa(virtualAirline)
|
||||
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)
|
||||
{}
|
||||
|
||||
const QString CAirlineIcaoCode::getVDesignator() const
|
||||
{
|
||||
if (!isVirtualAirline()) { return this->m_designator; }
|
||||
return QString("V").append(this->m_designator);
|
||||
}
|
||||
|
||||
bool CAirlineIcaoCode::hasCompleteData() const
|
||||
{
|
||||
return this->hasDesignator() && this->hasCountryIso() && this->hasName();
|
||||
}
|
||||
|
||||
QString CAirlineIcaoCode::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
@@ -38,11 +52,14 @@ namespace BlackMisc
|
||||
CVariant CAirlineIcaoCode::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::propertyByIndex(index); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAirlineDesignator:
|
||||
return CVariant::fromValue(this->m_designator);
|
||||
case IndexAirlineCountryIso:
|
||||
return CVariant::fromValue(this->m_countryIso);
|
||||
case IndexAirlineCountry:
|
||||
return CVariant::fromValue(this->m_country);
|
||||
case IndexAirlineName:
|
||||
@@ -59,12 +76,16 @@ namespace BlackMisc
|
||||
void CAirlineIcaoCode::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CAirlineIcaoCode>(); return; }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { IDatastoreObjectWithIntegerKey::setPropertyByIndex(variant, index); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexAirlineDesignator:
|
||||
this->setDesignator(variant.value<QString>());
|
||||
break;
|
||||
case IndexAirlineCountryIso:
|
||||
this->setCountryIso(variant.value<QString>());
|
||||
break;
|
||||
case IndexAirlineCountry:
|
||||
this->setCountry(variant.value<QString>());
|
||||
break;
|
||||
@@ -92,15 +113,25 @@ namespace BlackMisc
|
||||
|
||||
CAirlineIcaoCode CAirlineIcaoCode::fromDatabaseJson(const QJsonObject &json)
|
||||
{
|
||||
// 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(); }
|
||||
|
||||
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
|
||||
CAirlineIcaoCode code(
|
||||
inner.at(1).toString(),
|
||||
inner.at(3).toString(), // name
|
||||
inner.at(4).toString(), // country
|
||||
inner.at(2).toString(), // telephony
|
||||
inner.at(5).toString().startsWith("Y") // VA
|
||||
designator, name, countryIso, country, telephony, va
|
||||
);
|
||||
code.setDbKey(dbKey);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKMISC_AVIATION_AIRLINEICAOCODE_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/datastore.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
@@ -22,7 +23,9 @@ namespace BlackMisc
|
||||
namespace Aviation
|
||||
{
|
||||
//! Value object for ICAO classification
|
||||
class BLACKMISC_EXPORT CAirlineIcaoCode : public CValueObject<CAirlineIcaoCode>
|
||||
class BLACKMISC_EXPORT CAirlineIcaoCode :
|
||||
public CValueObject<CAirlineIcaoCode>,
|
||||
public BlackMisc::IDatastoreObjectWithIntegerKey
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
@@ -30,6 +33,7 @@ namespace BlackMisc
|
||||
{
|
||||
IndexAirlineDesignator = BlackMisc::CPropertyIndex::GlobalIndexCAirlineIcaoCode,
|
||||
IndexAirlineName,
|
||||
IndexAirlineCountryIso,
|
||||
IndexAirlineCountry,
|
||||
IndexTelephonyDesignator,
|
||||
IndexIsVirtualAirline
|
||||
@@ -42,17 +46,26 @@ namespace BlackMisc
|
||||
CAirlineIcaoCode(const QString &airlineDesignator);
|
||||
|
||||
//! Constructor.
|
||||
CAirlineIcaoCode(const QString &airlineDesignator, const QString &airlineName, const QString &country, const QString &telephony, bool virtualAirline);
|
||||
CAirlineIcaoCode(const QString &airlineDesignator, const QString &airlineName, const QString &countryIso, const QString &country, const QString &telephony, bool virtualAirline);
|
||||
|
||||
//! Get airline, e.g. "DLH"
|
||||
const QString &getDesignator() const { return this->m_designator; }
|
||||
|
||||
//! Get airline, e.g. "DLH", but "VMVA" for virtual airlines
|
||||
const QString getVDesignator() const;
|
||||
|
||||
//! Set airline, e.g. "DLH"
|
||||
void setDesignator(const QString &icaoDesignator) { this->m_designator = icaoDesignator.trimmed().toUpper(); }
|
||||
|
||||
//! Get country, e.g. "France"
|
||||
//! Get country, e.g. "FR"
|
||||
const QString &getCountryIso() const { return this->m_countryIso; }
|
||||
|
||||
//! Get country, e.g. "FRANCE"
|
||||
const QString &getCountry() const { return this->m_country; }
|
||||
|
||||
//! Set country ISO
|
||||
void setCountryIso(const QString &country) { this->m_countryIso = country.trimmed().toUpper(); }
|
||||
|
||||
//! Set country
|
||||
void setCountry(const QString &country) { this->m_country = country.trimmed(); }
|
||||
|
||||
@@ -74,9 +87,21 @@ namespace BlackMisc
|
||||
//! Virtual airline
|
||||
void setVirtualAirline(bool va) { m_isVa = va; }
|
||||
|
||||
//! Country?
|
||||
bool hasCountryIso() const { return !this->m_countryIso.isEmpty(); }
|
||||
|
||||
//! Airline available?
|
||||
bool hasDesignator() const { return !this->m_designator.isEmpty(); }
|
||||
|
||||
//! Telephony designator?
|
||||
bool hasTelephonyDesignator() const { return !this->m_telephonyDesignator.isEmpty(); }
|
||||
|
||||
//! Has (airline) name?
|
||||
bool hasName() const { return !m_name.isEmpty(); }
|
||||
|
||||
//! Complete data
|
||||
bool hasCompleteData() const;
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
@@ -96,7 +121,8 @@ namespace BlackMisc
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CAirlineIcaoCode)
|
||||
QString m_designator; //!< "DLH"
|
||||
QString m_name; //!< "Lufthansa"
|
||||
QString m_country; //!< "Poland"
|
||||
QString m_countryIso; //!< "FR"
|
||||
QString m_country; //!< clear text, "Germany"
|
||||
QString m_telephonyDesignator; //!< "Speedbird"
|
||||
bool m_isVa = false;
|
||||
};
|
||||
@@ -105,8 +131,10 @@ namespace BlackMisc
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CAirlineIcaoCode)
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CAirlineIcaoCode, (
|
||||
o.m_dbKey,
|
||||
o.m_designator,
|
||||
o.m_name,
|
||||
o.m_countryIso,
|
||||
o.m_country,
|
||||
o.m_telephonyDesignator,
|
||||
o.m_isVa
|
||||
|
||||
@@ -17,12 +17,14 @@ namespace BlackMisc
|
||||
CSequence<CAirlineIcaoCode>(other)
|
||||
{ }
|
||||
|
||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::fromDatabaseJson(const QJsonArray &array)
|
||||
CAirlineIcaoCodeList CAirlineIcaoCodeList::fromDatabaseJson(const QJsonArray &array, bool ignoreIncomplete)
|
||||
{
|
||||
CAirlineIcaoCodeList codes;
|
||||
for (const QJsonValue &value : array)
|
||||
{
|
||||
codes.push_back(CAirlineIcaoCode::fromDatabaseJson(value.toObject()));
|
||||
CAirlineIcaoCode icao(CAirlineIcaoCode::fromDatabaseJson(value.toObject()));
|
||||
if (ignoreIncomplete && !icao.hasCompleteData()) { continue; }
|
||||
codes.push_back(icao);
|
||||
}
|
||||
return codes;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace BlackMisc
|
||||
CAirlineIcaoCodeList(const CSequence<CAirlineIcaoCode> &other);
|
||||
|
||||
//! From our DB JSON
|
||||
static CAirlineIcaoCodeList fromDatabaseJson(const QJsonArray &array);
|
||||
static CAirlineIcaoCodeList fromDatabaseJson(const QJsonArray &array, bool ignoreIncomplete = true);
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
@@ -37,18 +37,15 @@ namespace BlackMisc
|
||||
|
||||
QString CAirport::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s = i18n ?
|
||||
QCoreApplication::translate("Aviation", "Airport") :
|
||||
"Airport";
|
||||
if (!this->m_icao.isEmpty())
|
||||
s.append(' ').append(this->m_icao.toQString(i18n));
|
||||
QString s = i18n ? QCoreApplication::translate("Aviation", "Airport") : "Airport";
|
||||
if (!this->m_icao.isEmpty()) { s.append(' ').append(this->m_icao.toQString(i18n)); }
|
||||
|
||||
// position
|
||||
s.append(' ').append(this->m_position.toQString(i18n));
|
||||
return s;
|
||||
|
||||
// force strings for translation in resource files
|
||||
(void)QT_TRANSLATE_NOOP("Aviation", "ATC station");
|
||||
(void)QT_TRANSLATE_NOOP("Aviation", "Airport");
|
||||
}
|
||||
|
||||
CVariant CAirport::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / authors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
/* Copyright (C) 2013
|
||||
* 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 "blackmisc/aviation/airportlist.h"
|
||||
#include "blackmisc/predicates.h"
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
/* Copyright (C) 2013 VATSIM Community / contributors
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
/* Copyright (C) 2013
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef BLACKMISC_AVIATION_AVIATION_H
|
||||
#define BLACKMISC_AVIATION_AVIATION_H
|
||||
@@ -40,5 +44,7 @@
|
||||
#include "blackmisc/aviation/aircraftlights.h"
|
||||
#include "blackmisc/aviation/aircraftparts.h"
|
||||
#include "blackmisc/aviation/aircraftpartslist.h"
|
||||
#include "blackmisc/aviation/livery.h"
|
||||
#include "blackmisc/aviation/liverylist.h"
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -49,4 +49,6 @@ void BlackMisc::Aviation::registerMetadata()
|
||||
CAircraftLights::registerMetadata();
|
||||
CAircraftParts::registerMetadata();
|
||||
CAircraftPartsList::registerMetadata();
|
||||
CLivery::registerMetadata();
|
||||
CLiveryList::registerMetadata();
|
||||
}
|
||||
|
||||
143
src/blackmisc/aviation/livery.cpp
Normal file
143
src/blackmisc/aviation/livery.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
/* 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 "blackmisc/aviation/livery.h"
|
||||
#include "blackmisc/datastoreutility.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
using namespace BlackMisc::Geo;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
CLivery::CLivery()
|
||||
{ }
|
||||
|
||||
CLivery::CLivery(const QString &combinedCode, const CAirlineIcaoCode &airline, const QString &description, const QString &colorFuselage, const QString &colorTail, bool isMilitary) :
|
||||
CLivery(-1, combinedCode, airline, description, colorFuselage, colorTail, isMilitary)
|
||||
{ }
|
||||
|
||||
CLivery::CLivery(int dbKey, const QString &combinedCode, const CAirlineIcaoCode &airline, const QString &description, const QString &colorFuselage, const QString &colorTail, bool isMilitary) :
|
||||
m_dbKey(dbKey), m_airline(airline),
|
||||
m_combinedCode(combinedCode.trimmed().toUpper()), m_description(description.trimmed()),
|
||||
m_colorFuselage(normalizeHexColor(colorFuselage)), m_colorTail(normalizeHexColor(colorTail)),
|
||||
m_military(isMilitary)
|
||||
{ }
|
||||
|
||||
QString CLivery::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s(i18n ? QCoreApplication::translate("Aviation", "Livery") : "Livery");
|
||||
s.append(m_combinedCode);
|
||||
if (!this->m_description.isEmpty()) { s.append(' ').append(this->m_description); }
|
||||
if (!this->m_colorFuselage.isEmpty()) { s.append(" F: ").append(this->m_colorFuselage); }
|
||||
if (!this->m_colorTail.isEmpty()) { s.append(" T: ").append(this->m_colorTail); }
|
||||
if (this->isMilitary()) { s.append(" Military");}
|
||||
return s;
|
||||
|
||||
// force strings for translation in resource files
|
||||
(void)QT_TRANSLATE_NOOP("Aviation", "Livery");
|
||||
}
|
||||
|
||||
bool CLivery::hasCompleteData() const
|
||||
{
|
||||
return !m_description.isEmpty() && !m_combinedCode.isEmpty();
|
||||
}
|
||||
|
||||
CLivery CLivery::fromDatabaseJson(const QJsonObject &json)
|
||||
{
|
||||
QJsonArray inner = json["cell"].toArray();
|
||||
Q_ASSERT_X(!inner.isEmpty(), Q_FUNC_INFO, "Missing JSON");
|
||||
if (inner.isEmpty()) { return CLivery(); }
|
||||
|
||||
int i = 0;
|
||||
int dbKey = inner.at(i++).toInt(-1);
|
||||
QString code(inner.at(i++).toString());
|
||||
QString combinedCode(inner.at(i++).toString());
|
||||
QString airlineWithId(inner.at(i++).toString());
|
||||
QString airlineName(inner.at(i++).toString());
|
||||
QString description(inner.at(i++).toString());
|
||||
QString colorFuselage(normalizeHexColor(inner.at(i++).toString()));
|
||||
QString colorTail(normalizeHexColor(inner.at(i++).toString()));
|
||||
bool military = CDatastoreUtility::dbBoolStringToBool(inner.at(i++).toString());
|
||||
|
||||
int airlineId(CDatastoreUtility::extractIntegerKey(airlineWithId));
|
||||
CAirlineIcaoCode airline;
|
||||
airline.setDbKey(airlineId);
|
||||
airline.setName(airlineName);
|
||||
Q_ASSERT_X(code.length() > 0, Q_FUNC_INFO, "Missing code");
|
||||
Q_ASSERT_X(description.length() > 0, Q_FUNC_INFO, "require description");
|
||||
CLivery livery(dbKey, combinedCode, airline, description, colorFuselage, colorTail, military);
|
||||
return livery;
|
||||
}
|
||||
|
||||
QString CLivery::normalizeHexColor(const QString &color)
|
||||
{
|
||||
if (color.isEmpty()) { return ""; }
|
||||
QString c = color.trimmed().replace('#', "").toUpper();
|
||||
return c;
|
||||
}
|
||||
|
||||
CVariant CLivery::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { return IDatastoreObjectWithIntegerKey::propertyByIndex(index); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDescription:
|
||||
return CVariant::fromValue(m_description);
|
||||
case IndexColorFuselage:
|
||||
return CVariant::fromValue(this->m_colorFuselage);
|
||||
case IndexColorTail:
|
||||
return CVariant::fromValue(this->m_colorTail);
|
||||
case IndexCombinedCode:
|
||||
return CVariant::fromValue(this->m_combinedCode);
|
||||
case IndexIsMilitary:
|
||||
return CVariant::fromValue(this->m_military);
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CLivery::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CLivery>(); return; }
|
||||
if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { IDatastoreObjectWithIntegerKey::setPropertyByIndex(variant, index); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDescription:
|
||||
this->m_description = variant.toQString(false);
|
||||
break;
|
||||
case IndexColorFuselage:
|
||||
this->setColorFuselage(variant.toQString(false));
|
||||
break;
|
||||
case IndexColorTail:
|
||||
this->setColorTail(variant.toQString(false));
|
||||
break;
|
||||
case IndexCombinedCode:
|
||||
this->setCombinedCode(variant.toQString(false));
|
||||
break;
|
||||
case IndexIsMilitary:
|
||||
this->setMilitary(variant.toBool());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
124
src/blackmisc/aviation/livery.h
Normal file
124
src/blackmisc/aviation/livery.h
Normal file
@@ -0,0 +1,124 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_AVIATION_LIVERY_H
|
||||
#define BLACKMISC_AVIATION_LIVERY_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/aviation/airlineicaocode.h"
|
||||
#include "blackmisc/geo/coordinategeodetic.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/datastore.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
//! Value object encapsulating information about an airpot.
|
||||
class BLACKMISC_EXPORT CLivery :
|
||||
public CValueObject<CLivery>,
|
||||
public BlackMisc::IDatastoreObjectWithIntegerKey
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexDescription = BlackMisc::CPropertyIndex::GlobalIndexCLivery,
|
||||
IndexCombinedCode,
|
||||
IndexColorFuselage,
|
||||
IndexColorTail,
|
||||
IndexIsMilitary
|
||||
};
|
||||
|
||||
//! Default constructor.
|
||||
CLivery();
|
||||
|
||||
//! Constructor
|
||||
CLivery(const QString &combinedCode, const CAirlineIcaoCode &airline, const QString &description, const QString &colorFuselage, const QString &colorTail, bool isMilitary);
|
||||
|
||||
//! Constructor
|
||||
CLivery(int dbKey, const QString &combinedCode, const CAirlineIcaoCode &airline, const QString &description, const QString &colorFuselage, const QString &colorTail, bool isMilitary);
|
||||
|
||||
//! Corresponding airline, if any
|
||||
const CAirlineIcaoCode &getAirlineIcao() const { return m_airline; }
|
||||
|
||||
//! Combined code
|
||||
const QString &getCombinedCode() const { return m_combinedCode; }
|
||||
|
||||
//! Get description.
|
||||
const QString &getDescription() const { return m_description; }
|
||||
|
||||
//! Get fuselage color.
|
||||
const QString &getColorFuselage() const { return m_colorFuselage; }
|
||||
|
||||
//! Get tail color.
|
||||
const QString &getColorTails() const { return m_colorTail; }
|
||||
|
||||
//! Military livery
|
||||
bool isMilitary() const { return m_military; }
|
||||
|
||||
//! Airline ICAO code
|
||||
void setAirlineIcao(const CAirlineIcaoCode &airlineIcao) { m_airline = airlineIcao; }
|
||||
|
||||
//! Combined code
|
||||
void setCombinedCode(const QString &code) { m_combinedCode = code.trimmed().toUpper(); }
|
||||
|
||||
//! Set fuselage color
|
||||
void setColorFuselage(const QString &color) { this->m_colorFuselage = normalizeHexColor(color); }
|
||||
|
||||
//! Set tail color
|
||||
void setColorTail(const QString &color) { this->m_colorTail = normalizeHexColor(color); }
|
||||
|
||||
//! Military aircraft?
|
||||
void setMilitary(bool isMilitary) { this->m_military = isMilitary; }
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! Complete data?
|
||||
bool hasCompleteData() const;
|
||||
|
||||
//! Object from JSON
|
||||
static CLivery fromDatabaseJson(const QJsonObject &json);
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CLivery)
|
||||
int m_dbKey = -1; //!< optional DB key
|
||||
CAirlineIcaoCode m_airline; //!< corresponding airline, if any
|
||||
QString m_combinedCode; //!< livery code and pseudo airline ICAO code
|
||||
QString m_description;
|
||||
QString m_colorFuselage;
|
||||
QString m_colorTail;
|
||||
bool m_military = false; //! Military livery?
|
||||
|
||||
static QString normalizeHexColor(const QString &color);
|
||||
};
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CLivery, (
|
||||
attr(o.m_dbKey),
|
||||
attr(o.m_airline),
|
||||
attr(o.m_combinedCode, flags <CaseInsensitiveComparison> ()),
|
||||
attr(o.m_description),
|
||||
attr(o.m_colorFuselage, flags <CaseInsensitiveComparison> ()),
|
||||
attr(o.m_colorTail, flags <CaseInsensitiveComparison> ())
|
||||
))
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CLivery)
|
||||
|
||||
#endif // guard
|
||||
34
src/blackmisc/aviation/liverylist.cpp
Normal file
34
src/blackmisc/aviation/liverylist.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/* 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 "blackmisc/aviation/liverylist.h"
|
||||
#include "blackmisc/predicates.h"
|
||||
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
|
||||
CLiveryList::CLiveryList() { }
|
||||
|
||||
CLiveryList::CLiveryList(const CSequence<CLivery> &other) :
|
||||
CSequence<CLivery>(other)
|
||||
{ }
|
||||
|
||||
CLiveryList CLiveryList::findByCombinedCode(const QString &combinedCode) const
|
||||
{
|
||||
QString cc(combinedCode.trimmed().toUpper());
|
||||
if (cc.isEmpty()) { return CLiveryList();}
|
||||
return this->findBy(&CLivery::getCombinedCode, cc);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
50
src/blackmisc/aviation/liverylist.h
Normal file
50
src/blackmisc/aviation/liverylist.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_AVIATION_LIVERYLIST_H
|
||||
#define BLACKMISC_AVIATION_LIVERYLIST_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/datastoreobjectlist.h"
|
||||
|
||||
#include "blackmisc/aviation/livery.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
{
|
||||
//! Value object for a list of airports.
|
||||
class BLACKMISC_EXPORT CLiveryList :
|
||||
public CSequence<CLivery>,
|
||||
public BlackMisc::IDatastoreObjectListWithIntegerKey<CLivery, CLiveryList>,
|
||||
public BlackMisc::Mixin::MetaType<CLiveryList>
|
||||
{
|
||||
public:
|
||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CLiveryList)
|
||||
|
||||
//! Default constructor.
|
||||
CLiveryList();
|
||||
|
||||
//! Construct from a base class object.
|
||||
CLiveryList(const CSequence<CLivery> &other);
|
||||
|
||||
//! Find 0..n liveries by combined code
|
||||
CLiveryList findByCombinedCode(const QString &combinedCode) const;
|
||||
|
||||
};
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Aviation::CLiveryList)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Aviation::CLivery>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Aviation::CLivery>)
|
||||
|
||||
#endif //guard
|
||||
Reference in New Issue
Block a user