From 24a1f7d96de15a4e5a6f0aa6976b75cd8b955f84 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 22 Jul 2018 18:19:26 +0200 Subject: [PATCH] Ref T292, adjusted UI components to reflect model loader changes --- .../aircraftmodelstringcompleter.cpp | 17 ++++++++--------- ...ymodelsfromotherswiftversionscomponent.cpp | 10 ++++------ src/blackgui/components/dbloaddatadialog.cpp | 19 ++++++++++++------- .../components/dbownmodelsetcomponent.cpp | 11 ++++++----- .../components/dbownmodelsetcomponent.h | 16 ++++++++-------- src/blackgui/components/dbstashcomponent.ui | 5 ++++- .../components/firstmodelsetcomponent.cpp | 10 +++++----- 7 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/blackgui/components/aircraftmodelstringcompleter.cpp b/src/blackgui/components/aircraftmodelstringcompleter.cpp index 08ff6d4ae..797ddcb48 100644 --- a/src/blackgui/components/aircraftmodelstringcompleter.cpp +++ b/src/blackgui/components/aircraftmodelstringcompleter.cpp @@ -44,22 +44,21 @@ namespace BlackGui connect(ui->rb_OwnModels, &QRadioButton::clicked, this, &CAircraftModelStringCompleter::initGui); connect(&m_modelCaches, &CModelCaches::cacheChanged, this, &CAircraftModelStringCompleter::setSimulator, Qt::QueuedConnection); - CSimulatorInfo sim = CSimulatorInfo(CSimulatorInfo::P3D); // default + CSimulatorInfo simulator = CSimulatorInfo(CSimulatorInfo::P3D); // default if (sGui->getIContextSimulator()) { connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CAircraftModelStringCompleter::onSimulatorConnected); - sim = sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator(); - if (sim.isSingleSimulator()) + CSimulatorInfo pluginSimulator = sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator(); + if (pluginSimulator.isSingleSimulator()) { - m_modelCaches.setCurrentSimulator(sim); + simulator = pluginSimulator; } else { - this->setSourceVisible(OwnModels, false); - sim = m_modelCaches.getCurrentSimulator(); + this->setSourceVisible(OwnModels, false); // hide own models } } - this->setSimulator(sim); + this->setSimulator(simulator); } CAircraftModelStringCompleter::~CAircraftModelStringCompleter() @@ -106,9 +105,9 @@ namespace BlackGui bool CAircraftModelStringCompleter::setSimulator(const CSimulatorInfo &simulator) { + if (simulator.isSingleSimulator()) { return false; } if (this->getSimulator() == simulator) { return false; } m_currentSimulator = simulator; - m_modelCaches.setCurrentSimulator(simulator); // all models QPointer myself(this); QTimer::singleShot(100, this, [ = ] { @@ -150,7 +149,7 @@ namespace BlackGui else if (ui->rb_OwnModels->isChecked()) { if (!simChanged && m_currentDataSource == OwnModels) { return; } - modelStrings = m_modelCaches.getCurrentCachedModels().toCompleterStrings(); + modelStrings = m_modelCaches.getCachedModels(this->getSimulator()).toCompleterStrings(); dataSource = OwnModels; } diff --git a/src/blackgui/components/copymodelsfromotherswiftversionscomponent.cpp b/src/blackgui/components/copymodelsfromotherswiftversionscomponent.cpp index 361dbb4bd..b090ebc07 100644 --- a/src/blackgui/components/copymodelsfromotherswiftversionscomponent.cpp +++ b/src/blackgui/components/copymodelsfromotherswiftversionscomponent.cpp @@ -75,8 +75,7 @@ namespace BlackGui if (set) { // inits current version cache - m_modelSetCaches.setCurrentSimulator(sim); - m_modelSetCaches.synchronizeCurrentCache(); + m_modelSetCaches.synchronizeCache(sim); // get file name CAircraftModelList otherSet; @@ -86,7 +85,7 @@ namespace BlackGui CApplication::processEventsFor(250); if (this->confirmOverride(QString("Override model set for '%1'").arg(sim.toQString()))) { - m_modelSetCaches.setModels(otherSet, sim); + m_modelSetCaches.setModelsForSimulator(otherSet, sim); } } } // set @@ -94,8 +93,7 @@ namespace BlackGui if (cache) { // inits current version cache - m_modelCaches.setCurrentSimulator(sim); - m_modelCaches.synchronizeCurrentCache(); + m_modelCaches.synchronizeCache(sim); // get file name CAircraftModelList otherCache; @@ -105,7 +103,7 @@ namespace BlackGui CApplication::processEventsFor(250); if (this->confirmOverride(QString("Override model cache for '%1'").arg(sim.toQString()))) { - m_modelCaches.setModels(otherCache, sim); + m_modelCaches.setModelsForSimulator(otherCache, sim); } } } diff --git a/src/blackgui/components/dbloaddatadialog.cpp b/src/blackgui/components/dbloaddatadialog.cpp index 5a9cdc3b7..39ff08c83 100644 --- a/src/blackgui/components/dbloaddatadialog.cpp +++ b/src/blackgui/components/dbloaddatadialog.cpp @@ -15,6 +15,7 @@ #include "blackmisc/simulation/aircraftmodellist.h" #include #include +#include using namespace BlackMisc::Network; using namespace BlackMisc::Simulation; @@ -39,13 +40,11 @@ namespace BlackGui ui->bb_loadDataDialog->button(QDialogButtonBox::Apply)->setText("Load"); ui->wi_WorkStatus->setVisible(false); ui->wi_Consolidate->setVisible(false); - ui->comp_SimulatorSelector->setValue(m_sets.getCurrentSimulator()); + ui->comp_SimulatorSelector->setRememberSelection(true); connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbLoadDataDialog::onDataRead, Qt::QueuedConnection); connect(ui->bb_loadDataDialog, &QDialogButtonBox::clicked, this, &CDbLoadDataDialog::onButtonClicked); connect(ui->pb_Consolidate, &QPushButton::clicked, this, &CDbLoadDataDialog::consolidate); connect(this, &CDbLoadDataDialog::rejected, this, &CDbLoadDataDialog::onRejected); - connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, &m_sets, &CModelSetCaches::setCurrentSimulator, Qt::QueuedConnection); - connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, &m_models, &CModelCaches::setCurrentSimulator, Qt::QueuedConnection); } CDbLoadDataDialog::~CDbLoadDataDialog() @@ -124,8 +123,10 @@ namespace BlackGui m_pendingEntitiesCount = -1; const bool defaultConsolidate = !ui->cb_AllModels->isChecked() && ui->cb_ModelSet->isChecked(); + QPointer myself(this); QTimer::singleShot(2000, this, [ = ] { + if (!myself) { return; } ui->wi_Consolidate->setVisible(true); ui->wi_WorkStatus->setVisible(false); if (defaultConsolidate) @@ -154,31 +155,35 @@ namespace BlackGui ui->wi_WorkStatus->setVisible(true); ui->pb_Loading->setValue(0); ui->pb_Loading->setMaximum(0); // 0/0 causing busy indicator + const CSimulatorInfo simulator = ui->comp_SimulatorSelector->getValue(); do { if (set) { ui->le_Info->setText("Model set"); - CAircraftModelList models = m_sets.getCurrentCachedModels(); + CAircraftModelList models = m_sets.getCachedModels(simulator); const int c = CDatabaseUtils::consolidateModelsWithDbDataAllowsGuiRefresh(models, true, true); - if (c > 0) { m_sets.setCachedModels(models, m_sets.getCurrentSimulator()); } + if (c > 0) { m_sets.setCachedModels(models, simulator); } } if (!this->isVisible()) { break; } // dialog closed? if (all) { ui->le_Info->setText("All models"); - CAircraftModelList models = m_models.getCurrentCachedModels(); + CAircraftModelList models = m_models.getCachedModels(simulator); const int c = CDatabaseUtils::consolidateModelsWithDbDataAllowsGuiRefresh(models, true, true); - if (c > 0) { m_models.setCachedModels(models, m_models.getCurrentSimulator()); } + if (c > 0) { m_models.setCachedModels(models, simulator); } } } while (false); m_consolidating = false; + + QPointer myself(this); QTimer::singleShot(2000, this, [ = ] { + if (!myself) { return; } ui->pb_Loading->setMaximum(100); ui->wi_WorkStatus->setVisible(false); if (m_autoConsolidate) diff --git a/src/blackgui/components/dbownmodelsetcomponent.cpp b/src/blackgui/components/dbownmodelsetcomponent.cpp index 49cee120b..3cb80a92a 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.cpp +++ b/src/blackgui/components/dbownmodelsetcomponent.cpp @@ -125,21 +125,22 @@ namespace BlackGui ui->tvp_OwnModelSet->updateContainerMaybeAsync(cleanModelList); } - void CDbOwnModelSetComponent::replaceOrAddModelSet(const CAircraftModelList &models, const CSimulatorInfo &simulator) + int CDbOwnModelSetComponent::replaceOrAddModelSet(const CAircraftModelList &models, const CSimulatorInfo &simulator) { Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator"); - if (models.isEmpty()) { return; } + if (models.isEmpty()) { return 0; } CAircraftModelList cleanModelList(models.matchesSimulator(simulator)); // remove those not matching the simulator const int diff = models.size() - cleanModelList.size(); if (diff > 0) { CLogMessage(this).warning("Removed %1 models from set because not matching %2") << diff << simulator.toQString(true); } - if (cleanModelList.isEmpty()) { return; } + if (cleanModelList.isEmpty()) { return 0; } CAircraftModelList updatedModels(ui->tvp_OwnModelSet->container()); updatedModels.replaceOrAddModelsWithString(cleanModelList, Qt::CaseInsensitive); updatedModels.resetOrder(); ui->tvp_OwnModelSet->updateContainerMaybeAsync(updatedModels); + return diff; } const CAircraftModelList &CDbOwnModelSetComponent::getModelSetFromView() const @@ -233,7 +234,7 @@ namespace BlackGui const CAircraftModelList ml(ui->tvp_OwnModelSet->container()); if (!ml.isEmpty()) { - const CStatusMessage m = m_modelSetLoader.setCachedModels(ml); + const CStatusMessage m = m_modelSetLoader.setCachedModels(ml, this->getSelectedSimulator()); CLogMessage::preformatted(m); } return; @@ -392,7 +393,7 @@ namespace BlackGui const CDistributorList distributors = preferences.getDistributors(simulator); if (distributors.isEmpty()) { return; } modelSet.updateDistributorOrder(distributors); - m_modelSetLoader.setModels(modelSet, simulator); + m_modelSetLoader.setModelsForSimulator(modelSet, simulator); // display? const CSimulatorInfo currentSimulator(this->getModelSetSimulator()); diff --git a/src/blackgui/components/dbownmodelsetcomponent.h b/src/blackgui/components/dbownmodelsetcomponent.h index cdb140194..f1a3349b4 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.h +++ b/src/blackgui/components/dbownmodelsetcomponent.h @@ -50,16 +50,16 @@ namespace BlackGui public CDbMappingComponentAware, public BlackMisc::Simulation::IModelsSetable, public BlackMisc::Simulation::IModelsUpdatable, - public BlackMisc::Simulation::IModelsPerSimulatorSetable, - public BlackMisc::Simulation::IModelsPerSimulatorUpdatable, + public BlackMisc::Simulation::IModelsForSimulatorSetable, + public BlackMisc::Simulation::IModelsForSimulatorUpdatable, public BlackMisc::Simulation::ISimulatorSelectable { Q_OBJECT Q_INTERFACES(BlackGui::Components::CDbMappingComponentAware) Q_INTERFACES(BlackMisc::Simulation::IModelsSetable) Q_INTERFACES(BlackMisc::Simulation::IModelsUpdatable) - Q_INTERFACES(BlackMisc::Simulation::IModelsPerSimulatorSetable) - Q_INTERFACES(BlackMisc::Simulation::IModelsPerSimulatorUpdatable) + Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorSetable) + Q_INTERFACES(BlackMisc::Simulation::IModelsForSimulatorUpdatable) Q_INTERFACES(BlackMisc::Simulation::ISimulatorSelectable) public: @@ -104,9 +104,9 @@ namespace BlackGui //! \name Implementations of the models interfaces //! @{ virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setModelSet(models, this->getModelSetSimulator()); } - virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->replaceOrAddModelSet(models, this->getModelSetSimulator()); } - virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->setModelSet(models, simulator); } - virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->replaceOrAddModelSet(models, simulator); } + virtual void setModelsForSimulator(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->setModelSet(models, simulator); } + virtual int updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { return this->replaceOrAddModelSet(models, this->getModelSetSimulator()); } + virtual int updateModelsForSimulator(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { return this->replaceOrAddModelSet(models, simulator); } virtual BlackMisc::Simulation::CSimulatorInfo getSelectedSimulator() const override { return this->getModelSetSimulator(); } //! @} @@ -117,7 +117,7 @@ namespace BlackGui void setModelSet(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator); //! Replace or add models provided for a given simulator - void replaceOrAddModelSet(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator); + int replaceOrAddModelSet(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator); private: //! Tab has been changed diff --git a/src/blackgui/components/dbstashcomponent.ui b/src/blackgui/components/dbstashcomponent.ui index 3645402ee..f71132c89 100644 --- a/src/blackgui/components/dbstashcomponent.ui +++ b/src/blackgui/components/dbstashcomponent.ui @@ -164,11 +164,14 @@ - selected models only + publish selected models only selected + + true + diff --git a/src/blackgui/components/firstmodelsetcomponent.cpp b/src/blackgui/components/firstmodelsetcomponent.cpp index 08cc6f2c9..fb2b2d45d 100644 --- a/src/blackgui/components/firstmodelsetcomponent.cpp +++ b/src/blackgui/components/firstmodelsetcomponent.cpp @@ -88,8 +88,8 @@ namespace BlackGui // we us the loader of the components directly, // avoid to fully init a loader logic here static const QString modelsNo("No models so far"); - const int modelsCount = this->modelLoader()->getAircraftModelsCount(); - ui->le_ModelsInfo->setText(modelsCount > 0 ? this->modelLoader()->getModelCacheCountAndTimestamp() : modelsNo); + const int modelsCount = this->modelLoader()->getCachedModelsCount(simulator); + ui->le_ModelsInfo->setText(modelsCount > 0 ? this->modelLoader()->getCacheCountAndTimestamp(simulator) : modelsNo); ui->pb_CreateModelSet->setEnabled(modelsCount > 0); static const QString modelsSetNo("Model set is empty"); @@ -214,7 +214,8 @@ namespace BlackGui void CFirstModelSetComponent::createModelSet() { - const int modelsCount = this->modelLoader()->getAircraftModelsCount(); + const CSimulatorInfo sim = ui->comp_SimulatorSelector->getValue(); + const int modelsCount = this->modelLoader()->getCachedModelsCount(sim); if (modelsCount < 1) { static const CStatusMessage msg = CStatusMessage(this).validationError("No models indexed so far. Try 'reload'!"); @@ -237,14 +238,13 @@ namespace BlackGui return; } } - CAircraftModelList modelsForSet = this->modelLoader()->getAircraftModels(); + CAircraftModelList modelsForSet = this->modelLoader()->getCachedModels(sim); if (!useAllModels) { const CDistributorList distributors = ui->comp_Distributors->getSelectedDistributors(); modelsForSet = modelsForSet.findByDistributors(distributors); } - const CSimulatorInfo sim = ui->comp_SimulatorSelector->getValue(); m_modelSetDialog->modelSetComponent()->setModelSet(modelsForSet, sim); ui->pb_ModelSet->click(); }