From 25fd0f4f2d6d1f7be8f316d16925f30aea3d735a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 10 Jul 2015 00:39:24 +0200 Subject: [PATCH] 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 --- src/blackmisc/aviation/aircraft.cpp | 5 + src/blackmisc/aviation/aircraft.h | 10 ++ src/blackmisc/aviation/aircrafticaocode.cpp | 84 ++++++++-- src/blackmisc/aviation/aircrafticaocode.h | 18 ++- .../aviation/aircrafticaocodelist.cpp | 6 +- src/blackmisc/aviation/aircrafticaocodelist.h | 2 +- src/blackmisc/aviation/aircrafticaodata.cpp | 26 +--- src/blackmisc/aviation/aircrafticaodata.h | 40 +---- src/blackmisc/aviation/airlineicaocode.cpp | 45 +++++- src/blackmisc/aviation/airlineicaocode.h | 36 ++++- .../aviation/airlineicaocodelist.cpp | 6 +- src/blackmisc/aviation/airlineicaocodelist.h | 2 +- src/blackmisc/aviation/airport.cpp | 9 +- src/blackmisc/aviation/airportlist.cpp | 12 +- src/blackmisc/aviation/aviation.h | 14 +- .../blackmiscfreefunctions_avmeta.cpp | 2 + src/blackmisc/aviation/livery.cpp | 143 ++++++++++++++++++ src/blackmisc/aviation/livery.h | 124 +++++++++++++++ src/blackmisc/aviation/liverylist.cpp | 34 +++++ src/blackmisc/aviation/liverylist.h | 50 ++++++ src/blackmisc/blackmiscfreefunctions.cpp | 72 ++------- src/blackmisc/blackmiscfreefunctions.h | 3 + .../blackmiscfreefunctions_simmeta.cpp | 6 + src/blackmisc/datastore.cpp | 94 ++++++++++++ src/blackmisc/datastore.h | 92 +++++++++++ src/blackmisc/datastoreobjectlist.cpp | 80 ++++++++++ src/blackmisc/datastoreobjectlist.h | 83 ++++++++++ src/blackmisc/datastoreutility.cpp | 31 ++++ src/blackmisc/datastoreutility.h | 40 +++++ src/blackmisc/network/aircraftmapping.h | 8 +- src/blackmisc/propertyindex.h | 9 +- src/blackmisc/simulation/aircraftmodel.cpp | 66 +++++++- src/blackmisc/simulation/aircraftmodel.h | 80 +++++++--- src/blackmisc/simulation/aircraftmodellist.h | 3 +- src/blackmisc/simulation/distributor.cpp | 95 ++++++++++++ src/blackmisc/simulation/distributor.h | 101 +++++++++++++ src/blackmisc/simulation/distributorlist.cpp | 24 +++ src/blackmisc/simulation/distributorlist.h | 50 ++++++ .../simulation/simulatedaircraft.cpp | 11 +- src/blackmisc/simulation/simulatedaircraft.h | 6 +- src/blackmisc/timestampobjectlist.cpp | 9 ++ src/blackmisc/timestampobjectlist.h | 16 ++ 42 files changed, 1447 insertions(+), 200 deletions(-) create mode 100644 src/blackmisc/aviation/livery.cpp create mode 100644 src/blackmisc/aviation/livery.h create mode 100644 src/blackmisc/aviation/liverylist.cpp create mode 100644 src/blackmisc/aviation/liverylist.h create mode 100644 src/blackmisc/datastore.cpp create mode 100644 src/blackmisc/datastore.h create mode 100644 src/blackmisc/datastoreobjectlist.cpp create mode 100644 src/blackmisc/datastoreobjectlist.h create mode 100644 src/blackmisc/datastoreutility.cpp create mode 100644 src/blackmisc/datastoreutility.h create mode 100644 src/blackmisc/simulation/distributor.cpp create mode 100644 src/blackmisc/simulation/distributor.h create mode 100644 src/blackmisc/simulation/distributorlist.cpp create mode 100644 src/blackmisc/simulation/distributorlist.h diff --git a/src/blackmisc/aviation/aircraft.cpp b/src/blackmisc/aviation/aircraft.cpp index d591ae845..e4421c1b4 100644 --- a/src/blackmisc/aviation/aircraft.cpp +++ b/src/blackmisc/aviation/aircraft.cpp @@ -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; diff --git a/src/blackmisc/aviation/aircraft.h b/src/blackmisc/aviation/aircraft.h index 644b4f17b..506da56fc 100644 --- a/src/blackmisc/aviation/aircraft.h +++ b/src/blackmisc/aviation/aircraft.h @@ -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 )) diff --git a/src/blackmisc/aviation/aircrafticaocode.cpp b/src/blackmisc/aviation/aircrafticaocode.cpp index 9d6f9fc4d..9d87c9099 100644 --- a/src/blackmisc/aviation/aircrafticaocode.cpp +++ b/src/blackmisc/aviation/aircrafticaocode.cpp @@ -11,10 +11,12 @@ #include "blackmisc/propertyindex.h" #include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/variant.h" - +#include "blackmisc/datastoreutility.h" #include #include +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(); switch (i) { @@ -109,6 +117,7 @@ namespace BlackMisc void CAircraftIcaoCode::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) { if (index.isMyself()) { (*this) = variant.to(); return; } + if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { IDatastoreObjectWithIntegerKey::setPropertyByIndex(variant, index); return; } ColumnIndex i = index.frontCasted(); 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 diff --git a/src/blackmisc/aviation/aircrafticaocode.h b/src/blackmisc/aviation/aircrafticaocode.h index 4fc910341..03e5b6c9b 100644 --- a/src/blackmisc/aviation/aircrafticaocode.h +++ b/src/blackmisc/aviation/aircrafticaocode.h @@ -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 + class BLACKMISC_EXPORT CAircraftIcaoCode : + public CValueObject, + 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, diff --git a/src/blackmisc/aviation/aircrafticaocodelist.cpp b/src/blackmisc/aviation/aircrafticaocodelist.cpp index e332c5ebc..390766190 100644 --- a/src/blackmisc/aviation/aircrafticaocodelist.cpp +++ b/src/blackmisc/aviation/aircrafticaocodelist.cpp @@ -18,12 +18,14 @@ namespace BlackMisc CSequence(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; } diff --git a/src/blackmisc/aviation/aircrafticaocodelist.h b/src/blackmisc/aviation/aircrafticaocodelist.h index 18b03f647..bc702d506 100644 --- a/src/blackmisc/aviation/aircrafticaocodelist.h +++ b/src/blackmisc/aviation/aircrafticaocodelist.h @@ -37,7 +37,7 @@ namespace BlackMisc CAircraftIcaoCodeList(const CSequence &other); //! From our database JSON format - static CAircraftIcaoCodeList fromDatabaseJson(const QJsonArray &array); + static CAircraftIcaoCodeList fromDatabaseJson(const QJsonArray &array, bool ignoreIncomplete = true); }; } //namespace diff --git a/src/blackmisc/aviation/aircrafticaodata.cpp b/src/blackmisc/aviation/aircrafticaodata.cpp index 921494d23..4e561c553 100644 --- a/src/blackmisc/aviation/aircrafticaodata.cpp +++ b/src/blackmisc/aviation/aircrafticaodata.cpp @@ -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()); - break; default: CValueObject::setPropertyByIndex(variant, index); break; diff --git a/src/blackmisc/aviation/aircrafticaodata.h b/src/blackmisc/aviation/aircrafticaodata.h index d06a7ce93..2e4a75487 100644 --- a/src/blackmisc/aviation/aircrafticaodata.h +++ b/src/blackmisc/aviation/aircrafticaodata.h @@ -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 { 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 diff --git a/src/blackmisc/aviation/airlineicaocode.cpp b/src/blackmisc/aviation/airlineicaocode.cpp index 099311420..b992d1d6f 100644 --- a/src/blackmisc/aviation/airlineicaocode.cpp +++ b/src/blackmisc/aviation/airlineicaocode.cpp @@ -15,6 +15,9 @@ #include #include + +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(); 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(); return; } + if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { IDatastoreObjectWithIntegerKey::setPropertyByIndex(variant, index); return; } ColumnIndex i = index.frontCasted(); switch (i) { case IndexAirlineDesignator: this->setDesignator(variant.value()); break; + case IndexAirlineCountryIso: + this->setCountryIso(variant.value()); + break; case IndexAirlineCountry: this->setCountry(variant.value()); 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; } diff --git a/src/blackmisc/aviation/airlineicaocode.h b/src/blackmisc/aviation/airlineicaocode.h index 64fb0ae56..8f21cdf63 100644 --- a/src/blackmisc/aviation/airlineicaocode.h +++ b/src/blackmisc/aviation/airlineicaocode.h @@ -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 + class BLACKMISC_EXPORT CAirlineIcaoCode : + public CValueObject, + 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 diff --git a/src/blackmisc/aviation/airlineicaocodelist.cpp b/src/blackmisc/aviation/airlineicaocodelist.cpp index 105c72bee..2250b27c8 100644 --- a/src/blackmisc/aviation/airlineicaocodelist.cpp +++ b/src/blackmisc/aviation/airlineicaocodelist.cpp @@ -17,12 +17,14 @@ namespace BlackMisc CSequence(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; } diff --git a/src/blackmisc/aviation/airlineicaocodelist.h b/src/blackmisc/aviation/airlineicaocodelist.h index 97537c151..60d436c53 100644 --- a/src/blackmisc/aviation/airlineicaocodelist.h +++ b/src/blackmisc/aviation/airlineicaocodelist.h @@ -37,7 +37,7 @@ namespace BlackMisc CAirlineIcaoCodeList(const CSequence &other); //! From our DB JSON - static CAirlineIcaoCodeList fromDatabaseJson(const QJsonArray &array); + static CAirlineIcaoCodeList fromDatabaseJson(const QJsonArray &array, bool ignoreIncomplete = true); }; } //namespace diff --git a/src/blackmisc/aviation/airport.cpp b/src/blackmisc/aviation/airport.cpp index 801ed680f..7c9b6d705 100644 --- a/src/blackmisc/aviation/airport.cpp +++ b/src/blackmisc/aviation/airport.cpp @@ -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 diff --git a/src/blackmisc/aviation/airportlist.cpp b/src/blackmisc/aviation/airportlist.cpp index 89e329624..0496c39e7 100644 --- a/src/blackmisc/aviation/airportlist.cpp +++ b/src/blackmisc/aviation/airportlist.cpp @@ -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" diff --git a/src/blackmisc/aviation/aviation.h b/src/blackmisc/aviation/aviation.h index 4ad1fb570..564b2e502 100644 --- a/src/blackmisc/aviation/aviation.h +++ b/src/blackmisc/aviation/aviation.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 diff --git a/src/blackmisc/aviation/blackmiscfreefunctions_avmeta.cpp b/src/blackmisc/aviation/blackmiscfreefunctions_avmeta.cpp index 66e786826..04fcdf896 100644 --- a/src/blackmisc/aviation/blackmiscfreefunctions_avmeta.cpp +++ b/src/blackmisc/aviation/blackmiscfreefunctions_avmeta.cpp @@ -49,4 +49,6 @@ void BlackMisc::Aviation::registerMetadata() CAircraftLights::registerMetadata(); CAircraftParts::registerMetadata(); CAircraftPartsList::registerMetadata(); + CLivery::registerMetadata(); + CLiveryList::registerMetadata(); } diff --git a/src/blackmisc/aviation/livery.cpp b/src/blackmisc/aviation/livery.cpp new file mode 100644 index 000000000..17b65d871 --- /dev/null +++ b/src/blackmisc/aviation/livery.cpp @@ -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(); + 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(); return; } + if (IDatastoreObjectWithIntegerKey::canHandleIndex(index)) { IDatastoreObjectWithIntegerKey::setPropertyByIndex(variant, index); return; } + ColumnIndex i = index.frontCasted(); + 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 diff --git a/src/blackmisc/aviation/livery.h b/src/blackmisc/aviation/livery.h new file mode 100644 index 000000000..d98363288 --- /dev/null +++ b/src/blackmisc/aviation/livery.h @@ -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, + 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 ()), + attr(o.m_description), + attr(o.m_colorFuselage, flags ()), + attr(o.m_colorTail, flags ()) + )) + +Q_DECLARE_METATYPE(BlackMisc::Aviation::CLivery) + +#endif // guard diff --git a/src/blackmisc/aviation/liverylist.cpp b/src/blackmisc/aviation/liverylist.cpp new file mode 100644 index 000000000..1dd897075 --- /dev/null +++ b/src/blackmisc/aviation/liverylist.cpp @@ -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 &other) : + CSequence(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 diff --git a/src/blackmisc/aviation/liverylist.h b/src/blackmisc/aviation/liverylist.h new file mode 100644 index 000000000..82e95a131 --- /dev/null +++ b/src/blackmisc/aviation/liverylist.h @@ -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, + public BlackMisc::IDatastoreObjectListWithIntegerKey, + public BlackMisc::Mixin::MetaType + { + public: + BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CLiveryList) + + //! Default constructor. + CLiveryList(); + + //! Construct from a base class object. + CLiveryList(const CSequence &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) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index f4fa2d6b0..05b6c1350 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -28,17 +28,11 @@ #include #include -/* - * Metadata for Math - */ void BlackMisc::Math::registerMetadata() { // void } -/* - * Metadata for Geo - */ void BlackMisc::Geo::registerMetadata() { CCoordinateGeodetic::registerMetadata(); @@ -46,9 +40,6 @@ void BlackMisc::Geo::registerMetadata() CLongitude::registerMetadata(); } -/* - * Metadata for Settings - */ void BlackMisc::Settings::registerMetadata() { CSettingsAudio::registerMetadata(); @@ -56,9 +47,6 @@ void BlackMisc::Settings::registerMetadata() CSettingKeyboardHotkeyList::registerMetadata(); } -/* - * Metadata for Audio - */ void BlackMisc::Audio::registerMetadata() { CAudioDeviceInfo::registerMetadata(); @@ -67,9 +55,6 @@ void BlackMisc::Audio::registerMetadata() CVoiceRoomList::registerMetadata(); } -/* - * Metadata for Hardware - */ void BlackMisc::Hardware::registerMetadata() { CKeyboardKey::registerMetadata(); @@ -77,17 +62,11 @@ void BlackMisc::Hardware::registerMetadata() CJoystickButton::registerMetadata(); } -/* - * Metadata for Event - */ void BlackMisc::Event::registerMetadata() { CEventHotkeyFunction::registerMetadata(); } -/* - * Metadata for Blackmisc - */ void BlackMisc::registerMetadata() { CPropertyIndex::registerMetadata(); @@ -128,17 +107,11 @@ void BlackMisc::registerMetadata() qDBusRegisterMetaType>(); } -/* - * Init resources - */ void BlackMisc::initResources() { initBlackMiscResources(); } -/* - * Add hash values - */ uint BlackMisc::calculateHash(const QList &values, const char *className) { // http://stackoverflow.com/questions/113511/hash-code-implementation/113600#113600 @@ -157,9 +130,6 @@ uint BlackMisc::calculateHash(const QList &values, const char *className) return hash; } -/* - * Add hash values - */ uint BlackMisc::calculateHash(const QList &values, const char *className) { QList list; @@ -181,9 +151,6 @@ uint BlackMisc::calculateHash(const QList &values, const char *className) } -/* - * Fix QVariant if it comes from DBus and contains QDBusArgument - */ QVariant BlackMisc::fixQVariantFromDbusArgument(const QVariant &variant, int localUserType) { // my business? @@ -212,9 +179,6 @@ QVariant BlackMisc::fixQVariantFromDbusArgument(const QVariant &variant, int loc } } -/* - * Return QVariant based on QDBusArgument - */ QVariant BlackMisc::complexQtTypeFromDbusArgument(const QDBusArgument &argument, int type) { // QDate = 14, QTime = 15, QDateTime = 16, QUrl = 17, @@ -251,9 +215,6 @@ QVariant BlackMisc::complexQtTypeFromDbusArgument(const QDBusArgument &argument, #ifdef Q_CC_MSVC #include -/* - * Heap size of an object - */ size_t BlackMisc::heapSizeOf(const QMetaType &metaType) { metaType.destroy(metaType.create()); // ignore one-off allocations of a class being instantiated for the first time @@ -268,9 +229,6 @@ size_t BlackMisc::heapSizeOf(const QMetaType &metaType) return diff.lSizes[_NORMAL_BLOCK]; } -/* - * Heap size of an object - */ size_t BlackMisc::heapSizeOf(const QMetaObject &metaObject) { delete metaObject.newInstance(); //ignore one-off allocations of a class being instantiated for the first time @@ -287,17 +245,12 @@ size_t BlackMisc::heapSizeOf(const QMetaObject &metaObject) #else //!Q_CC_MSVC -/* - * Heap size of an object - */ size_t BlackMisc::heapSizeOf(const QMetaType &) { qDebug() << "heapSizeOf not supported by your compiler toolchain"; return 0; } -/* - * Heap size of an object - */ + size_t BlackMisc::heapSizeOf(const QMetaObject &) { qDebug() << "heapSizeOf not supported by your compiler toolchain"; @@ -306,9 +259,6 @@ size_t BlackMisc::heapSizeOf(const QMetaObject &) #endif //!Q_CC_MSVC -/* - * Dump all user types - */ void BlackMisc::displayAllUserMetatypesTypes(QTextStream &out) { @@ -321,27 +271,18 @@ void BlackMisc::displayAllUserMetatypesTypes(QTextStream &out) } } -/* - * Local host name - */ const QString &BlackMisc::localHostName() { static const QString hostName = QHostInfo::localHostName(); return hostName; } -/* - * Local host name - */ const QString &BlackMisc::localHostNameEnvVariable() { static const QString hostName = QProcessEnvironment::systemEnvironment().value("COMPUTERNAME", QProcessEnvironment::systemEnvironment().value("HOSTNAME")); return hostName; } -/* - * Window mixer - */ bool BlackMisc::Audio::startWindowsMixer() { QStringList parameterlist; @@ -405,3 +346,14 @@ QString BlackMisc::boolToTrueFalse(bool v, bool i18n) Q_UNUSED(i18n); return v ? "true" : "false"; } + +bool BlackMisc::stringToBool(const QString &string) +{ + if (string.isEmpty()) { return false; } + QChar c = string.at(0).toLower(); + + // explicit values + if (c == '1' || c == 't' || c == 'y' || c == 'x') { return true; } + if (c == '0' || c == 'f' || c == 'n' || c == ' ') { return false; } + return false; +} diff --git a/src/blackmisc/blackmiscfreefunctions.h b/src/blackmisc/blackmiscfreefunctions.h index c6548d7fc..70eb18a16 100644 --- a/src/blackmisc/blackmiscfreefunctions.h +++ b/src/blackmisc/blackmiscfreefunctions.h @@ -300,6 +300,9 @@ namespace BlackMisc //! Bool to true / false BLACKMISC_EXPORT QString boolToTrueFalse(bool v, bool i18n = false); + //! Convert string to bool + BLACKMISC_EXPORT bool stringToBool(const QString &boolString); + //! Get local host name BLACKMISC_EXPORT const QString &localHostName(); diff --git a/src/blackmisc/blackmiscfreefunctions_simmeta.cpp b/src/blackmisc/blackmiscfreefunctions_simmeta.cpp index 486356343..6824bc0d1 100644 --- a/src/blackmisc/blackmiscfreefunctions_simmeta.cpp +++ b/src/blackmisc/blackmiscfreefunctions_simmeta.cpp @@ -11,9 +11,11 @@ #include "blackmisc/simulation/simulatedaircraftlist.h" #include "blackmisc/simulation/simulatorplugininfolist.h" #include "blackmisc/simulation/airspaceaircraftsnapshot.h" +#include "blackmisc/simulation/distributorlist.h" #include "blackmisc/simulation/simulatorsetup.h" #include "blackmisc/simulation/fsx/simconnectutilities.h" #include "blackmisc/simulation/fscommon/aircraftcfgentrieslist.h" +#include "blackmisc/simulation/fscommon/vpilotmodelruleset.h" using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::Fsx; @@ -36,6 +38,10 @@ void BlackMisc::Simulation::registerMetadata() CAircraftModelList::registerMetadata(); CSimulatedAircraft::registerMetadata(); CSimulatedAircraftList::registerMetadata(); + CDistributor::registerMetadata(); + CDistributorList::registerMetadata(); + CVPilotModelRule::registerMetadata(); + CVPilotModelRuleSet::registerMetadata(); CSimulatorSetup::registerMetadata(); CAirspaceAircraftSnapshot::registerMetadata(); } diff --git a/src/blackmisc/datastore.cpp b/src/blackmisc/datastore.cpp new file mode 100644 index 000000000..b94941da7 --- /dev/null +++ b/src/blackmisc/datastore.cpp @@ -0,0 +1,94 @@ +/* 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/datastore.h" +#include "blackmisc/blackmiscfreefunctions.h" + +namespace BlackMisc +{ + + CVariant IDatastoreObjectWithIntegerKey::propertyByIndex(const CPropertyIndex &index) const + { + if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexDbIntergerKey: return CVariant::from(this->m_dbKey); + default: + break; + } + return CVariant(); + } + + void IDatastoreObjectWithIntegerKey::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index) + { + if (ITimestampBased::canHandleIndex(index)) + { + ITimestampBased::setPropertyByIndex(variant, index); + return; + } + + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexDbIntergerKey: + this->m_dbKey = variant.toInt(); + break; + default: + break; + } + } + + bool IDatastoreObjectWithIntegerKey::canHandleIndex(const BlackMisc::CPropertyIndex &index) + { + if (ITimestampBased::canHandleIndex(index)) { return true;} + int i = index.frontCasted(); + return (i >= static_cast(IndexDbIntergerKey)) && (i <= static_cast(IndexDbIntergerKey)); + } + + CVariant IDatastoreObjectWithStringKey::propertyByIndex(const CPropertyIndex &index) const + { + if (ITimestampBased::canHandleIndex(index)) { return ITimestampBased::propertyByIndex(index); } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexDbStringKey: return CVariant::from(this->m_dbKey); + default: + break; + } + return CVariant(); + } + + void IDatastoreObjectWithStringKey::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index) + { + if (ITimestampBased::canHandleIndex(index)) + { + ITimestampBased::setPropertyByIndex(variant, index); + return; + } + + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexDbStringKey: + this->m_dbKey = variant.value(); + break; + default: + break; + } + } + + bool IDatastoreObjectWithStringKey::canHandleIndex(const CPropertyIndex &index) + { + if (ITimestampBased::canHandleIndex(index)) { return true;} + int i = index.frontCasted(); + return (i >= static_cast(IndexDbStringKey)) && (i <= static_cast(IndexDbStringKey)); + } + +} // namespace diff --git a/src/blackmisc/datastore.h b/src/blackmisc/datastore.h new file mode 100644 index 000000000..d124dae89 --- /dev/null +++ b/src/blackmisc/datastore.h @@ -0,0 +1,92 @@ +/* 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_DATASTORE_H +#define BLACKMISC_DATASTORE_H + +#include "blackmiscexport.h" +#include "timestampbased.h" +#include "propertyindex.h" +#include "variant.h" + +namespace BlackMisc +{ + /*! + * Class from which a derived class can inherit datastore-related functions. + */ + class IDatastoreObjectWithIntegerKey : public ITimestampBased + { + public: + //! Property index + enum ColumnIndex + { + IndexDbIntergerKey = CPropertyIndex::GlobalIndexIDatastoreInteger + }; + + //! Get DB key. + int getDbKey() const { return m_dbKey; } + + //! Set the DB key + void setDbKey(int key) { m_dbKey = key; } + + //! Has valid DB key + bool hasValidDbKey() const { return m_dbKey >= 0; } + + protected: + //! \copydoc CValueObject::propertyByIndex + CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc CValueObject::setPropertyByIndex + void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index); + + //! Can given index be handled? + static bool canHandleIndex(const BlackMisc::CPropertyIndex &index); + + int m_dbKey = -1; //!< key + }; + + /*! + * Class from which a derived class can inherit datastore-related functions. + */ + class IDatastoreObjectWithStringKey : public ITimestampBased + { + public: + //! Property index + enum ColumnIndex + { + IndexDbStringKey = CPropertyIndex::GlobalIndexIDatastoreString + }; + + //! Get DB key. + const QString &getDbKey() const { return m_dbKey; } + + //! Set the DB key + void setDbKey(const QString &key) { m_dbKey = key.trimmed().toUpper(); } + + //! Has valid DB key + bool hasValidDbKey() const { return !m_dbKey.isEmpty(); } + + protected: + //! \copydoc CValueObject::propertyByIndex + CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc CValueObject::setPropertyByIndex + void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index); + + //! Can given index be handled + static bool canHandleIndex(const BlackMisc::CPropertyIndex &index); + + QString m_dbKey; //!< key + }; + +} // namespace + +#endif // guard diff --git a/src/blackmisc/datastoreobjectlist.cpp b/src/blackmisc/datastoreobjectlist.cpp new file mode 100644 index 000000000..f1e743537 --- /dev/null +++ b/src/blackmisc/datastoreobjectlist.cpp @@ -0,0 +1,80 @@ +/* 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/datastoreobjectlist.h" +#include "blackmisc/predicates.h" +#include "blackmisc/aviation/liverylist.h" +#include "blackmisc/simulation/aircraftmodellist.h" +#include "blackmisc/simulation/distributorlist.h" +#include +#include + +namespace BlackMisc +{ + template + IDatastoreObjectListWithIntegerKey::IDatastoreObjectListWithIntegerKey() + { } + + template + IDatastoreObjectListWithStringKey::IDatastoreObjectListWithStringKey() + { } + + template + OBJ IDatastoreObjectListWithIntegerKey::findByKey(int key, const OBJ ¬Found ) const + { + return this->container().findFirstByOrDefault(&OBJ::getDbKey, key, notFound); + } + + template + OBJ IDatastoreObjectListWithStringKey::findByKey(const QString &key, const OBJ ¬Found) const + { + return this->container().findFirstByOrDefault(&OBJ::getDbKey, key, notFound); + } + + template + void IDatastoreObjectListWithIntegerKey::sortByKey() + { + this->container().sort(BlackMisc::Predicates::MemberLess(&OBJ::getDbKey)); + } + + template + void IDatastoreObjectListWithStringKey::sortByKey() + { + this->container().sort(BlackMisc::Predicates::MemberLess(&OBJ::getDbKey)); + } + + template + CONTAINER IDatastoreObjectListWithIntegerKey::fromDatabaseJson(const QJsonArray &array) + { + CONTAINER container; + for (const QJsonValue &value : array) + { + container.push_back(OBJ::fromDatabaseJson(value.toObject())); + } + return container; + } + + template + CONTAINER IDatastoreObjectListWithStringKey::fromDatabaseJson(const QJsonArray &array) + { + CONTAINER container; + for (const QJsonValue &value : array) + { + container.push_back(OBJ::fromDatabaseJson(value.toObject())); + } + return container; + } + + // see here for the reason of thess forward instantiations + // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html + template class IDatastoreObjectListWithIntegerKey; + template class IDatastoreObjectListWithIntegerKey; + template class IDatastoreObjectListWithStringKey; + +} // namespace diff --git a/src/blackmisc/datastoreobjectlist.h b/src/blackmisc/datastoreobjectlist.h new file mode 100644 index 000000000..4aa5e2c7f --- /dev/null +++ b/src/blackmisc/datastoreobjectlist.h @@ -0,0 +1,83 @@ +/* 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_DATABASEOBJECTLIST_H +#define BLACKMISC_DATABASEOBJECTLIST_H + +#include "blackmisc/timestampobjectlist.h" +#include "blackmisc/collection.h" +#include "blackmisc/sequence.h" +#include +#include + +namespace BlackMisc +{ + //! List of objects read from database. + //! Such objects should implement \sa ITimestampBased and \sa IDatastoreObjectWithIntegerKey + template class IDatastoreObjectListWithIntegerKey : public ITimestampObjectList + { + public: + //! Object with key, notFound otherwise + OBJ findByKey(int key, const OBJ ¬Found = OBJ()) const; + + //! Sort by timestamp + void sortByKey(); + + //! From DB JSON + static CONTAINER fromDatabaseJson(const QJsonArray &array); + + protected: + //! Constructor + IDatastoreObjectListWithIntegerKey(); + }; + + //! List of objects read from database. + //! Such objects should implement \sa ITimestampBased and \sa IDatastoreObjectWithString + template class IDatastoreObjectListWithStringKey : public ITimestampObjectList + { + public: + //! Object with key, not found otherwise + OBJ findByKey(const QString &key, const OBJ ¬Found = OBJ()) const; + + //! Sort by timestamp + void sortByKey(); + + //! From DB JSON + static CONTAINER fromDatabaseJson(const QJsonArray &array); + + protected: + //! Constructor + IDatastoreObjectListWithStringKey(); + }; + + //! \cond PRIVATE + namespace Aviation + { + class CLivery; + class CLiveryList; + } + + namespace Simulation + { + class CDistributor; + class CDistributorList; + class CAircraftModel; + class CAircraftModelList; + } + + extern template class BLACKMISC_EXPORT_TEMPLATE IDatastoreObjectListWithIntegerKey; + extern template class BLACKMISC_EXPORT_TEMPLATE IDatastoreObjectListWithIntegerKey; + extern template class BLACKMISC_EXPORT_TEMPLATE IDatastoreObjectListWithStringKey; + //! \endcond + +} //namespace + +#endif //guard diff --git a/src/blackmisc/datastoreutility.cpp b/src/blackmisc/datastoreutility.cpp new file mode 100644 index 000000000..237dde8ca --- /dev/null +++ b/src/blackmisc/datastoreutility.cpp @@ -0,0 +1,31 @@ +/* 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/datastoreutility.h" +#include "blackmisc/blackmiscfreefunctions.h" + +namespace BlackMisc +{ + bool CDatastoreUtility::dbBoolStringToBool(const QString &dbBool) + { + return BlackMisc::stringToBool(dbBool); + } + + int CDatastoreUtility::extractIntegerKey(const QString &stringWithKey) + { + int i1 = stringWithKey.lastIndexOf('('); + if (i1 < 0) { return -1; } + int i2 = stringWithKey.lastIndexOf(')'); + if (i2 <= i1 + 1) { return -1;} + QString n(stringWithKey.mid(i1 + 1, i2 - i1 - 1)); + bool ok = false; + int key = n.toInt(&ok); + return ok ? key : -1; + } +} // namespace diff --git a/src/blackmisc/datastoreutility.h b/src/blackmisc/datastoreutility.h new file mode 100644 index 000000000..bf6818e51 --- /dev/null +++ b/src/blackmisc/datastoreutility.h @@ -0,0 +1,40 @@ +/* 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_DATASTOREUTILITY_H +#define BLACKMISC_DATASTOREUTILITY_H + +#include "blackmiscexport.h" +#include "timestampbased.h" +#include "propertyindex.h" +#include "variant.h" + +namespace BlackMisc +{ + /*! + * Class with datastore related utilities + */ + class CDatastoreUtility + { + public: + //! No constructor + CDatastoreUtility() = delete; + + //! DB Bool value to bool + static bool dbBoolStringToBool(const QString &dbBool); + + //! Extract key from string like "MyAircraft (33)" + static int extractIntegerKey(const QString &stringWithKey); + }; + +} // namespace + +#endif // guard diff --git a/src/blackmisc/network/aircraftmapping.h b/src/blackmisc/network/aircraftmapping.h index 0a5a5a3b8..8a99ad5e8 100644 --- a/src/blackmisc/network/aircraftmapping.h +++ b/src/blackmisc/network/aircraftmapping.h @@ -71,10 +71,10 @@ namespace BlackMisc private: BLACK_ENABLE_TUPLE_CONVERSION(CAircraftMapping) - QString m_source; //!< source, e.g. database, vPilot - QString m_packageName; //!< something like WoA, .. - BlackMisc::Aviation::CAircraftIcaoData m_icao; //!< ICAO code - BlackMisc::Simulation::CAircraftModel m_model; //!< aircraft model + QString m_source; //!< source, e.g. database, vPilot + QString m_packageName; //!< something like WoA, .. + BlackMisc::Aviation::CAircraftIcaoData m_icao; //!< ICAO code + BlackMisc::Simulation::CAircraftModel m_model; //!< aircraft model // BlackMisc::Simulation::CSimulatorPluginInfo m_simulatorInfo; //!< Mapping is for simulator }; diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index d92903155..bbd32e2bc 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -45,7 +45,7 @@ namespace BlackMisc //! Global index, make sure the indexes are unqiue (for using them in class hierarchy) enum GlobalIndex { - GlobalIndexCValueObject = 10, // GlobalIndexCValueObject needs to be set manually in CValueObject + GlobalIndexCValueObject = 10, // avoid circular dependencies, GlobalIndexCValueObject needs to be set manually in CValueObject GlobalIndexCPhysicalQuantity = 100, GlobalIndexCStatusMessage = 200, GlobalIndexCNameVariantPair = 300, @@ -58,6 +58,7 @@ namespace BlackMisc GlobalIndexCAirport = 1400, GlobalIndexCAircraftParts = 1500, GlobalIndexCAircraftLights = 1600, + GlobalIndexCLivery = 1700, GlobalIndexCModulator = 2000, GlobalIndexCTransponder = 2100, GlobalIndexCAircraftIcaoData = 2500, @@ -75,9 +76,13 @@ namespace BlackMisc GlobalIndexCTextMessage = 4600, GlobalIndexCSimulatorSetup = 4700, GlobalIndexCAircraftCfgEntries = 4800, + GlobalIndexCDistributor = 4900, + GlobalIndexVPilotModelRule = 5000, GlobalIndexCVoiceRoom = 6000, GlobalIndexCSettingKeyboardHotkey = 7000, - GlobalIndexAbuseMode = 20000 // property index abused as map key or otherwise, do be removed if no longer needed + GlobalIndexIDatastoreInteger = 8000, + GlobalIndexIDatastoreString = 8100, + GlobalIndexAbuseMode = 20000 // property index abused as map key or otherwise, to be removed if no longer needed }; //! Default constructor. diff --git a/src/blackmisc/simulation/aircraftmodel.cpp b/src/blackmisc/simulation/aircraftmodel.cpp index 8628cf697..614af8523 100644 --- a/src/blackmisc/simulation/aircraftmodel.cpp +++ b/src/blackmisc/simulation/aircraftmodel.cpp @@ -8,14 +8,26 @@ */ #include "aircraftmodel.h" +#include "distributor.h" +#include "blackmisc/datastoreutility.h" #include +using namespace BlackMisc::Aviation; + namespace BlackMisc { namespace Simulation { + CAircraftModel::CAircraftModel(const QString &model, CAircraftModel::ModelType type) : + m_modelString(model), m_modelType(type) + {} + + CAircraftModel::CAircraftModel(const QString &model, CAircraftModel::ModelType type, const QString &description, const Aviation::CAircraftIcaoData &icao, const Aviation::CLivery &livery) : + m_icao(icao), m_livery(livery), m_modelString(model), m_description(description), m_modelType(type) + {} + CAircraftModel::CAircraftModel(const Aviation::CAircraft &aircraft) : - m_callsign(aircraft.getCallsign()), m_icao(aircraft.getIcaoInfo()) + m_callsign(aircraft.getCallsign()), m_icao(aircraft.getIcaoInfo()), m_livery(aircraft.getLivery()) { } QString CAircraftModel::convertToQString(bool i18n) const @@ -44,7 +56,7 @@ namespace BlackMisc case IndexHasQueriedModelString: return CVariant::fromValue(this->hasQueriedModelString()); case IndexModelType: - return CVariant::fromValue(this->m_modelType); + return CVariant::fromValue(static_cast(this->m_modelType)); case IndexModelTypeAsString: return CVariant(this->getModelTypeAsString()); case IndexDescription: @@ -53,6 +65,8 @@ namespace BlackMisc return CVariant(this->m_fileName); case IndexIcao: return m_icao.propertyByIndex(index.copyFrontRemoved()); + case IndexLivery: + return m_livery.propertyByIndex(index.copyFrontRemoved()); case IndexCallsign: return m_callsign.propertyByIndex(index.copyFrontRemoved()); default: @@ -72,6 +86,9 @@ namespace BlackMisc case IndexIcao: this->m_icao.setPropertyByIndex(variant, index.copyFrontRemoved()); break; + case IndexLivery: + this->m_livery.setPropertyByIndex(variant, index.copyFrontRemoved()); + break; case IndexDescription: this->m_description = variant.toQString(); break; @@ -82,7 +99,7 @@ namespace BlackMisc this->m_fileName = variant.toQString(); break; case IndexModelType: - this->m_modelType = variant.toInt(); + this->m_modelType = static_cast(variant.toInt()); break; default: CValueObject::setPropertyByIndex(variant, index); @@ -90,6 +107,16 @@ namespace BlackMisc } } + const CAircraftIcaoCode &CAircraftModel::getAircraftIcaoCode() const + { + return m_icao.getAircraftIcaoCode(); + } + + const CAirlineIcaoCode &CAircraftModel::getAirlineIcaoCode() const + { + return m_icao.getAirlineIcaoCode(); + } + void CAircraftModel::updateMissingParts(const CAircraftModel &model) { if (this->m_modelString.isEmpty()) { this->m_modelString = model.getModelString(); } @@ -138,5 +165,38 @@ namespace BlackMisc } } + CAircraftModel CAircraftModel::fromDatabaseJson(const QJsonObject &json) + { + QJsonArray inner = json["cell"].toArray(); + Q_ASSERT_X(!inner.isEmpty(), Q_FUNC_INFO, "Missing JSON"); + if (inner.isEmpty()) { return CAircraftModel(); } + + // int i = 0; + + int i = 0; + int dbKey(inner.at(i++).toInt(-1)); + QString modelString(inner.at(i++).toString()); + QString distributorKey(inner.at(i++).toString()); + QString liveryDescription(inner.at(i++).toString()); + QString modelDescription; + + CAircraftIcaoData aircraftIcao; + CAirlineIcaoCode airlineIcao; + CLivery livery; + CDistributor distributor(distributorKey, "", "", ""); + + bool fsx = CDatastoreUtility::dbBoolStringToBool(inner.at(i++).toString()); + bool fs9 = CDatastoreUtility::dbBoolStringToBool(inner.at(i++).toString()); + bool xp = CDatastoreUtility::dbBoolStringToBool(inner.at(i++).toString()); + CSimulatorInfo simInfo(fsx, fs9, xp); + + CAircraftModel model( + modelString, CAircraftModel::TypeModelMapping, modelDescription, aircraftIcao, livery + ); + model.setDbKey(dbKey); + model.setSimulatorInfo(simInfo); + return model; + } + } // namespace } // namespace diff --git a/src/blackmisc/simulation/aircraftmodel.h b/src/blackmisc/simulation/aircraftmodel.h index d4013da30..eb0bc5285 100644 --- a/src/blackmisc/simulation/aircraftmodel.h +++ b/src/blackmisc/simulation/aircraftmodel.h @@ -13,8 +13,10 @@ #define BLACKMISC_SIMULATION_AIRCRAFTMODEL_H #include "blackmisc/blackmiscexport.h" +#include "blackmisc/simulation/simulatorinfo.h" #include "blackmisc/aviation/aircraft.h" #include "blackmisc/aviation/aircrafticaodata.h" +#include "blackmisc/aviation/livery.h" #include "blackmisc/network/user.h" #include "blackmisc/propertyindex.h" @@ -22,21 +24,23 @@ namespace BlackMisc { namespace Simulation { - //! Aircraft model (other pilot, my models on disk) + //! Aircraft model (used by another pilot, my models on disk) //! \remarks Simulator independent class, supposed to be common denominator - class BLACKMISC_EXPORT CAircraftModel : public CValueObject + class BLACKMISC_EXPORT CAircraftModel : + public CValueObject, + public BlackMisc::IDatastoreObjectWithIntegerKey { public: //! Model type enum ModelType { TypeUnknown, - TypeQueriedFromNetwork, //!< model was queried by network protocol - TypeModelMatching, //!< model is result of model matching + TypeQueriedFromNetwork, //!< model was queried by network protocol + TypeModelMatching, //!< model is result of model matching TypeModelMatchingDefaultModel, //!< a default model assigned by model matching - TypeModelMapping, //!< used along with mapping definition - TypeManuallySet, //!< manually set, e.g. from GUI - TypeOwnSimulatorModel //!< represents own simulator model + TypeModelMapping, //!< used along with mapping definition + TypeManuallySet, //!< manually set, e.g. from GUI + TypeOwnSimulatorModel //!< represents own simulator model }; //! Indexes @@ -46,6 +50,7 @@ namespace BlackMisc IndexCallsign, IndexDescription, IndexIcao, + IndexLivery, IndexFileName, IndexModelType, IndexModelTypeAsString, @@ -56,11 +61,10 @@ namespace BlackMisc CAircraftModel() {} //! Constructor. - CAircraftModel(const QString &model, ModelType type) : m_modelString(model), m_modelType(type) {} + CAircraftModel(const QString &model, ModelType type); //! Constructor. - CAircraftModel(const QString &model, ModelType type, const QString &description, const BlackMisc::Aviation::CAircraftIcaoData &icao) : - m_icao(icao), m_modelString(model), m_description(description), m_modelType(type) {} + CAircraftModel(const QString &model, ModelType type, const QString &description, const BlackMisc::Aviation::CAircraftIcaoData &icao, const BlackMisc::Aviation::CLivery &livery = BlackMisc::Aviation::CLivery()); //! Constructor CAircraftModel(const BlackMisc::Aviation::CAircraft &aircraft); @@ -80,7 +84,7 @@ namespace BlackMisc //! Callsign empty bool isCallsignEmpty() const { return this->m_callsign.isEmpty(); } - //! Queried model string + //! Model string, either queried or loaded from simulator model const QString &getModelString() const { return this->m_modelString; } //! Model string @@ -107,18 +111,42 @@ namespace BlackMisc //! \copydoc CAircraftIcaoData::hasAircraftDesignator bool hasAircraftDesignator() const { return this->m_icao.hasAircraftDesignator(); } + //! Aircraft ICAO code + const BlackMisc::Aviation::CAircraftIcaoCode &getAircraftIcaoCode() const; + + //! Airline ICAO code + const BlackMisc::Aviation::CAirlineIcaoCode &getAirlineIcaoCode() const; + + //! Get livery + const BlackMisc::Aviation::CLivery &getLivery() const { return m_livery; } + + //! Livery + void setLivery(const BlackMisc::Aviation::CLivery &livery) { this->m_livery = livery; } + + //! Livery available? + bool hasLivery() const { return m_livery.hasCompleteData();} + //! Model type - ModelType getModelType() const { return static_cast(m_modelType); } + ModelType getModelType() const { return m_modelType; } //! Model type QString getModelTypeAsString() const { return modelTypeToString(getModelType()); } //! Set type - void setModelType(ModelType type) { this->m_modelType = static_cast(type); } + void setModelType(ModelType type) { this->m_modelType = type; } - //! File name + //! Simulator info + CSimulatorInfo getSimulatorInfo() const { return this->m_simulator; } + + //! Set simulator info + void setSimulatorInfo(const CSimulatorInfo &simulator) { this->m_simulator = simulator; } + + //! File name (corresponding data for simulator, only available if representing simulator model= QString getFileName() const { return m_fileName; } + //! File name? + bool hasFileName() const { return !m_fileName.isEmpty(); } + //! File name void setFileName(const QString &fileName) { m_fileName = fileName; } @@ -137,20 +165,25 @@ namespace BlackMisc //! Matches model string? bool matchesModelString(const QString &modelString, Qt::CaseSensitivity sensitivity) const; - //! Model type - static QString modelTypeToString(ModelType type); - //! \copydoc CValueObject::convertToQString QString convertToQString(bool i18n = false) const; + //! Model type + static QString modelTypeToString(ModelType type); + + //! From swift DB JSON + static CAircraftModel fromDatabaseJson(const QJsonObject &json); + private: BLACK_ENABLE_TUPLE_CONVERSION(CAircraftModel) - BlackMisc::Aviation::CCallsign m_callsign; //!< aircraft's callsign - BlackMisc::Aviation::CAircraftIcaoData m_icao; //!< ICAO data if available - QString m_modelString; //!< Simulator model string - QString m_description; //!< descriptive text - QString m_fileName; //!< file name - int m_modelType = static_cast(TypeUnknown); //!< model string is queried from network? + BlackMisc::Aviation::CCallsign m_callsign; //!< aircraft's callsign if any + BlackMisc::Aviation::CAircraftIcaoData m_icao; //!< ICAO data if available + BlackMisc::Aviation::CLivery m_livery; //!< livery information + CSimulatorInfo m_simulator; //!< model for given simulator + QString m_modelString; //!< Simulator model string + QString m_description; //!< descriptive text + QString m_fileName; //!< file name + ModelType m_modelType = TypeUnknown; //!< model string is coming from ...? }; } // namespace } // namespace @@ -159,6 +192,7 @@ BLACK_DECLARE_TUPLE_CONVERSION( BlackMisc::Simulation::CAircraftModel, ( attr(o.m_callsign), attr(o.m_icao), + attr(o.m_simulator), attr(o.m_modelString, flags()), attr(o.m_description, flags()), attr(o.m_fileName, flags ()), diff --git a/src/blackmisc/simulation/aircraftmodellist.h b/src/blackmisc/simulation/aircraftmodellist.h index 71471b8db..0841c5985 100644 --- a/src/blackmisc/simulation/aircraftmodellist.h +++ b/src/blackmisc/simulation/aircraftmodellist.h @@ -14,6 +14,7 @@ #include "blackmisc/blackmiscexport.h" #include "blackmisc/simulation/aircraftmodel.h" +#include "blackmisc/datastoreobjectlist.h" #include "blackmisc/collection.h" #include "blackmisc/sequence.h" @@ -24,6 +25,7 @@ namespace BlackMisc //! Value object encapsulating a list of aircraft models class BLACKMISC_EXPORT CAircraftModelList : public CSequence, + public IDatastoreObjectListWithIntegerKey, public BlackMisc::Mixin::MetaType { public: @@ -49,7 +51,6 @@ namespace BlackMisc //! Model strings QStringList getSortedModelStrings() const; - }; } //namespace diff --git a/src/blackmisc/simulation/distributor.cpp b/src/blackmisc/simulation/distributor.cpp new file mode 100644 index 000000000..150c67358 --- /dev/null +++ b/src/blackmisc/simulation/distributor.cpp @@ -0,0 +1,95 @@ +/* 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 "distributor.h" +#include + +namespace BlackMisc +{ + namespace Simulation + { + CDistributor::CDistributor() { } + + CDistributor::CDistributor(const QString &id, const QString &description, const QString &alias1, const QString &alias2) : + m_description(description), m_alias1(alias1.trimmed().toUpper()), m_alias2(alias2.trimmed().toUpper()) + { + this->setDbKey(id); + } + + CVariant CDistributor::propertyByIndex(const CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + if (IDatastoreObjectWithStringKey::canHandleIndex(index)) { return IDatastoreObjectWithStringKey::propertyByIndex(index); } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexAlias1: return CVariant::from(this->m_alias1); + case IndexAlias2: return CVariant::from(this->m_alias2); + case IndexDescription: return CVariant::from(this->m_description); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CDistributor::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + if (IDatastoreObjectWithStringKey::canHandleIndex(index)) { IDatastoreObjectWithStringKey::setPropertyByIndex(variant, index); return; } + ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexAlias1: + this->m_alias1 = variant.value(); + break; + case IndexAlias2: + this->m_alias2 = variant.value(); + break; + case IndexDescription: + this->m_description = variant.value(); + break; + default: + CValueObject::setPropertyByIndex(variant, index); + break; + } + } + + QString CDistributor::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + QString s("Id: %1"); + s.arg(m_dbKey); + if (this->hasAlias1()) { s.append(" ").append(m_alias1); } + if (this->hasAlias2()) { s.append(" ").append(m_alias2); } + return s; + } + + bool CDistributor::hasCompleteData() const + { + return !this->m_description.isEmpty() && !this->m_dbKey.isEmpty(); + } + + CDistributor CDistributor::fromDatabaseJson(const QJsonObject &json) + { + QJsonArray inner = json["cell"].toArray(); + Q_ASSERT_X(!inner.isEmpty(), Q_FUNC_INFO, "Missing JSON"); + if (inner.isEmpty()) { return CDistributor(); } + + int i = 0; + QString dbKey(inner.at(i++).toString()); + QString description(inner.at(i++).toString()); + QString alias1(inner.at(i++).toString()); + QString alias2(inner.at(i++).toString()); + Q_ASSERT_X(!dbKey.isEmpty(), Q_FUNC_INFO, "Missing key"); + Q_ASSERT_X(!description.isEmpty(), Q_FUNC_INFO, "Missing description"); + CDistributor distributor(dbKey, description, alias1, alias2); + return distributor; + } + + } // namespace +} // namespace diff --git a/src/blackmisc/simulation/distributor.h b/src/blackmisc/simulation/distributor.h new file mode 100644 index 000000000..05252b3b3 --- /dev/null +++ b/src/blackmisc/simulation/distributor.h @@ -0,0 +1,101 @@ +/* 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_SIMULATION_DISTRIBUTOR_H +#define BLACKMISC_SIMULATION_DISTRIBUTOR_H + +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/valueobject.h" +#include "blackmisc/datastore.h" +#include + +namespace BlackMisc +{ + namespace Simulation + { + //! Value object encapsulating information of software distributor. + class BLACKMISC_EXPORT CDistributor : + public BlackMisc::CValueObject, + public BlackMisc::IDatastoreObjectWithStringKey + { + public: + //! Property indexes + enum ColumnIndex + { + IndexDescription = CPropertyIndex::GlobalIndexCDistributor, + IndexAlias1, + IndexAlias2 + }; + + //! Default constructor. + CDistributor(); + + //! Constructor + CDistributor(const QString &id, const QString &description, const QString &alias1, const QString &alias2); + + //! Id + const QString &getId() const { return this->getDbKey(); } + + //! Get description + const QString &getDescription() const { return this->m_description;} + + //! Get alias1 + const QString &getAlias1() const { return this->m_alias1;} + + //! Get alias2 + const QString &getAlias2() const { return this->m_alias2;} + + //! Set alias1 + void setAlias1(const QString &alias) { this->m_alias1 = alias.trimmed().toUpper(); } + + //! Set alias2 + void setAlias2(const QString &alias) { this->m_alias2 = alias.trimmed().toUpper(); } + + //! Alias 1? + bool hasAlias1() const { return !this->m_alias1.isEmpty(); } + + //! Alias 2? + bool hasAlias2() const { return !this->m_alias2.isEmpty(); } + + //! \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 CDistributor fromDatabaseJson(const QJsonObject &json); + + private: + BLACK_ENABLE_TUPLE_CONVERSION(CDistributor) + QString m_description; //!< description + QString m_alias1; //!< alias name + QString m_alias2; //!< alias name + }; + + } // namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Simulation::CDistributor) +BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Simulation::CDistributor, ( + attr(o.m_dbKey, flags ()), + attr(o.m_description), + attr(o.m_alias1, flags ()), + attr(o.m_alias2, flags ()) + )) + +#endif // guard diff --git a/src/blackmisc/simulation/distributorlist.cpp b/src/blackmisc/simulation/distributorlist.cpp new file mode 100644 index 000000000..820e3b6f0 --- /dev/null +++ b/src/blackmisc/simulation/distributorlist.cpp @@ -0,0 +1,24 @@ +/* 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/simulation/distributorlist.h" +#include "blackmisc/predicates.h" + +namespace BlackMisc +{ + namespace Simulation + { + CDistributorList::CDistributorList() { } + + CDistributorList::CDistributorList(const CSequence &other) : + CSequence(other) + { } + + } // namespace +} // namespace diff --git a/src/blackmisc/simulation/distributorlist.h b/src/blackmisc/simulation/distributorlist.h new file mode 100644 index 000000000..59d746477 --- /dev/null +++ b/src/blackmisc/simulation/distributorlist.h @@ -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_SIMULATION_DISTRIBUTORLIST_H +#define BLACKMISC_SIMULATION_DISTRIBUTORLIST_H + +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/simulation/distributor.h" +#include "blackmisc/datastoreobjectlist.h" +#include "blackmisc/collection.h" +#include "blackmisc/sequence.h" +#include +#include +#include + +namespace BlackMisc +{ + namespace Simulation + { + //! Value object encapsulating a list of distributors. + class BLACKMISC_EXPORT CDistributorList : + public BlackMisc::CSequence, + public BlackMisc::IDatastoreObjectListWithStringKey, + public BlackMisc::Mixin::MetaType + { + public: + BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CDistributorList) + + //! Default constructor. + CDistributorList(); + + //! Construct from a base class object. + CDistributorList(const CSequence &other); + }; + } //namespace +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Simulation::CDistributorList) +Q_DECLARE_METATYPE(BlackMisc::CCollection) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif //guard diff --git a/src/blackmisc/simulation/simulatedaircraft.cpp b/src/blackmisc/simulation/simulatedaircraft.cpp index 35007d056..f0b1e0438 100644 --- a/src/blackmisc/simulation/simulatedaircraft.cpp +++ b/src/blackmisc/simulation/simulatedaircraft.cpp @@ -18,7 +18,6 @@ namespace BlackMisc { namespace Simulation { - CSimulatedAircraft::CSimulatedAircraft() { init(); @@ -33,9 +32,11 @@ namespace BlackMisc void CSimulatedAircraft::init() { // sync some values, order here is crucial + // set get/set thing here updates the redundant data (e.g. livery / model.livery) this->setCallsign(this->getCallsign()); this->setIcaoInfo(this->getIcaoInfo()); - this->setModel(this->getModel()); // fix internal values + this->setLivery(this->getLivery()); + this->setModel(this->getModel()); this->setPilot(this->hasValidRealName() ? this->getPilot() : this->getClient().getUser()); } @@ -125,6 +126,12 @@ namespace BlackMisc CAircraft::setIcaoInfo(newIcao); } + void CSimulatedAircraft::setLivery(const CLivery &livery) + { + this->m_model.setLivery(livery); + CAircraft::setLivery(livery); + } + void CSimulatedAircraft::setPilot(const CUser &user) { this->m_client.setUser(user); diff --git a/src/blackmisc/simulation/simulatedaircraft.h b/src/blackmisc/simulation/simulatedaircraft.h index 6dc9434ef..222e2823a 100644 --- a/src/blackmisc/simulation/simulatedaircraft.h +++ b/src/blackmisc/simulation/simulatedaircraft.h @@ -69,6 +69,9 @@ namespace BlackMisc //! \copydoc CAircraft::setIcaoInfo virtual void setIcaoInfo(const BlackMisc::Aviation::CAircraftIcaoData &icao) override; + //! \copydoc CAircraft::setLivery + virtual void setLivery(const BlackMisc::Aviation::CLivery &livery) override; + //! \copydoc CAircraft::setPilot virtual void setPilot(const BlackMisc::Network::CUser &user) override; @@ -115,8 +118,9 @@ namespace BlackMisc bool m_enabled = true; //!< to be displayed in sim bool m_rendered = false; //!< really shown in simulator bool m_partsSynchronized = false; //!< sync.parts - bool m_fastPositionUpdates =false; //! @@ -171,7 +174,13 @@ namespace BlackMisc // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html template class ITimestampObjectList; template class ITimestampObjectList; + template class ITimestampObjectList; + + template class ITimestampObjectList; + template class ITimestampObjectList; + template class ITimestampObjectList; + template class ITimestampObjectList; template class ITimestampObjectList; diff --git a/src/blackmisc/timestampobjectlist.h b/src/blackmisc/timestampobjectlist.h index f4b0a9e2a..5750f63b4 100644 --- a/src/blackmisc/timestampobjectlist.h +++ b/src/blackmisc/timestampobjectlist.h @@ -90,6 +90,8 @@ namespace BlackMisc class CAircraftSituationList; class CAircraftParts; class CAircraftPartsList; + class CLivery; + class CLiveryList; } namespace Network @@ -98,6 +100,14 @@ namespace BlackMisc class CTextMessageList; } + namespace Simulation + { + class CDistributor; + class CDistributorList; + class CAircraftModel; + class CAircraftModelList; + } + class CStatusMessage; class CStatusMessageList; class CIdentifier; @@ -105,7 +115,13 @@ namespace BlackMisc extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; + + extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; + extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; extern template class BLACKMISC_EXPORT_TEMPLATE ITimestampObjectList; //! \endcond