From 8b6bdf22762a3081fa12abf37cdfc1daa10e1667 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 7 Aug 2018 19:54:47 +0200 Subject: [PATCH] Ref T298, added algorithm and score values to matching setup --- .../components/settingsmatchingcomponent.cpp | 28 ++++- .../components/settingsmatchingcomponent.h | 3 + .../components/settingsmatchingcomponent.ui | 28 +++-- src/blackgui/editors/matchingform.cpp | 44 ++++++- src/blackgui/editors/matchingform.h | 3 + src/blackgui/editors/matchingform.ui | 111 +++++++++++++++--- .../simulation/aircraftmatchersetup.cpp | 60 ++++++++-- .../simulation/aircraftmatchersetup.h | 50 +++++++- .../simulation/registermetadatasimulation.cpp | 2 + 9 files changed, 276 insertions(+), 53 deletions(-) diff --git a/src/blackgui/components/settingsmatchingcomponent.cpp b/src/blackgui/components/settingsmatchingcomponent.cpp index cff1ab5f3..9cc9f9e4e 100644 --- a/src/blackgui/components/settingsmatchingcomponent.cpp +++ b/src/blackgui/components/settingsmatchingcomponent.cpp @@ -9,10 +9,10 @@ #include "settingsmatchingcomponent.h" #include "ui_settingsmatchingcomponent.h" - #include "blackgui/guiapplication.h" #include "blackcore/context/contextsimulator.h" #include "blackmisc/simulation/aircraftmatchersetup.h" +#include using namespace BlackMisc::Simulation; using namespace BlackCore::Context; @@ -28,6 +28,7 @@ namespace BlackGui ui->setupUi(this); connect(ui->pb_Save, &QPushButton::released, this, &CSettingsMatchingComponent::onSavePressed); connect(ui->pb_Reload, &QPushButton::released, this, &CSettingsMatchingComponent::onReloadPressed); + this->deferredReload(5000); } CSettingsMatchingComponent::~CSettingsMatchingComponent() @@ -43,10 +44,27 @@ namespace BlackGui void CSettingsMatchingComponent::onReloadPressed() { - IContextSimulator *simContext = simulatorContext(); - if (!simContext) { return; } - const CAircraftMatcherSetup setup = simContext->getMatchingSetup(); - ui->editor_MatchingForm->setValue(setup); + this->deferredReload(0); + } + + void CSettingsMatchingComponent::deferredReload(int deferMs) + { + if (deferMs < 1) + { + IContextSimulator *simContext = simulatorContext(); + if (!simContext) { return; } + const CAircraftMatcherSetup setup = simContext->getMatchingSetup(); + ui->editor_MatchingForm->setValue(setup); + } + else + { + QPointer myself(this); + QTimer::singleShot(deferMs, this, [ = ] + { + if (!myself) { return; } + this->deferredReload(0); + }); + } } IContextSimulator *CSettingsMatchingComponent::simulatorContext() diff --git a/src/blackgui/components/settingsmatchingcomponent.h b/src/blackgui/components/settingsmatchingcomponent.h index 8d89e6eea..acad9e834 100644 --- a/src/blackgui/components/settingsmatchingcomponent.h +++ b/src/blackgui/components/settingsmatchingcomponent.h @@ -42,6 +42,9 @@ namespace BlackGui //! Reload pressed void onReloadPressed(); + //! Deferred reload + void deferredReload(int deferMs); + //! Network context static BlackCore::Context::IContextSimulator *simulatorContext(); }; diff --git a/src/blackgui/components/settingsmatchingcomponent.ui b/src/blackgui/components/settingsmatchingcomponent.ui index 123ee83ad..8affd4358 100644 --- a/src/blackgui/components/settingsmatchingcomponent.ui +++ b/src/blackgui/components/settingsmatchingcomponent.ui @@ -6,21 +6,33 @@ 0 0 - 640 - 480 + 232 + 197 - Frame + Matching settings + + 3 + + + 3 + + + 3 + + + 3 + - - QFrame::StyledPanel - - - QFrame::Raised + + + 0 + 150 + diff --git a/src/blackgui/editors/matchingform.cpp b/src/blackgui/editors/matchingform.cpp index d4eadedd1..c73e57d4f 100644 --- a/src/blackgui/editors/matchingform.cpp +++ b/src/blackgui/editors/matchingform.cpp @@ -32,10 +32,17 @@ namespace BlackGui void CMatchingForm::setReadOnly(bool readonly) { CGuiUtility::checkBoxReadOnly(ui->cb_ByModelString, readonly); - CGuiUtility::checkBoxReadOnly(ui->cb_ByICAOdata, readonly); + CGuiUtility::checkBoxReadOnly(ui->cb_ByIcaoDataAircraft1st, readonly); + CGuiUtility::checkBoxReadOnly(ui->cb_ByIcaoDataAirline1st, readonly); CGuiUtility::checkBoxReadOnly(ui->cb_ByFamily, readonly); CGuiUtility::checkBoxReadOnly(ui->cb_ByLivery, readonly); CGuiUtility::checkBoxReadOnly(ui->cb_ByCombinedCode, readonly); + CGuiUtility::checkBoxReadOnly(ui->cb_ScoreIgnoreZeros, readonly); + CGuiUtility::checkBoxReadOnly(ui->cb_ScorePreferColorLiveries, readonly); + + const bool enabled = !readonly; + ui->rb_Reduction->setEnabled(enabled); + ui->rb_ScoreBased->setEnabled(enabled); } CStatusMessageList CMatchingForm::validate(bool withNestedForms) const @@ -49,24 +56,49 @@ namespace BlackGui const CAircraftMatcherSetup::MatchingMode mode = setup.getMatchingMode(); ui->cb_ByModelString->setChecked(mode.testFlag(CAircraftMatcherSetup::ByModelString)); ui->cb_ByCombinedCode->setChecked(mode.testFlag(CAircraftMatcherSetup::ByCombinedType)); - ui->cb_ByICAOdata->setChecked(mode.testFlag(CAircraftMatcherSetup::ByIcaoData)); + ui->cb_ByIcaoDataAircraft1st->setChecked(mode.testFlag(CAircraftMatcherSetup::ByIcaoOrderAircraftFirst)); + ui->cb_ByIcaoDataAirline1st->setChecked(mode.testFlag(CAircraftMatcherSetup::ByIcaoOrderAirlineFirst)); ui->cb_ByLivery->setChecked(mode.testFlag(CAircraftMatcherSetup::ByLivery)); ui->cb_ByFamily->setChecked(mode.testFlag(CAircraftMatcherSetup::ByFamily)); + ui->cb_ScoreIgnoreZeros->setChecked(mode.testFlag(CAircraftMatcherSetup::ScoreIgnoreZeros)); + ui->cb_ScorePreferColorLiveries->setChecked(mode.testFlag(CAircraftMatcherSetup::ScorePreferColorLiveries)); + + if (setup.getMatchingAlgorithm() == CAircraftMatcherSetup::MatchingScoreBased) + { + ui->rb_ScoreBased->setChecked(true); + } + else + { + ui->rb_Reduction->setChecked(true); + } } CAircraftMatcherSetup CMatchingForm::value() const { - CAircraftMatcherSetup setup; - setup.setMatchingMode(matchingMode()); + const CAircraftMatcherSetup setup(algorithm(), matchingMode()); return setup; } + void CMatchingForm::clear() + { + CAircraftMatcherSetup s; + this->setValue(s); + } + + CAircraftMatcherSetup::MatchingAlgorithm CMatchingForm::algorithm() const + { + if (ui->rb_Reduction->isChecked()) { return CAircraftMatcherSetup::MatchingStepwiseReduce; } + return CAircraftMatcherSetup::MatchingScoreBased; + } + CAircraftMatcherSetup::MatchingMode CMatchingForm::matchingMode() const { return CAircraftMatcherSetup::matchingMode( - ui->cb_ByModelString->isChecked(), ui->cb_ByICAOdata->isChecked(), + ui->cb_ByModelString->isChecked(), + ui->cb_ByIcaoDataAircraft1st->isChecked(), ui->cb_ByIcaoDataAirline1st->isChecked(), ui->cb_ByFamily->isChecked(), ui->cb_ByLivery->isChecked(), - ui->cb_ByCombinedCode->isChecked() + ui->cb_ByCombinedCode->isChecked(), + ui->cb_ScoreIgnoreZeros->isChecked(), ui->cb_ScorePreferColorLiveries->isChecked() ); } } // ns diff --git a/src/blackgui/editors/matchingform.h b/src/blackgui/editors/matchingform.h index eaacd29b7..ff1f5c1eb 100644 --- a/src/blackgui/editors/matchingform.h +++ b/src/blackgui/editors/matchingform.h @@ -49,6 +49,9 @@ namespace BlackGui void clear(); private: + //! Algorithm + BlackMisc::Simulation::CAircraftMatcherSetup::MatchingAlgorithm algorithm() const; + //! Mode BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode matchingMode() const; diff --git a/src/blackgui/editors/matchingform.ui b/src/blackgui/editors/matchingform.ui index b13a9b7c1..0cf0567f2 100644 --- a/src/blackgui/editors/matchingform.ui +++ b/src/blackgui/editors/matchingform.ui @@ -6,20 +6,69 @@ 0 0 - 287 - 87 + 243 + 239 Frame + + 5 + + + 5 + + + 5 + + + 5 + - + - Mode + Algorithm + + + + + + reduction, then score based + + + + + + + reduction + + + + + + + + + + Reduction + + + + by family + + + + + + + combined code + + + @@ -27,28 +76,21 @@ - - + + - by ICAO data + by ICAO: airline first - + - by family + by ICAO: aircraft first - - - - combined code - - - - + by livery @@ -58,8 +100,43 @@ + + + + Scoring + + + + + + prefer color liveries + + + + + + + ignore 0 (zero) scores + + + + + + + + rb_ScoreBased + rb_Reduction + cb_ByModelString + cb_ByIcaoDataAircraft1st + cb_ByIcaoDataAirline1st + cb_ByFamily + cb_ByLivery + cb_ByCombinedCode + cb_ScorePreferColorLiveries + cb_ScoreIgnoreZeros + diff --git a/src/blackmisc/simulation/aircraftmatchersetup.cpp b/src/blackmisc/simulation/aircraftmatchersetup.cpp index 8d132d7b2..852160ea3 100644 --- a/src/blackmisc/simulation/aircraftmatchersetup.cpp +++ b/src/blackmisc/simulation/aircraftmatchersetup.cpp @@ -8,15 +8,23 @@ */ #include "aircraftmatchersetup.h" +#include namespace BlackMisc { namespace Simulation { + CAircraftMatcherSetup::CAircraftMatcherSetup(CAircraftMatcherSetup::MatchingAlgorithm algorithm, MatchingMode mode) + { + this->setMatchingAlgorithm(algorithm); + this->setMatchingMode(mode); + } + QString CAircraftMatcherSetup::convertToQString(bool i18n) const { Q_UNUSED(i18n); - return modeToString(this->getMatchingMode()); + return QStringLiteral("algorithm: '") % this->getMatchingAlgorithmAsString() % + QStringLiteral("' mode: ") % this->getMatchingModeAsString(); } CVariant CAircraftMatcherSetup::propertyByIndex(const CPropertyIndex &index) const @@ -25,6 +33,7 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); switch (i) { + case IndexMatchingAlgorithm: return CVariant::fromValue(m_algorithm); case IndexMatchingMode: return CVariant::fromValue(m_mode); default: break; } @@ -37,19 +46,37 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); switch (i) { + case IndexMatchingAlgorithm: m_algorithm = variant.toInt(); break; case IndexMatchingMode: m_mode = variant.toInt(); break; default: break; } CValueObject::setPropertyByIndex(index, variant); } + const QString &CAircraftMatcherSetup::algorithmToString(CAircraftMatcherSetup::MatchingAlgorithm algorithm) + { + static const QString s("score based"); + static const QString r("stepwise reduce"); + switch (algorithm) + { + case MatchingStepwiseReduce: return r; + case MatchingScoreBased: + default: break; + } + return s; + } + const QString &CAircraftMatcherSetup::modeFlagToString(MatchingModeFlag modeFlag) { static const QString ms("by model string"); static const QString icao("by ICAO"); + static const QString icaoAircraft("by ICAO, aircraft first"); + static const QString icaoAirline("by ICAO, airline first"); static const QString family("by family"); static const QString livery("by livery"); static const QString combined("by combined combined"); + static const QString noZeros("scoring, ignore zero scores"); + static const QString preferColorLiveries("scoring, prefer color liveries"); switch (modeFlag) { @@ -58,6 +85,10 @@ namespace BlackMisc case ByFamily: return family; case ByLivery: return livery; case ByCombinedType: return combined; + case ByIcaoOrderAircraftFirst: return icaoAircraft; + case ByIcaoOrderAirlineFirst: return icaoAirline; + case ScoreIgnoreZeros: return noZeros; + case ScorePreferColorLiveries: return preferColorLiveries; default: break; } @@ -67,24 +98,31 @@ namespace BlackMisc 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); } + if (mode.testFlag(ByIcaoOrderAircraftFirst)) { modes << modeFlagToString(ByIcaoOrderAircraftFirst); } + if (mode.testFlag(ByIcaoOrderAirlineFirst)) { modes << modeFlagToString(ByIcaoOrderAirlineFirst); } + if (mode.testFlag(ByFamily)) { modes << modeFlagToString(ByFamily); } + if (mode.testFlag(ByLivery)) { modes << modeFlagToString(ByLivery); } + if (mode.testFlag(ByCombinedType)) { modes << modeFlagToString(ByCombinedType); } + if (mode.testFlag(ScoreIgnoreZeros)) { modes << modeFlagToString(ScoreIgnoreZeros); } + if (mode.testFlag(ScorePreferColorLiveries)) { modes << modeFlagToString(ScorePreferColorLiveries); } return modes.join(", "); } - CAircraftMatcherSetup::MatchingMode CAircraftMatcherSetup::matchingMode(bool byModelString, bool byIcaoData, bool byFamily, bool byLivery, bool byCombinedType) + CAircraftMatcherSetup::MatchingMode CAircraftMatcherSetup::matchingMode( + bool byModelString, bool byIcaoDataAircraft1st, bool byIcaoDataAirline1st, bool byFamily, bool byLivery, bool byCombinedType, + bool scoreIgnoreZeros, bool scorePreferColorLiveries) { MatchingMode mode = byModelString ? ByModelString : ModeNone; - if (byIcaoData) { mode |= ByIcaoData; } - if (byFamily) { mode |= ByFamily; } - if (byLivery) { mode |= ByLivery; } - if (byCombinedType) { mode |= ByCombinedType; } + if (byIcaoDataAircraft1st) { mode |= ByIcaoOrderAircraftFirst; } + if (byIcaoDataAirline1st) { mode |= ByIcaoOrderAirlineFirst; } + if (byFamily) { mode |= ByFamily; } + if (byLivery) { mode |= ByLivery; } + if (byCombinedType) { mode |= ByCombinedType; } + if (scoreIgnoreZeros) { mode |= ScoreIgnoreZeros; } + if (scorePreferColorLiveries) { mode |= ScorePreferColorLiveries; } return mode; } } // namespace diff --git a/src/blackmisc/simulation/aircraftmatchersetup.h b/src/blackmisc/simulation/aircraftmatchersetup.h index 77ee0ae15..0ce91930f 100644 --- a/src/blackmisc/simulation/aircraftmatchersetup.h +++ b/src/blackmisc/simulation/aircraftmatchersetup.h @@ -24,31 +24,61 @@ namespace BlackMisc class BLACKMISC_EXPORT CAircraftMatcherSetup : public CValueObject { public: + //! Matching algorithm + enum MatchingAlgorithm + { + MatchingScoreBased, + MatchingStepwiseReduce + }; + //! Enabled matching mode flags enum MatchingModeFlag { - ByModelString = 1 << 0, + ByModelString = 1 << 0, //!< allow exact model string match ByIcaoData = 1 << 1, ByFamily = 1 << 2, ByLivery = 1 << 3, ByCombinedType = 1 << 4, - ModeAll = ByModelString | ByIcaoData | ByFamily | ByLivery | ByCombinedType, - ModeNone = 0 + ByIcaoOrderAircraftFirst = (1 << 5) | ByIcaoData, + ByIcaoOrderAirlineFirst = (1 << 6) | ByIcaoData, + // --- score based matching --- + ScoreIgnoreZeros = 1 << 7, //!< zero scores are ignored + ScorePreferColorLiveries = 1 << 8, //!< prefer color liveries + // --- others --- + ModeNone = 0, + ModeScoreDefault = ScoreIgnoreZeros | ScorePreferColorLiveries, + ModeDefault = ByModelString | ByFamily | ByLivery | ByCombinedType | ByIcaoOrderAircraftFirst | ModeScoreDefault }; Q_DECLARE_FLAGS(MatchingMode, MatchingModeFlag) //! Properties by index enum ColumnIndex { - IndexMatchingMode = CPropertyIndex::GlobalIndexCAircraftMatcherSetup + IndexMatchingAlgorithm = CPropertyIndex::GlobalIndexCAircraftMatcherSetup, + IndexMatchingMode }; //! Constructor CAircraftMatcherSetup() {} + //! Constructor + CAircraftMatcherSetup(MatchingAlgorithm algorithm, MatchingMode mode); + + //! Algorithm + MatchingAlgorithm getMatchingAlgorithm() const { return static_cast(m_algorithm); } + + //! Algorithm as string + const QString &getMatchingAlgorithmAsString() const { return algorithmToString(this->getMatchingAlgorithm()); } + + //! Algorithm + void setMatchingAlgorithm(MatchingAlgorithm algorithm) { m_algorithm = static_cast(algorithm); } + //! Matching mode MatchingMode getMatchingMode() const { return static_cast(m_mode); } + //! Matching mode as string + QString getMatchingModeAsString() const { return modeToString(this->getMatchingMode()); } + //! Dynamic offset values? void setMatchingMode(MatchingMode mode) { m_mode = static_cast(mode); } @@ -61,6 +91,9 @@ namespace BlackMisc //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant); + //! Algorithm to string + static const QString &algorithmToString(MatchingAlgorithm algorithm); + //! Enumeration as string static const QString &modeFlagToString(MatchingModeFlag modeFlag); @@ -68,13 +101,17 @@ namespace BlackMisc static QString modeToString(MatchingMode mode); //! Mode by flags - static MatchingMode matchingMode(bool byModelString, bool byIcaoData, bool byFamily, bool byLivery, bool byCombinedType); + static MatchingMode matchingMode( + bool byModelString, bool byIcaoDataAircraft1st, bool byIcaoDataAirline1st, bool byFamily, bool byLivery, bool byCombinedType, + bool scoreIgnoreZeros, bool scorePreferColorLiveries); private: - int m_mode = static_cast(ModeAll); + int m_algorithm = static_cast(MatchingScoreBased); + int m_mode = static_cast(ModeDefault); BLACK_METACLASS( CAircraftMatcherSetup, + BLACK_METAMEMBER(algorithm), BLACK_METAMEMBER(mode) ); }; @@ -82,6 +119,7 @@ namespace BlackMisc } // namespace Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup) +Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingAlgorithm) Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode) Q_DECLARE_METATYPE(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingModeFlag) Q_DECLARE_OPERATORS_FOR_FLAGS(BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode) diff --git a/src/blackmisc/simulation/registermetadatasimulation.cpp b/src/blackmisc/simulation/registermetadatasimulation.cpp index 1b0c2fad6..6fde927b3 100644 --- a/src/blackmisc/simulation/registermetadatasimulation.cpp +++ b/src/blackmisc/simulation/registermetadatasimulation.cpp @@ -49,8 +49,10 @@ namespace BlackMisc CSwiftPluginSettings::registerMetadata(); CVPilotModelRule::registerMetadata(); CVPilotModelRuleSet::registerMetadata(); + qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); + qDBusRegisterMetaType(); qDBusRegisterMetaType(); CAircraftMatcherSetup::registerMetadata(); }