From c4bd1536f28acdecbe9a8cddebb43392a5c085fd Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 11 Aug 2018 00:44:24 +0200 Subject: [PATCH] Ref T298, new attributes for matching setup in editor --- src/blackgui/editors/matchingform.cpp | 60 ++++++++++++++--- src/blackgui/editors/matchingform.h | 12 ++++ src/blackgui/editors/matchingform.ui | 96 ++++++++++++++++++++------- 3 files changed, 134 insertions(+), 34 deletions(-) diff --git a/src/blackgui/editors/matchingform.cpp b/src/blackgui/editors/matchingform.cpp index deaadb091..b4884bb12 100644 --- a/src/blackgui/editors/matchingform.cpp +++ b/src/blackgui/editors/matchingform.cpp @@ -10,6 +10,7 @@ #include "ui_matchingform.h" #include "matchingform.h" #include "guiutility.h" +#include using namespace BlackMisc; using namespace BlackMisc::Simulation; @@ -24,6 +25,8 @@ namespace BlackGui ui(new Ui::CMatchingForm) { ui->setupUi(this); + connect(ui->rb_Reduction, &QRadioButton::toggled, this, &CMatchingForm::onAlgorithmChanged, Qt::QueuedConnection); + connect(ui->pb_Reset, &QPushButton::released, this, &CMatchingForm::clear, Qt::QueuedConnection); } CMatchingForm::~CMatchingForm() @@ -43,6 +46,9 @@ namespace BlackGui ui->rb_ScoreBased->setEnabled(enabled); ui->rb_ByIcaoDataAircraft1st->setEnabled(enabled); ui->rb_ByIcaoDataAirline1st->setEnabled(enabled); + ui->rb_PickFirst->setEnabled(enabled); + ui->rb_PickByOrder->setEnabled(enabled); + ui->rb_PickRandom->setEnabled(enabled); } CStatusMessageList CMatchingForm::validate(bool withNestedForms) const @@ -62,26 +68,22 @@ namespace BlackGui ui->cb_ByFamily->setChecked(mode.testFlag(CAircraftMatcherSetup::ByFamily)); ui->cb_ScoreIgnoreZeros->setChecked(mode.testFlag(CAircraftMatcherSetup::ScoreIgnoreZeros)); ui->cb_ScorePreferColorLiveries->setChecked(mode.testFlag(CAircraftMatcherSetup::ScorePreferColorLiveries)); + this->setMatchingAlgorithm(setup); + this->setPickStrategy(setup); - if (setup.getMatchingAlgorithm() == CAircraftMatcherSetup::MatchingScoreBased) - { - ui->rb_ScoreBased->setChecked(true); - } - else - { - ui->rb_Reduction->setChecked(true); - } + const bool scoring = (setup.getMatchingAlgorithm() == CAircraftMatcherSetup::MatchingScoreBased); + ui->gb_Scoring->setEnabled(scoring); } CAircraftMatcherSetup CMatchingForm::value() const { - const CAircraftMatcherSetup setup(algorithm(), matchingMode()); + const CAircraftMatcherSetup setup(algorithm(), matchingMode(), pickStrategy()); return setup; } void CMatchingForm::clear() { - CAircraftMatcherSetup s; + const CAircraftMatcherSetup s(algorithm()); this->setValue(s); } @@ -101,5 +103,43 @@ namespace BlackGui ui->cb_ScoreIgnoreZeros->isChecked(), ui->cb_ScorePreferColorLiveries->isChecked() ); } + + CAircraftMatcherSetup::PickSimilarStrategy CMatchingForm::pickStrategy() const + { + if (ui->rb_PickRandom->isChecked()) { return CAircraftMatcherSetup::PickRandom; } + if (ui->rb_PickByOrder->isChecked()) { return CAircraftMatcherSetup::PickByOrder; } + return CAircraftMatcherSetup::PickFirst; + } + + void CMatchingForm::setPickStrategy(const CAircraftMatcherSetup &setup) + { + switch (setup.getPickStrategy()) + { + case CAircraftMatcherSetup::PickByOrder: ui->rb_PickByOrder->setChecked(true); break; + case CAircraftMatcherSetup::PickRandom: ui->rb_PickRandom->setChecked(true); break; + case CAircraftMatcherSetup::PickFirst: + default: + ui->rb_PickFirst->setChecked(true); break; + } + } + + void CMatchingForm::setMatchingAlgorithm(const CAircraftMatcherSetup &setup) + { + if (setup.getMatchingAlgorithm() == CAircraftMatcherSetup::MatchingScoreBased) + { + ui->rb_ScoreBased->setChecked(true); + } + else + { + ui->rb_Reduction->setChecked(true); + } + } + + void CMatchingForm::onAlgorithmChanged(bool checked) + { + Q_UNUSED(checked); + const CAircraftMatcherSetup setup = this->value(); + this->setValue(setup); + } } // ns } // ns diff --git a/src/blackgui/editors/matchingform.h b/src/blackgui/editors/matchingform.h index ff1f5c1eb..8705eae02 100644 --- a/src/blackgui/editors/matchingform.h +++ b/src/blackgui/editors/matchingform.h @@ -55,6 +55,18 @@ namespace BlackGui //! Mode BlackMisc::Simulation::CAircraftMatcherSetup::MatchingMode matchingMode() const; + //! Stragey + BlackMisc::Simulation::CAircraftMatcherSetup::PickSimilarStrategy pickStrategy() const; + + //! Set the pick strategy + void setPickStrategy(const BlackMisc::Simulation::CAircraftMatcherSetup &setup); + + //! Set the matching mode + void setMatchingAlgorithm(const BlackMisc::Simulation::CAircraftMatcherSetup &setup); + + //! Algorithm has been toggled + void onAlgorithmChanged(bool checked); + QScopedPointer ui; }; } // ns diff --git a/src/blackgui/editors/matchingform.ui b/src/blackgui/editors/matchingform.ui index 144c78d40..33e9b8a08 100644 --- a/src/blackgui/editors/matchingform.ui +++ b/src/blackgui/editors/matchingform.ui @@ -6,8 +6,8 @@ 0 0 - 243 - 239 + 247 + 304 @@ -31,18 +31,55 @@ Algorithm - - + + + + + reduction + + + + reduction, then score based - - + + - reduction + reset + + + + + + + + + + Similar results (strategy) + + + + + + first + + + + + + + random + + + + + + + order (higher rank first) @@ -55,28 +92,35 @@ Reduction - - + + - combined code + by ICAO: airline first - - - - by livery - - - - + by family - + + + + combined code + + + + + + + by livery + + + + by model string @@ -90,10 +134,10 @@ - - - - by ICAO: airline first + + + + Qt::Horizontal @@ -128,11 +172,15 @@ rb_ScoreBased rb_Reduction + pb_Reset + rb_PickFirst + rb_PickRandom + rb_PickByOrder rb_ByIcaoDataAircraft1st rb_ByIcaoDataAirline1st cb_ByModelString - cb_ByFamily cb_ByLivery + cb_ByFamily cb_ByCombinedCode cb_ScorePreferColorLiveries cb_ScoreIgnoreZeros