From 541fd4bd617bc56b99c162c3a2a8075bc5ae2268 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 27 Oct 2018 20:50:54 +0200 Subject: [PATCH] Matcher settings as dialog so they can be changed in mapping tool model matcher for testing --- .../components/modelmatchercomponent.cpp | 30 +++++-- .../components/modelmatchercomponent.h | 6 ++ .../components/modelmatchercomponent.ui | 13 ++- .../components/settingsmatchingcomponent.cpp | 33 ++++++-- .../components/settingsmatchingcomponent.h | 10 +++ .../components/settingsmatchingcomponent.ui | 4 +- .../components/settingsmatchingdialog.cpp | 39 +++++++++ .../components/settingsmatchingdialog.h | 48 +++++++++++ .../components/settingsmatchingdialog.ui | 82 +++++++++++++++++++ 9 files changed, 247 insertions(+), 18 deletions(-) create mode 100644 src/blackgui/components/settingsmatchingdialog.cpp create mode 100644 src/blackgui/components/settingsmatchingdialog.h create mode 100644 src/blackgui/components/settingsmatchingdialog.ui diff --git a/src/blackgui/components/modelmatchercomponent.cpp b/src/blackgui/components/modelmatchercomponent.cpp index f7ae63ed5..b7cb6f37c 100644 --- a/src/blackgui/components/modelmatchercomponent.cpp +++ b/src/blackgui/components/modelmatchercomponent.cpp @@ -7,18 +7,19 @@ * contained in the LICENSE file. */ -#include "blackcore/webdataservices.h" -#include "blackgui/components/aircraftcombinedtypeselector.h" -#include "blackgui/components/dbaircrafticaoselectorcomponent.h" -#include "blackgui/components/dbairlineicaoselectorcomponent.h" -#include "blackgui/components/dbliveryselectorcomponent.h" -#include "blackgui/components/modelmatchercomponent.h" -#include "blackgui/components/simulatorselector.h" +#include "aircraftcombinedtypeselector.h" +#include "dbaircrafticaoselectorcomponent.h" +#include "dbairlineicaoselectorcomponent.h" +#include "dbliveryselectorcomponent.h" +#include "modelmatchercomponent.h" +#include "settingsmatchingdialog.h" +#include "simulatorselector.h" #include "blackgui/models/statusmessagelistmodel.h" #include "blackgui/views/statusmessageview.h" #include "blackgui/uppercasevalidator.h" #include "blackgui/guiapplication.h" #include "blackgui/guiutility.h" +#include "blackcore/webdataservices.h" #include "blackmisc/simulation/data/modelcaches.h" #include "blackmisc/aviation/aircrafticaocode.h" #include "blackmisc/aviation/airlineicaocode.h" @@ -71,9 +72,11 @@ namespace BlackGui ui->le_Callsign->setValidator(validator); connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CModelMatcherComponent::onSimulatorChanged); + connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CModelMatcherComponent::onWebDataRead, Qt::QueuedConnection); + connect(ui->pb_ModelMatching, &QPushButton::pressed, this, &CModelMatcherComponent::testModelMatching); connect(ui->pb_ReverseLookup, &QPushButton::pressed, this, &CModelMatcherComponent::reverseLookup); - connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CModelMatcherComponent::onWebDataRead, Qt::QueuedConnection); + connect(ui->pb_Settings, &QPushButton::pressed, this, &CModelMatcherComponent::displaySettingsDialog); this->redisplay(); } @@ -146,6 +149,17 @@ namespace BlackGui } } + void CModelMatcherComponent::displaySettingsDialog() + { + if (!m_settingsDialog) { m_settingsDialog = new CSettingsMatchingDialog(this); } + m_settingsDialog->setMatchingSetup(m_matcher.getSetup()); + const QDialog::DialogCode r = static_cast(m_settingsDialog->exec()); + if (r == QDialog::Accepted) + { + m_settingsDialog->setMatchingSetup(m_settingsDialog->getMatchingSetup()); + } + } + void CModelMatcherComponent::redisplay() { const int c = this->getModelSetModelsCount(); diff --git a/src/blackgui/components/modelmatchercomponent.h b/src/blackgui/components/modelmatchercomponent.h index c780f218c..030cd894a 100644 --- a/src/blackgui/components/modelmatchercomponent.h +++ b/src/blackgui/components/modelmatchercomponent.h @@ -28,6 +28,8 @@ namespace BlackGui { namespace Components { + class CSettingsMatchingDialog; + /*! * Model matcher testing and configuration */ @@ -55,6 +57,9 @@ namespace BlackGui //! Web data have been read void onWebDataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number); + //! Display settings dialog + void displaySettingsDialog(); + //! Run the matcher void testModelMatching(); @@ -77,6 +82,7 @@ namespace BlackGui BlackMisc::Simulation::CAircraftModel defaultModel() const; QScopedPointer ui; + CSettingsMatchingDialog *m_settingsDialog = nullptr; BlackCore::CAircraftMatcher m_matcher { this }; //!< used matcher }; } // ns diff --git a/src/blackgui/components/modelmatchercomponent.ui b/src/blackgui/components/modelmatchercomponent.ui index 461d9d041..c2b473dbe 100644 --- a/src/blackgui/components/modelmatchercomponent.ui +++ b/src/blackgui/components/modelmatchercomponent.ui @@ -6,8 +6,8 @@ 0 0 - 356 - 340 + 478 + 561 @@ -139,6 +139,13 @@ + + + + settings + + + @@ -159,7 +166,7 @@ use reverse lookup for model matching - with lookup + with reverse lookup true diff --git a/src/blackgui/components/settingsmatchingcomponent.cpp b/src/blackgui/components/settingsmatchingcomponent.cpp index 7f78cee63..9fb83f0f8 100644 --- a/src/blackgui/components/settingsmatchingcomponent.cpp +++ b/src/blackgui/components/settingsmatchingcomponent.cpp @@ -32,22 +32,45 @@ namespace BlackGui connect(ui->pb_Reload, &QPushButton::released, this, &CSettingsMatchingComponent::onReloadPressed); connect(ui->pb_MatchingAgain, &QPushButton::released, this, &CSettingsMatchingComponent::onMatchingsAgainPressed); + // also used in mapping tool, must also work without contexts IContextSimulator *simContext = simulatorContext(); if (simContext) { connect(simContext, &IContextSimulator::matchingSetupChanged, this, &CSettingsMatchingComponent::onSetupChanged, Qt::QueuedConnection); + this->deferredReload(5000); + } + else + { + this->showButtons(false); } - this->deferredReload(5000); } CSettingsMatchingComponent::~CSettingsMatchingComponent() { } + CAircraftMatcherSetup CSettingsMatchingComponent::getMatchingSetup() const + { + return ui->form_Matching->value(); + } + + void CSettingsMatchingComponent::setMatchingSetup(const CAircraftMatcherSetup &setup) + { + ui->form_Matching->setValue(setup); + } + + void CSettingsMatchingComponent::showButtons(bool show) + { + ui->fr_Buttons->setVisible(show); + // ui->pb_MatchingAgain->setVisible(show); + // ui->pb_Reload->setVisible(show); + // ui->pb_Save->setVisible(show); + } + void CSettingsMatchingComponent::onSavePressed() const { IContextSimulator *simContext = simulatorContext(); if (!simContext) { return; } - const CAircraftMatcherSetup setup = ui->editor_MatchingForm->value(); + const CAircraftMatcherSetup setup = ui->form_Matching->value(); simContext->setMatchingSetup(setup); } @@ -72,12 +95,12 @@ namespace BlackGui void CSettingsMatchingComponent::deferredReload(int deferMs) { + IContextSimulator *simContext = simulatorContext(); + if (!simContext) { return; } if (deferMs < 1) { - IContextSimulator *simContext = simulatorContext(); - if (!simContext) { return; } const CAircraftMatcherSetup setup = simContext->getMatchingSetup(); - ui->editor_MatchingForm->setValue(setup); + ui->form_Matching->setValue(setup); } else { diff --git a/src/blackgui/components/settingsmatchingcomponent.h b/src/blackgui/components/settingsmatchingcomponent.h index 852b50173..f49297ba3 100644 --- a/src/blackgui/components/settingsmatchingcomponent.h +++ b/src/blackgui/components/settingsmatchingcomponent.h @@ -12,6 +12,7 @@ #ifndef BLACKGUI_COMPONENTS_SETTINGSMATCHINGCOMPONENT_H #define BLACKGUI_COMPONENTS_SETTINGSMATCHINGCOMPONENT_H +#include "blackmisc/simulation/aircraftmatchersetup.h" #include #include @@ -33,6 +34,15 @@ namespace BlackGui //! Destructor virtual ~CSettingsMatchingComponent() override; + //! Get setup + BlackMisc::Simulation::CAircraftMatcherSetup getMatchingSetup() const; + + //! Set setup + void setMatchingSetup(const BlackMisc::Simulation::CAircraftMatcherSetup &setup); + + //! Show buttons + void showButtons(bool show); + private: QScopedPointer ui; diff --git a/src/blackgui/components/settingsmatchingcomponent.ui b/src/blackgui/components/settingsmatchingcomponent.ui index dcf84120e..d60192165 100644 --- a/src/blackgui/components/settingsmatchingcomponent.ui +++ b/src/blackgui/components/settingsmatchingcomponent.ui @@ -54,7 +54,7 @@ 0 - + 0 @@ -68,7 +68,7 @@ - + diff --git a/src/blackgui/components/settingsmatchingdialog.cpp b/src/blackgui/components/settingsmatchingdialog.cpp new file mode 100644 index 000000000..06dd66259 --- /dev/null +++ b/src/blackgui/components/settingsmatchingdialog.cpp @@ -0,0 +1,39 @@ +/* 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 "settingsmatchingdialog.h" +#include "ui_settingsmatchingdialog.h" + +using namespace BlackMisc::Simulation; + +namespace BlackGui +{ + namespace Components + { + CSettingsMatchingDialog::CSettingsMatchingDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::CSettingsMatchingDialog) + { + ui->setupUi(this); + } + + CSettingsMatchingDialog::~CSettingsMatchingDialog() + { } + + CAircraftMatcherSetup CSettingsMatchingDialog::getMatchingSetup() const + { + return ui->comp_Settings->getMatchingSetup(); + } + + void CSettingsMatchingDialog::setMatchingSetup(const CAircraftMatcherSetup &setup) + { + ui->comp_Settings->setMatchingSetup(setup); + } + } // ns +} // ns diff --git a/src/blackgui/components/settingsmatchingdialog.h b/src/blackgui/components/settingsmatchingdialog.h new file mode 100644 index 000000000..647ab5861 --- /dev/null +++ b/src/blackgui/components/settingsmatchingdialog.h @@ -0,0 +1,48 @@ +/* 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 BLACKGUI_COMPONENTS_SETTINGSMATCHINGDIALOG_H +#define BLACKGUI_COMPONENTS_SETTINGSMATCHINGDIALOG_H + +#include "blackmisc/simulation/aircraftmatchersetup.h" +#include +#include + +namespace Ui { class CSettingsMatchingDialog; } +namespace BlackGui +{ + namespace Components + { + //! Matching settings as dialog + class CSettingsMatchingDialog : public QDialog + { + Q_OBJECT + + public: + //! Matching settings as dialog + explicit CSettingsMatchingDialog(QWidget *parent = nullptr); + + //! Destructor + virtual ~CSettingsMatchingDialog(); + + //! Get setup + BlackMisc::Simulation::CAircraftMatcherSetup getMatchingSetup() const; + + //! Set the setup + void setMatchingSetup(const BlackMisc::Simulation::CAircraftMatcherSetup &setup); + + private: + QScopedPointer ui; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/settingsmatchingdialog.ui b/src/blackgui/components/settingsmatchingdialog.ui new file mode 100644 index 000000000..1fe8dca7d --- /dev/null +++ b/src/blackgui/components/settingsmatchingdialog.ui @@ -0,0 +1,82 @@ + + + CSettingsMatchingDialog + + + + 0 + 0 + 640 + 480 + + + + Matcher setup + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + BlackGui::Components::CSettingsMatchingComponent + QFrame +
blackgui/components/settingsmatchingcomponent.h
+ 1 +
+
+ + + + bb_SettingsMatchingDialog + accepted() + CSettingsMatchingDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + bb_SettingsMatchingDialog + rejected() + CSettingsMatchingDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +