From 305a1a34c22b8a5b86c04c7a3ca10b043d5bcf4c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 27 Mar 2019 02:55:49 +0100 Subject: [PATCH] Ref T578, allow to use workbench data in matcher component for testing --- .../components/dbmappingcomponent.cpp | 3 + .../components/modelmatchercomponent.cpp | 64 +++- .../components/modelmatchercomponent.h | 17 +- .../components/modelmatchercomponent.ui | 301 ++++++++++-------- 4 files changed, 239 insertions(+), 146 deletions(-) diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index 8f97a2117..562261ee1 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -134,6 +134,9 @@ namespace BlackGui this->onStashedModelsDataChangedDigest(ui->comp_StashAircraft->view()->rowCount(), ui->comp_StashAircraft->view()->hasFilter()); this->onOwnModelsChangedDigest(ui->comp_OwnAircraftModels->view()->rowCount(), ui->comp_OwnAircraftModels->view()->hasFilter()); + // allow to use workbench data + ui->comp_ModelMatcher->setWorkbenchView(ui->comp_ModelWorkbench->view()); + // how to display forms ui->editor_AircraftModel->setSelectOnly(); diff --git a/src/blackgui/components/modelmatchercomponent.cpp b/src/blackgui/components/modelmatchercomponent.cpp index da7b9406c..605cf1483 100644 --- a/src/blackgui/components/modelmatchercomponent.cpp +++ b/src/blackgui/components/modelmatchercomponent.cpp @@ -15,6 +15,7 @@ #include "simulatorselector.h" #include "blackgui/models/statusmessagelistmodel.h" #include "blackgui/views/statusmessageview.h" +#include "blackgui/views/aircraftmodelview.h" #include "blackgui/uppercasevalidator.h" #include "blackgui/guiapplication.h" #include "blackgui/guiutility.h" @@ -32,8 +33,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -77,7 +78,10 @@ namespace BlackGui connect(ui->pb_ReverseLookup, &QPushButton::pressed, this, &CModelMatcherComponent::reverseLookup); connect(ui->pb_Settings, &QPushButton::pressed, this, &CModelMatcherComponent::displaySettingsDialog); + connect(ui->cb_UseWorkbench, &QCheckBox::toggled, this, &CModelMatcherComponent::onWorkbenchToggled); + this->redisplay(); + ui->cb_UseWorkbench->setVisible(false); } CModelMatcherComponent::~CModelMatcherComponent() @@ -94,14 +98,51 @@ namespace BlackGui this->redisplay(); } + void CModelMatcherComponent::setWorkbenchView(Views::CAircraftModelView *workbenchView) + { + if (workbenchView) + { + ui->cb_UseWorkbench->setVisible(true); + m_workbenchView = workbenchView; + } + else + { + ui->cb_UseWorkbench->setVisible(false); + m_workbenchView.clear(); + } + } + void CModelMatcherComponent::onSimulatorChanged(const CSimulatorInfo &simulator) { Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); - const CAircraftModelList models = CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().getCachedModels(simulator); - m_matcher.setModelSet(models, simulator, true); + + ui->tvp_ResultMessages->clear(); + if (this->useWorkbench()) + { + const CAircraftModelList models = m_workbenchView->container(); + if (models.isEmpty()) + { + CStatusMessage m(this, CStatusMessage::SeverityWarning, u"No models in workbench, disabled."); + ui->tvp_ResultMessages->insert(m); + return; + } + CSimulatorInfo simulator = models.simulatorsWithMaxEntries(); + m_matcher.setModelSet(models, simulator, true); + } + else + { + const CAircraftModelList models = CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().getCachedModels(simulator); + m_matcher.setModelSet(models, simulator, true); + } this->redisplay(); } + void CModelMatcherComponent::onWorkbenchToggled(bool checked) + { + Q_UNUSED(checked); + this->onSimulatorChanged(ui->comp_SimulatorSelector->getValue()); + } + void CModelMatcherComponent::onCacheChanged(CSimulatorInfo &simulator) { Q_UNUSED(simulator); @@ -118,7 +159,7 @@ namespace BlackGui { const QString liveryString(ui->comp_LiverySelector->getRawCombinedCode()); const CAircraftModel reverseModel = CAircraftMatcher::reverseLookupModel(remoteAircraft.getModel(), liveryString, &msgs); - remoteAircraft.setModel(reverseModel); + remoteAircraft.setModel(reverseModel); // current model } m_matcher.setDefaultModel(CModelMatcherComponent::defaultModel()); @@ -163,8 +204,8 @@ namespace BlackGui void CModelMatcherComponent::redisplay() { - const int c = this->getModelSetModelsCount(); - ui->le_ModelSetCount->setText(QString::number(c)); + const int c = this->getMatcherModelsCount(); + ui->le_ModelSetCount->setText(QString::number(c) % (this->useWorkbench() ? u" (workbench)" : u"")); } CAircraftModelList CModelMatcherComponent::getModelSetModels() const @@ -174,11 +215,14 @@ namespace BlackGui return models; } - int CModelMatcherComponent::getModelSetModelsCount() const + int CModelMatcherComponent::getMatcherModelsCount() const { - const CSimulatorInfo simulator = ui->comp_SimulatorSelector->getValue(); - const int modelCount = CCentralMultiSimulatorModelSetCachesProvider::modelCachesInstance().getCachedModelsCount(simulator); - return modelCount; + return m_matcher.getModelSetCount(); + } + + bool CModelMatcherComponent::useWorkbench() const + { + return ui->cb_UseWorkbench->isChecked() && m_workbenchView; } CSimulatedAircraft CModelMatcherComponent::createAircraft() const diff --git a/src/blackgui/components/modelmatchercomponent.h b/src/blackgui/components/modelmatchercomponent.h index 9f7ea0b4a..977fbeb5f 100644 --- a/src/blackgui/components/modelmatchercomponent.h +++ b/src/blackgui/components/modelmatchercomponent.h @@ -20,11 +20,13 @@ #include #include +#include #include namespace Ui { class CModelMatcherComponent; } namespace BlackGui { + namespace Views { class CAircraftModelView; } namespace Components { class CSettingsMatchingDialog; @@ -41,15 +43,21 @@ namespace BlackGui explicit CModelMatcherComponent(QWidget *parent = nullptr); //! Destructor - virtual ~CModelMatcherComponent(); + virtual ~CModelMatcherComponent() override; //! Tab (where this component is embedded) has been changed void tabIndexChanged(int index); + //! Set an external + void setWorkbenchView(Views::CAircraftModelView *workbenchView); + private: //! Simulator switched void onSimulatorChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator); + //! Workbench toggled + void onWorkbenchToggled(bool checked); + //! Cache changed void onCacheChanged(BlackMisc::Simulation::CSimulatorInfo &simulator); @@ -72,7 +80,10 @@ namespace BlackGui BlackMisc::Simulation::CAircraftModelList getModelSetModels() const; //! The current model set models size - int getModelSetModelsCount() const; + int getMatcherModelsCount() const; + + //! Use workbench data + bool useWorkbench() const; //! Pseudo aircraft created from entries BlackMisc::Simulation::CSimulatedAircraft createAircraft() const; @@ -81,6 +92,8 @@ namespace BlackGui BlackMisc::Simulation::CAircraftModel defaultModel() const; QScopedPointer ui; + + QPointer m_workbenchView; //!< an external workbenc CSettingsMatchingDialog *m_settingsDialog = nullptr; //!< matching settings as dialog BlackCore::CAircraftMatcher m_matcher { this }; //!< used matcher }; diff --git a/src/blackgui/components/modelmatchercomponent.ui b/src/blackgui/components/modelmatchercomponent.ui index 1088e2a8b..f86f111a9 100644 --- a/src/blackgui/components/modelmatchercomponent.ui +++ b/src/blackgui/components/modelmatchercomponent.ui @@ -32,27 +32,21 @@ 0 - - - - - 100 - 0 - - - - Qt::StrongFocus - - - - + Qt::StrongFocus - + + + + Livery: + + + + @@ -65,59 +59,7 @@ - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - - true - - - - - - - QAbstractItemView::SingleSelection - - - QAbstractItemView::SelectRows - - - false - - - - - - - - - - Qt::StrongFocus - - - - - - - - 100 - 0 - - - - Qt::StrongFocus - - - - + @@ -182,69 +124,80 @@ - - - - Model: - - - - - - - Aircraft: - - - - - - - Airline: - - - - - - - Combined: - - - - - - - Livery: - - - - - - - model string - - - - - - - Simulator: - - - - + e.g. Cessna - + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + true + + + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + + + + + Manufacturer: + + + + model string + + + + + + + Aircraft: + + + + + + + Model: + + + + + + + Airline: + + + @@ -252,27 +205,105 @@ - - - - true - - - - - - - Callsign: - - - - + e.g. DAMBZ + + + + Simulator: + + + + + + + Qt::StrongFocus + + + + + + + + 100 + 0 + + + + Qt::StrongFocus + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + true + + + + + + + use workbench + + + + + + + + + + + 100 + 0 + + + + Qt::StrongFocus + + + + + + + Combined: + + + + + + + Callsign: + + + @@ -315,6 +346,7 @@ comp_SimulatorSelector le_ModelSetCount + cb_UseWorkbench comp_AircraftSelector comp_AirlineSelector comp_CombinedCode @@ -322,6 +354,7 @@ le_Manufacturer le_Callsign le_ModelString + pb_Settings pb_ReverseLookup pb_ModelMatching cb_withReverseLookup