From 2b4d71bb2871cb69be87db68baa00eb3fbd319ad Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 10 May 2019 21:54:20 +0200 Subject: [PATCH] Ref T658, settings for matching (dirs/UI) --- src/blackgui/editors/matchingform.cpp | 38 ++++++++- src/blackgui/editors/matchingform.h | 3 + src/blackgui/editors/matchingform.ui | 77 ++++++++++++++++++- .../simulation/aircraftmatchersetup.cpp | 20 ++++- .../simulation/aircraftmatchersetup.h | 36 ++++++++- 5 files changed, 163 insertions(+), 11 deletions(-) diff --git a/src/blackgui/editors/matchingform.cpp b/src/blackgui/editors/matchingform.cpp index 88201f39a..4d1aa1070 100644 --- a/src/blackgui/editors/matchingform.cpp +++ b/src/blackgui/editors/matchingform.cpp @@ -9,7 +9,9 @@ #include "ui_matchingform.h" #include "matchingform.h" #include "guiutility.h" + #include +#include using namespace BlackMisc; using namespace BlackMisc::Simulation; @@ -29,6 +31,8 @@ namespace BlackGui connect(ui->rb_ScoreOnly, &QRadioButton::released, this, &CMatchingForm::onAlgorithmChanged, Qt::QueuedConnection); connect(ui->pb_ResetAlgorithm, &QPushButton::released, this, &CMatchingForm::resetByAlgorithm, Qt::QueuedConnection); connect(ui->pb_ResetAll, &QPushButton::released, this, &CMatchingForm::resetAll, Qt::QueuedConnection); + connect(ui->pb_MsNetwork, &QPushButton::released, this, &CMatchingForm::fileDialog, Qt::QueuedConnection); + connect(ui->pb_MsMatching, &QPushButton::released, this, &CMatchingForm::fileDialog, Qt::QueuedConnection); } CMatchingForm::~CMatchingForm() @@ -61,6 +65,11 @@ namespace BlackGui ui->rb_PickFirst->setEnabled(enabled); ui->rb_PickByOrder->setEnabled(enabled); ui->rb_PickRandom->setEnabled(enabled); + + ui->le_MsNetwork->setEnabled(enabled); + ui->le_MsMatching->setEnabled(enabled); + CGuiUtility::checkBoxReadOnly(ui->cb_MsNetwork, readonly); + CGuiUtility::checkBoxReadOnly(ui->cb_MsMatching, readonly); } CStatusMessageList CMatchingForm::validate(bool withNestedForms) const @@ -94,11 +103,20 @@ namespace BlackGui this->setMatchingAlgorithm(setup); this->setPickStrategy(setup); + + ui->cb_MsNetwork->setChecked(setup.isMsNetworkEntryEnabled()); + ui->cb_MsMatching->setChecked(setup.isMsMatchingStageEnabled()); + ui->le_MsNetwork->setText(setup.getMsNetworkEntryFile()); + ui->le_MsMatching->setText(setup.getMsMatchingStageFile()); } CAircraftMatcherSetup CMatchingForm::value() const { - const CAircraftMatcherSetup setup(algorithm(), matchingMode(), pickStrategy()); + CAircraftMatcherSetup setup(algorithm(), matchingMode(), pickStrategy()); + setup.setMsNetworkEntryFile(ui->le_MsNetwork->text()); + setup.setMsMatchingStageFile(ui->le_MsMatching->text()); + setup.setMsNetworkEntryEnabled(ui->cb_MsNetwork->isChecked()); + setup.setMsMatchingStageEnabled(ui->cb_MsMatching->isChecked()); return setup; } @@ -119,6 +137,23 @@ namespace BlackGui this->setValue(s); } + void CMatchingForm::fileDialog() + { + const bool nw = (QObject::sender() == ui->pb_MsNetwork); + QString fn = nw ? ui->le_MsNetwork->text() : ui->le_MsMatching->text(); + fn = QFileDialog::getOpenFileName(nullptr, tr("Matching script"), fn, "Matching script (*.js)"); + const QFileInfo fi(fn); + if (!fi.exists()) { return; } + if (nw) + { + ui->le_MsNetwork->setText(fi.absoluteFilePath()); + } + else + { + ui->le_MsMatching->setText(fi.absoluteFilePath()); + } + } + CAircraftMatcherSetup::MatchingAlgorithm CMatchingForm::algorithm() const { if (ui->rb_Reduction->isChecked()) { return CAircraftMatcherSetup::MatchingStepwiseReduce; } @@ -193,6 +228,5 @@ namespace BlackGui 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 cb987323a..a10493907 100644 --- a/src/blackgui/editors/matchingform.h +++ b/src/blackgui/editors/matchingform.h @@ -71,6 +71,9 @@ namespace BlackGui void resetAll(); //! } + //! Directory browser + void fileDialog(); + QScopedPointer ui; }; } // ns diff --git a/src/blackgui/editors/matchingform.ui b/src/blackgui/editors/matchingform.ui index af79352eb..ab60a4e5a 100644 --- a/src/blackgui/editors/matchingform.ui +++ b/src/blackgui/editors/matchingform.ui @@ -7,7 +7,7 @@ 0 0 293 - 559 + 647 @@ -70,6 +70,71 @@ + + + + Matching script + + + + + + Matching: + + + + + + + [...] + + + + + + + network entry matching script file + + + + + + + matching stage matching script file + + + + + + + [...] + + + + + + + Network: + + + + + + + + + + + + + + + + + + + + @@ -312,9 +377,17 @@ + pb_ResetAll + rb_Reduction rb_ScoreOnly rb_ScoreAndReduction pb_ResetAlgorithm + le_MsNetwork + cb_MsNetwork + pb_MsNetwork + le_MsMatching + cb_MsMatching + pb_MsMatching rb_PickFirst rb_PickRandom rb_PickByOrder @@ -337,8 +410,6 @@ cb_ExclNoDbData cb_ScorePreferColorLiveries cb_ScoreIgnoreZeros - pb_ResetAll - rb_Reduction diff --git a/src/blackmisc/simulation/aircraftmatchersetup.cpp b/src/blackmisc/simulation/aircraftmatchersetup.cpp index 56da9ccae..e637d386c 100644 --- a/src/blackmisc/simulation/aircraftmatchersetup.cpp +++ b/src/blackmisc/simulation/aircraftmatchersetup.cpp @@ -71,7 +71,7 @@ namespace BlackMisc return u"algorithm: '" % this->getMatchingAlgorithmAsString() % u"' mode: '" % this->getMatchingModeAsString() % u"' strategy: '" % this->getPickStrategyAsString() % - u'\''; + u"\' matching script: " % boolToOnOff(m_msNetworkEnabled) % u'/' % boolToOnOff(m_msMatchingEnabled); } CVariant CAircraftMatcherSetup::propertyByIndex(const CPropertyIndex &index) const @@ -80,9 +80,13 @@ namespace BlackMisc const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexMatchingAlgorithm: return CVariant::fromValue(m_algorithm); - case IndexMatchingMode: return CVariant::fromValue(m_mode); - case IndexPickStrategy: return CVariant::fromValue(m_strategy); + case IndexMatchingAlgorithm: return CVariant::fromValue(m_algorithm); + case IndexMatchingMode: return CVariant::fromValue(m_mode); + case IndexPickStrategy: return CVariant::fromValue(m_strategy); + case IndexMsNetworkEntryFile: return CVariant::fromValue(m_msNetworkEntryFile); + case IndexMsMatchingStageFile: return CVariant::fromValue(m_msMatchingStageFile); + case IndexMsNetworkEnabled: return CVariant::fromValue(m_msNetworkEnabled); + case IndexMsMatchingStageEnabled: return CVariant::fromValue(m_msMatchingEnabled); default: break; } return CValueObject::propertyByIndex(index); @@ -97,6 +101,10 @@ namespace BlackMisc case IndexMatchingAlgorithm: m_algorithm = variant.toInt(); break; case IndexMatchingMode: m_mode = variant.toInt(); break; case IndexPickStrategy: m_strategy = variant.toInt(); break; + case IndexMsNetworkEntryFile: m_msNetworkEntryFile = variant.toQString(); break; + case IndexMsMatchingStageFile: m_msMatchingStageFile = variant.toQString(); break; + case IndexMsNetworkEnabled: m_msNetworkEnabled = variant.toBool(); break; + case IndexMsMatchingStageEnabled: m_msNetworkEnabled = variant.toBool(); break; default: break; } CValueObject::setPropertyByIndex(index, variant); @@ -105,6 +113,10 @@ namespace BlackMisc void CAircraftMatcherSetup::reset() { this->reset(MatchingStepwiseReducePlusScoreBased); + m_msNetworkEntryFile.clear(); + m_msMatchingStageFile.clear(); + m_msNetworkEnabled = false; + m_msMatchingEnabled = false; } void CAircraftMatcherSetup::reset(CAircraftMatcherSetup::MatchingAlgorithm algorithm) diff --git a/src/blackmisc/simulation/aircraftmatchersetup.h b/src/blackmisc/simulation/aircraftmatchersetup.h index ec6003c4e..1ada9815d 100644 --- a/src/blackmisc/simulation/aircraftmatchersetup.h +++ b/src/blackmisc/simulation/aircraftmatchersetup.h @@ -94,7 +94,11 @@ namespace BlackMisc { IndexMatchingAlgorithm = CPropertyIndex::GlobalIndexCAircraftMatcherSetup, IndexMatchingMode, - IndexPickStrategy + IndexPickStrategy, + IndexMsNetworkEntryFile, + IndexMsMatchingStageFile, + IndexMsNetworkEnabled, + IndexMsMatchingStageEnabled }; //! Constructor @@ -118,6 +122,26 @@ namespace BlackMisc //! Matching mode MatchingMode getMatchingMode() const { return static_cast(m_mode); } + //! Get matching files @{ + const QString &getMsNetworkEntryFile() const { return m_msNetworkEntryFile; } + const QString &getMsMatchingStageFile() const { return m_msMatchingStageFile; } + //! @} + + //! Set matching files @{ + void setMsNetworkEntryFile(const QString &file) { m_msNetworkEntryFile = file; } + void setMsMatchingStageFile(const QString &file) { m_msMatchingStageFile = file; } + //! @} + + //! Is matching script enabled @{ + bool isMsNetworkEntryEnabled() const { return m_msNetworkEnabled; } + bool isMsMatchingStageEnabled() const { return m_msMatchingEnabled; } + //! @} + + //! Is matching script enabled @{ + void setMsNetworkEntryEnabled(bool enabled) { m_msNetworkEnabled = enabled; } + void setMsMatchingStageEnabled(bool enabled) { m_msMatchingEnabled = enabled; } + //! @} + //! Verification at startup? //! \sa ModelVerificationOnStartup bool doVerificationAtStartup() const { return this->getMatchingMode().testFlag(ModelVerificationAtStartup); } @@ -199,12 +223,20 @@ namespace BlackMisc int m_algorithm = static_cast(MatchingStepwiseReducePlusScoreBased); int m_mode = static_cast(ModeDefaultReducePlusScore); int m_strategy = static_cast(PickByOrder); + QString m_msNetworkEntryFile; //!< network entry matching script file + QString m_msMatchingStageFile; //!< matching stage matching script file + bool m_msNetworkEnabled = false; //!< enable network matching script + bool m_msMatchingEnabled = false; //!< enable matching stage matching script BLACK_METACLASS( CAircraftMatcherSetup, BLACK_METAMEMBER(algorithm), BLACK_METAMEMBER(mode), - BLACK_METAMEMBER(strategy) + BLACK_METAMEMBER(strategy), + BLACK_METAMEMBER(msNetworkEntryFile), + BLACK_METAMEMBER(msMatchingStageFile), + BLACK_METAMEMBER(msNetworkEnabled), + BLACK_METAMEMBER(msMatchingEnabled) ); }; } // ns