diff --git a/src/blackcore/aircraftmatcher.cpp b/src/blackcore/aircraftmatcher.cpp index fcc985d48..6564e71a1 100644 --- a/src/blackcore/aircraftmatcher.cpp +++ b/src/blackcore/aircraftmatcher.cpp @@ -30,7 +30,6 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; -using namespace BlackCore::Settings; namespace BlackCore { @@ -1075,70 +1074,4 @@ namespace BlackCore if (!sApp || sApp->isShuttingDown() || !sApp->hasWebDataServices()) { return true; } return (sApp->getWebDataServices()->containsAirlineIcaoDesignator(designator)); } - - const QString &CAircraftMatcherSetup::modeFlagToString(MatchingModeFlag modeFlag) - { - static const QString ms("by model string"); - static const QString icao("by ICAO"); - static const QString family("by family"); - static const QString livery("by livery"); - static const QString combined("by combined combined"); - - switch (modeFlag) - { - case ByModelString: return ms; - case ByIcaoData: return icao; - case ByFamily: return family; - case ByLivery: return livery; - case ByCombinedType: return combined; - default: break; - } - - static const QString unknown("unknown"); - return unknown; - } - - QString CAircraftMatcherSetup::modeToString(MatchingMode mode) - { - if (mode == ModeAll) { return "all"; } - - QStringList modes; - if (mode.testFlag(ByModelString)) { modes << modeFlagToString(ByModelString); } - if (mode.testFlag(ByIcaoData)) { modes << modeFlagToString(ByIcaoData); } - if (mode.testFlag(ByFamily)) { modes << modeFlagToString(ByFamily); } - if (mode.testFlag(ByLivery)) { modes << modeFlagToString(ByLivery); } - if (mode.testFlag(ByCombinedType)) { modes << modeFlagToString(ByCombinedType); } - return modes.join(", "); - } - - QString CAircraftMatcherSetup::convertToQString(bool i18n) const - { - Q_UNUSED(i18n); - return modeToString(this->getMatchingMode()); - } - - CVariant CAircraftMatcherSetup::propertyByIndex(const CPropertyIndex &index) const - { - if (index.isMyself()) { return CVariant::from(*this); } - const ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexMatchingMode: return CVariant::fromValue(m_mode); - default: break; - } - return CValueObject::propertyByIndex(index); - } - - void CAircraftMatcherSetup::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) - { - if (index.isMyself()) { (*this) = variant.to(); return; } - const ColumnIndex i = index.frontCasted(); - switch (i) - { - case IndexMatchingMode: m_mode = variant.toInt(); break; - default: break; - } - CValueObject::setPropertyByIndex(index, variant); - } - } // namespace diff --git a/src/blackcore/aircraftmatcher.h b/src/blackcore/aircraftmatcher.h index f44d5dfe8..ad834f105 100644 --- a/src/blackcore/aircraftmatcher.h +++ b/src/blackcore/aircraftmatcher.h @@ -13,6 +13,7 @@ #define BLACKCORE_AIRCRAFTMATCHER_H #include "blackcore/blackcoreexport.h" +#include "blackmisc/simulation/aircraftmatchersetup.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/matchingstatistics.h" #include "blackmisc/statusmessage.h" @@ -33,64 +34,6 @@ namespace BlackMisc namespace BlackCore { - namespace Settings - { - //! Matcher settings - class BLACKCORE_EXPORT CAircraftMatcherSetup : public BlackMisc::CValueObject - { - public: - //! Enabled matching mode flags - enum MatchingModeFlag - { - ByModelString = 1 << 0, - ByIcaoData = 1 << 1, - ByFamily = 1 << 2, - ByLivery = 1 << 3, - ByCombinedType = 1 << 4, - ModeAll = ByModelString | ByIcaoData | ByFamily | ByLivery | ByCombinedType - }; - Q_DECLARE_FLAGS(MatchingMode, MatchingModeFlag) - - //! Enumeration as string - static const QString &modeFlagToString(MatchingModeFlag modeFlag); - - //! Enumeration as string - static QString modeToString(MatchingMode mode); - - //! Properties by index - enum ColumnIndex - { - IndexMatchingMode = BlackMisc::CPropertyIndex::GlobalIndexCAircraftMatcherSetup - }; - - //! Constructor - CAircraftMatcherSetup() {} - - //! Matching mode - MatchingMode getMatchingMode() const { return static_cast(m_mode); } - - //! Dynamic offset values? - void setMatchingMode(MatchingMode mode) { m_mode = static_cast(mode); } - - //! \copydoc BlackMisc::Mixin::String::toQString - QString convertToQString(bool i18n = false) const; - - //! \copydoc BlackMisc::Mixin::Index::propertyByIndex - BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; - - //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex - void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant); - - private: - int m_mode = static_cast(ModeAll); - - BLACK_METACLASS( - CAircraftMatcherSetup, - BLACK_METAMEMBER(mode) - ); - }; - } // ns - //! Matcher for all models. //! \details Reads the model set (ie the models the user wants to use). //! Also Allows to reverse lookup a model (from network to DB data). @@ -103,7 +46,7 @@ namespace BlackCore static const BlackMisc::CLogCategoryList &getLogCategories(); //! Constructor - CAircraftMatcher(const Settings::CAircraftMatcherSetup &setup, QObject *parent = nullptr); + CAircraftMatcher(const BlackMisc::Simulation::CAircraftMatcherSetup &setup, QObject *parent = nullptr); //! Constructor CAircraftMatcher(QObject *parent = nullptr); @@ -111,8 +54,8 @@ namespace BlackCore //! Destructor virtual ~CAircraftMatcher(); - //! Set the enabled matching modes - void setSetup(const Settings::CAircraftMatcherSetup matchingModes); + //! Set the setup + void setSetup(const BlackMisc::Simulation::CAircraftMatcherSetup &setup) { m_setup = setup; } //! Get the closest matching aircraft model from set. //! Result depends on enabled modes. @@ -228,11 +171,11 @@ namespace BlackCore private: //! The search based implementation //! \threadsafe - BlackMisc::Simulation::CAircraftModel getClosestMatchSearchImplementation(Settings::CAircraftMatcherSetup::MatchingMode mode, const BlackMisc::Simulation::CAircraftModelList &modelSet, const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, BlackMisc::CStatusMessageList *log = nullptr) const; + BlackMisc::Simulation::CAircraftModel getClosestMatchSearchImplementation(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode mode, const BlackMisc::Simulation::CAircraftModelList &modelSet, const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, BlackMisc::CStatusMessageList *log = nullptr) const; //! The score based implementation //! \threadsafe - BlackMisc::Simulation::CAircraftModel getClosestMatchScoreImplementation(Settings::CAircraftMatcherSetup::MatchingMode mode, const BlackMisc::Simulation::CAircraftModelList &modelSet, const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, BlackMisc::CStatusMessageList *log = nullptr) const; + BlackMisc::Simulation::CAircraftModel getClosestMatchScoreImplementation(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode mode, const BlackMisc::Simulation::CAircraftModelList &modelSet, const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft, BlackMisc::CStatusMessageList *log = nullptr) const; //! Get combined type default model, i.e. get a default model under consideration of the combined code such as "L2J" //! \see BlackMisc::Simulation::CSimulatedAircraft::getAircraftIcaoCombinedType @@ -288,18 +231,13 @@ namespace BlackCore //! \threadsafe static bool isValidAirlineIcaoDesignator(const QString &designator, bool checkAgainstSwiftDb); - Settings::CAircraftMatcherSetup m_setup; //!< setup - BlackMisc::Simulation::CAircraftModel m_defaultModel; //!< model to be used as default model - BlackMisc::Simulation::CAircraftModelList m_modelSet; //!< models used for model matching - BlackMisc::Simulation::CSimulatorInfo m_simulator; //!< simulator (optional) - BlackMisc::Simulation::CMatchingStatistics m_statistics; //!< matching statistics - QString m_modelSetInfo; //!< info string + BlackMisc::Simulation::CAircraftMatcherSetup m_setup; //!< setup + BlackMisc::Simulation::CAircraftModel m_defaultModel; //!< model to be used as default model + BlackMisc::Simulation::CAircraftModelList m_modelSet; //!< models used for model matching + BlackMisc::Simulation::CSimulatorInfo m_simulator; //!< simulator (optional) + BlackMisc::Simulation::CMatchingStatistics m_statistics; //!< matching statistics + QString m_modelSetInfo; //!< info string }; } // namespace -Q_DECLARE_METATYPE(BlackCore::Settings::CAircraftMatcherSetup) -Q_DECLARE_METATYPE(BlackCore::Settings::CAircraftMatcherSetup::MatchingMode) -Q_DECLARE_METATYPE(BlackCore::Settings::CAircraftMatcherSetup::MatchingModeFlag) -Q_DECLARE_OPERATORS_FOR_FLAGS(BlackCore::Settings::CAircraftMatcherSetup::MatchingMode) - #endif // guard diff --git a/src/blackcore/registermetadata.cpp b/src/blackcore/registermetadata.cpp index a1b684489..8379a3687 100644 --- a/src/blackcore/registermetadata.cpp +++ b/src/blackcore/registermetadata.cpp @@ -36,8 +36,6 @@ namespace BlackCore qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); @@ -45,15 +43,12 @@ namespace BlackCore qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); - // qDBusRegisterMetaType(); - qDBusRegisterMetaType(); Db::CDatabaseReaderConfig::registerMetadata(); Db::CDatabaseReaderConfigList::registerMetadata(); Data::CGlobalSetup::registerMetadata(); Data::CVatsimSetup::registerMetadata(); Data::CLauncherSetup::registerMetadata(); - Settings::CAircraftMatcherSetup::registerMetadata(); Vatsim::CReaderSettings::registerMetadata(); Vatsim::CRawFsdMessageSettings::registerMetadata(); } diff --git a/src/blackmisc/simulation/aircraftmatchersetup.cpp b/src/blackmisc/simulation/aircraftmatchersetup.cpp new file mode 100644 index 000000000..8d132d7b2 --- /dev/null +++ b/src/blackmisc/simulation/aircraftmatchersetup.cpp @@ -0,0 +1,91 @@ +/* Copyright (C) 2018 + * 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 "aircraftmatchersetup.h" + +namespace BlackMisc +{ + namespace Simulation + { + QString CAircraftMatcherSetup::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + return modeToString(this->getMatchingMode()); + } + + CVariant CAircraftMatcherSetup::propertyByIndex(const CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexMatchingMode: return CVariant::fromValue(m_mode); + default: break; + } + return CValueObject::propertyByIndex(index); + } + + void CAircraftMatcherSetup::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexMatchingMode: m_mode = variant.toInt(); break; + default: break; + } + CValueObject::setPropertyByIndex(index, variant); + } + + const QString &CAircraftMatcherSetup::modeFlagToString(MatchingModeFlag modeFlag) + { + static const QString ms("by model string"); + static const QString icao("by ICAO"); + static const QString family("by family"); + static const QString livery("by livery"); + static const QString combined("by combined combined"); + + switch (modeFlag) + { + case ByModelString: return ms; + case ByIcaoData: return icao; + case ByFamily: return family; + case ByLivery: return livery; + case ByCombinedType: return combined; + default: break; + } + + static const QString unknown("unknown"); + return unknown; + } + + QString CAircraftMatcherSetup::modeToString(MatchingMode mode) + { + if (mode == ModeAll) { return "all"; } + + QStringList modes; + if (mode.testFlag(ByModelString)) { modes << modeFlagToString(ByModelString); } + if (mode.testFlag(ByIcaoData)) { modes << modeFlagToString(ByIcaoData); } + if (mode.testFlag(ByFamily)) { modes << modeFlagToString(ByFamily); } + if (mode.testFlag(ByLivery)) { modes << modeFlagToString(ByLivery); } + if (mode.testFlag(ByCombinedType)) { modes << modeFlagToString(ByCombinedType); } + return modes.join(", "); + } + + CAircraftMatcherSetup::MatchingMode CAircraftMatcherSetup::matchingMode(bool byModelString, bool byIcaoData, bool byFamily, bool byLivery, bool byCombinedType) + { + MatchingMode mode = byModelString ? ByModelString : ModeNone; + if (byIcaoData) { mode |= ByIcaoData; } + if (byFamily) { mode |= ByFamily; } + if (byLivery) { mode |= ByLivery; } + if (byCombinedType) { mode |= ByCombinedType; } + return mode; + } + } // namespace +} // namespace diff --git a/src/blackmisc/simulation/aircraftmatchersetup.h b/src/blackmisc/simulation/aircraftmatchersetup.h new file mode 100644 index 000000000..77ee0ae15 --- /dev/null +++ b/src/blackmisc/simulation/aircraftmatchersetup.h @@ -0,0 +1,89 @@ +/* Copyright (C) 2018 + * 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_AIRCRAFTMATCHERSETUP_H +#define BLACKMISC_SIMULATION_AIRCRAFTMATCHERSETUP_H + +#include "blackmisc/valueobject.h" +#include "blackmisc/blackmiscexport.h" + + +namespace BlackMisc +{ + namespace Simulation + { + //! Matcher settings + class BLACKMISC_EXPORT CAircraftMatcherSetup : public CValueObject + { + public: + //! Enabled matching mode flags + enum MatchingModeFlag + { + ByModelString = 1 << 0, + ByIcaoData = 1 << 1, + ByFamily = 1 << 2, + ByLivery = 1 << 3, + ByCombinedType = 1 << 4, + ModeAll = ByModelString | ByIcaoData | ByFamily | ByLivery | ByCombinedType, + ModeNone = 0 + }; + Q_DECLARE_FLAGS(MatchingMode, MatchingModeFlag) + + //! Properties by index + enum ColumnIndex + { + IndexMatchingMode = CPropertyIndex::GlobalIndexCAircraftMatcherSetup + }; + + //! Constructor + CAircraftMatcherSetup() {} + + //! Matching mode + MatchingMode getMatchingMode() const { return static_cast(m_mode); } + + //! Dynamic offset values? + void setMatchingMode(MatchingMode mode) { m_mode = static_cast(mode); } + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant); + + //! Enumeration as string + static const QString &modeFlagToString(MatchingModeFlag modeFlag); + + //! Enumeration as string + static QString modeToString(MatchingMode mode); + + //! Mode by flags + static MatchingMode matchingMode(bool byModelString, bool byIcaoData, bool byFamily, bool byLivery, bool byCombinedType); + + private: + int m_mode = static_cast(ModeAll); + + BLACK_METACLASS( + CAircraftMatcherSetup, + BLACK_METAMEMBER(mode) + ); + }; + } // ns +} // namespace + +Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup) +Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode) +Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingModeFlag) +Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode) + +#endif // guard diff --git a/src/blackmisc/simulation/registermetadatasimulation.cpp b/src/blackmisc/simulation/registermetadatasimulation.cpp index 0dfd6adbd..1b0c2fad6 100644 --- a/src/blackmisc/simulation/registermetadatasimulation.cpp +++ b/src/blackmisc/simulation/registermetadatasimulation.cpp @@ -49,6 +49,10 @@ namespace BlackMisc CSwiftPluginSettings::registerMetadata(); CVPilotModelRule::registerMetadata(); CVPilotModelRuleSet::registerMetadata(); + qRegisterMetaType(); + qRegisterMetaType(); + qDBusRegisterMetaType(); + CAircraftMatcherSetup::registerMetadata(); } } // ns } // ns diff --git a/src/blackmisc/simulation/simulation.h b/src/blackmisc/simulation/simulation.h index 70f0166f6..edcdb1616 100644 --- a/src/blackmisc/simulation/simulation.h +++ b/src/blackmisc/simulation/simulation.h @@ -15,6 +15,7 @@ * \brief Generic simulation related class, but not OS or driver dependent */ +#include "blackmisc/simulation/aircraftmatchersetup.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/airspaceaircraftsnapshot.h" #include "blackmisc/simulation/distributorlist.h"