From c4a61c275d5ec70d051eea5b4da202b131e1cf08 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 2 Oct 2016 23:26:13 +0200 Subject: [PATCH] refs #743, bottom bar to switch simulator for own models (like for model set, not only by context menu but also by radio buttons) --- .../components/dbownmodelscomponent.cpp | 47 ++++++++++-- .../components/dbownmodelscomponent.h | 14 +++- .../components/dbownmodelscomponent.ui | 73 +++++++++++++++++++ 3 files changed, 125 insertions(+), 9 deletions(-) diff --git a/src/blackgui/components/dbownmodelscomponent.cpp b/src/blackgui/components/dbownmodelscomponent.cpp index febe36207..4f4032493 100644 --- a/src/blackgui/components/dbownmodelscomponent.cpp +++ b/src/blackgui/components/dbownmodelscomponent.cpp @@ -10,6 +10,7 @@ #include "blackcore/webdataservices.h" #include "blackcore/db/databaseutils.h" #include "blackgui/components/dbownmodelscomponent.h" +#include "blackgui/components/simulatorselector.h" #include "blackgui/guiapplication.h" #include "blackgui/menus/aircraftmodelmenus.h" #include "blackgui/menus/menuaction.h" @@ -41,6 +42,7 @@ namespace BlackGui ui(new Ui::CDbOwnModelsComponent) { ui->setupUi(this); + ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons); ui->tvp_OwnAircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping); ui->tvp_OwnAircraftModels->addFilterDialog(); ui->tvp_OwnAircraftModels->setDisplayAutomatically(true); @@ -51,8 +53,8 @@ namespace BlackGui // should be single simulator or no simulator (default) this->m_simulatorSelection.synchronize(); const CSimulatorInfo simulator(this->m_simulatorSelection.get()); - const bool s = this->initModelLoader(!simulator.isSingleSimulator() ? CSimulatorInfo(CSimulatorInfo::FSX) : simulator); - if (s) + const bool succes = this->initModelLoader(!simulator.isSingleSimulator() ? CSimulatorInfo(CSimulatorInfo::FSX) : simulator); + if (succes) { this->m_modelLoader->startLoading(IAircraftModelLoader::CacheOnly); } @@ -61,6 +63,10 @@ namespace BlackGui CLogMessage(this).error("Init of model loader failed in component"); } + ui->comp_SimulatorSelector->setValue(simulator); + ui->le_Simulator->setText(simulator.toQString()); + connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDbOwnModelsComponent::ps_requestSimulatorModelsWithCacheInBackground); + // menu ui->tvp_OwnAircraftModels->setCustomMenu(new CConsolidateWithDbDataMenu(ui->tvp_OwnAircraftModels, this, false)); } @@ -98,6 +104,13 @@ namespace BlackGui return this->m_modelLoader->getAircraftModels(); } + CAircraftModelList CDbOwnModelsComponent::getOwnCachedModels(const CSimulatorInfo &simulator) const + { + static const CAircraftModelList empty; + if (!this->m_modelLoader) { return empty; } + return this->m_modelLoader->getCachedAircraftModels(simulator); + } + CAircraftModelList CDbOwnModelsComponent::getOwnSelectedModels() const { return ui->tvp_OwnAircraftModels->selectedObjects(); @@ -122,6 +135,18 @@ namespace BlackGui return this->m_modelLoader->getAircraftModelsCount(); } + QString CDbOwnModelsComponent::getInfoString() const + { + if (!this->m_modelLoader) { return ""; } + return this->m_modelLoader->getInfoString(); + } + + QString CDbOwnModelsComponent::getInfoStringFsFamily() const + { + if (!this->m_modelLoader) { return ""; } + return this->m_modelLoader->getInfoStringFsFamily(); + } + CStatusMessage CDbOwnModelsComponent::updateViewAndCache(const CAircraftModelList &models) { const CStatusMessage m = this->m_modelLoader->setCachedModels(models, this->getOwnModelsSimulator()); @@ -196,8 +221,7 @@ namespace BlackGui QString CDbOwnModelsComponent::directorySelector(const CSimulatorInfo &simulatorInfo) { const QString text("Open directory (%1)"); - const QString dir = QFileDialog::getExistingDirectory(nullptr, text.arg(simulatorInfo.toQString()), - "", + const QString dir = QFileDialog::getExistingDirectory(nullptr, text.arg(simulatorInfo.toQString()), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); return dir; } @@ -222,7 +246,7 @@ namespace BlackGui connect(this->m_loadActions[0], &QAction::triggered, ownModelsComp, [ownModelsComp](bool checked) { Q_UNUSED(checked); - ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FSX), IAircraftModelLoader::InBackgroundWithCache); + ownModelsComp->ps_requestSimulatorModelsWithCacheInBackground(CSimulatorInfo(CSimulatorInfo::FSX)); }); } menuActions.addAction(this->m_loadActions[0], CMenuAction::pathSimulator()); @@ -235,7 +259,7 @@ namespace BlackGui connect(this->m_loadActions[1], &QAction::triggered, ownModelsComp, [ownModelsComp](bool checked) { Q_UNUSED(checked); - ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::P3D), IAircraftModelLoader::InBackgroundWithCache); + ownModelsComp->ps_requestSimulatorModelsWithCacheInBackground(CSimulatorInfo(CSimulatorInfo::P3D)); }); } menuActions.addAction(this->m_loadActions[1], CMenuAction::pathSimulator()); @@ -248,7 +272,7 @@ namespace BlackGui connect(this->m_loadActions[2], &QAction::triggered, ownModelsComp, [ownModelsComp](bool checked) { Q_UNUSED(checked); - ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FS9), IAircraftModelLoader::InBackgroundWithCache); + ownModelsComp->ps_requestSimulatorModelsWithCacheInBackground(CSimulatorInfo(CSimulatorInfo::FS9)); }); } menuActions.addAction(this->m_loadActions[2], CMenuAction::pathSimulator()); @@ -261,7 +285,7 @@ namespace BlackGui connect(this->m_loadActions[3], &QAction::triggered, ownModelsComp, [ownModelsComp](bool checked) { Q_UNUSED(checked); - ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::XPLANE), IAircraftModelLoader::InBackgroundWithCache); + ownModelsComp->ps_requestSimulatorModelsWithCacheInBackground(CSimulatorInfo(CSimulatorInfo::XPLANE)); }); } menuActions.addAction(this->m_loadActions[3], CMenuAction::pathSimulator()); @@ -435,11 +459,18 @@ namespace BlackGui CLogMessage(this).error("Loading of models failed, simulator %1") << simulator.toQString(); } ui->tvp_OwnAircraftModels->hideLoadIndicator(); + ui->le_Simulator->setText(simulator.toQString()); + ui->comp_SimulatorSelector->setValue(simulator); } void CDbOwnModelsComponent::ps_requestSimulatorModels(const CSimulatorInfo &simulator, IAircraftModelLoader::LoadMode mode, const QString &directory) { this->ps_loadInstalledModels(simulator, mode, directory); } + + void CDbOwnModelsComponent::ps_requestSimulatorModelsWithCacheInBackground(const CSimulatorInfo &simulator) + { + this->ps_requestSimulatorModels(simulator, IAircraftModelLoader::InBackgroundWithCache); + } } // ns } // ns diff --git a/src/blackgui/components/dbownmodelscomponent.h b/src/blackgui/components/dbownmodelscomponent.h index b2752f59b..b2c2c455d 100644 --- a/src/blackgui/components/dbownmodelscomponent.h +++ b/src/blackgui/components/dbownmodelscomponent.h @@ -70,6 +70,9 @@ namespace BlackGui //! Own models BlackMisc::Simulation::CAircraftModelList getOwnModels() const; + //! Own cached models from loader + BlackMisc::Simulation::CAircraftModelList getOwnCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const; + //! Own models selected in view BlackMisc::Simulation::CAircraftModelList getOwnSelectedModels() const; @@ -82,6 +85,12 @@ namespace BlackGui //! Number of own models int getOwnModelsCount() const; + //! \copydoc BlackMisc::Simulation::Data::CModelCaches::getInfoString + QString getInfoString() const; + + //! \copydoc BlackMisc::Simulation::Data::CModelCaches::getInfoStringFsFamily + QString getInfoStringFsFamily() const; + //! Update view and cache BlackMisc::CStatusMessage updateViewAndCache(const BlackMisc::Simulation::CAircraftModelList &models); @@ -118,6 +127,9 @@ namespace BlackGui //! Request simulator models void ps_requestSimulatorModels(const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode, const QString &directory = ""); + //! Request simulator models from cache + void ps_requestSimulatorModelsWithCacheInBackground(const BlackMisc::Simulation::CSimulatorInfo &simulator); + private: QScopedPointer ui; std::unique_ptr m_modelLoader; //!< read own aircraft models @@ -129,7 +141,7 @@ namespace BlackGui //! File name for savinf void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &sim); - //! Directory selector + //! Directory selector for given simulator static QString directorySelector(const BlackMisc::Simulation::CSimulatorInfo &simulatorInfo); //! The menu for loading and handling own models for mapping tasks diff --git a/src/blackgui/components/dbownmodelscomponent.ui b/src/blackgui/components/dbownmodelscomponent.ui index 2144acd08..7919c2325 100644 --- a/src/blackgui/components/dbownmodelscomponent.ui +++ b/src/blackgui/components/dbownmodelscomponent.ui @@ -45,6 +45,73 @@ + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 200 + 0 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Simulator: + + + + + + + + 100 + 16777215 + + + + Simulator + + + + + + @@ -53,6 +120,12 @@ QTableView
blackgui/views/aircraftmodelview.h
+ + BlackGui::Components::CSimulatorSelector + QFrame +
blackgui/components/simulatorselector.h
+ 1 +