diff --git a/src/blackgui/blackgui.pro b/src/blackgui/blackgui.pro index c5c367b3e..cdbf9ce5c 100644 --- a/src/blackgui/blackgui.pro +++ b/src/blackgui/blackgui.pro @@ -24,6 +24,8 @@ HEADERS += *.h SOURCES += *.cpp HEADERS += $$PWD/models/*.h SOURCES += $$PWD/models/*.cpp +HEADERS += $$PWD/menus/*.h +SOURCES += $$PWD/menus/*.cpp HEADERS += $$PWD/views/*.h SOURCES += $$PWD/views/*.cpp diff --git a/src/blackgui/components/data/lastselections.cpp b/src/blackgui/components/data/lastselections.cpp index c67d6bf8b..026ce40bc 100644 --- a/src/blackgui/components/data/lastselections.cpp +++ b/src/blackgui/components/data/lastselections.cpp @@ -17,13 +17,13 @@ namespace BlackGui { namespace Data { - QString CDbMappingComponent::convertToQString(bool i18n) const + QString CDbOwnModelsComponent::convertToQString(bool i18n) const { QString s(this->m_simulator.toQString(i18n)); return s; } - CVariant CDbMappingComponent::propertyByIndex(const BlackMisc::CPropertyIndex &index) const + CVariant CDbOwnModelsComponent::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } ColumnIndex i = index.frontCasted(); @@ -36,9 +36,9 @@ namespace BlackGui } } - void CDbMappingComponent::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) + void CDbOwnModelsComponent::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index) { - if (index.isMyself()) { (*this) = variant.to(); return; } + if (index.isMyself()) { (*this) = variant.to(); return; } ColumnIndex i = index.frontCasted(); switch (i) { @@ -51,7 +51,7 @@ namespace BlackGui } } - int CDbMappingComponent::comparePropertyByIndex(const CDbMappingComponent &compareValue, const CPropertyIndex &index) const + int CDbOwnModelsComponent::comparePropertyByIndex(const CDbOwnModelsComponent &compareValue, const CPropertyIndex &index) const { if (index.isMyself()) { return this->toQString().compare(compareValue.toQString()); } ColumnIndex i = index.frontCasted(); diff --git a/src/blackgui/components/data/lastselections.h b/src/blackgui/components/data/lastselections.h index b0b3e80cb..1d3ac0bdf 100644 --- a/src/blackgui/components/data/lastselections.h +++ b/src/blackgui/components/data/lastselections.h @@ -26,7 +26,7 @@ namespace BlackGui /*! * Store last selections/interactions with this component */ - class BLACKGUI_EXPORT CDbMappingComponent : public BlackMisc::CValueObject + class BLACKGUI_EXPORT CDbOwnModelsComponent : public BlackMisc::CValueObject { public: //! Properties by index @@ -51,32 +51,32 @@ namespace BlackGui void setPropertyByIndex(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index); //! Compare by index - int comparePropertyByIndex(const CDbMappingComponent &compareValue, const BlackMisc::CPropertyIndex &index) const; + int comparePropertyByIndex(const CDbOwnModelsComponent &compareValue, const BlackMisc::CPropertyIndex &index) const; private: - BLACK_ENABLE_TUPLE_CONVERSION(CDbMappingComponent) + BLACK_ENABLE_TUPLE_CONVERSION(CDbOwnModelsComponent) BlackMisc::Simulation::CSimulatorInfo m_simulator; //!< Last simulator selection }; //! Trait for model cache - struct DbMappingComponent : public BlackMisc::CDataTrait + struct DbOwnModelsComponent : public BlackMisc::CDataTrait { //! Default value - static const CDbMappingComponent &defaultValue() + static const CDbOwnModelsComponent &defaultValue() { - static const CDbMappingComponent ls; + static const CDbOwnModelsComponent ls; return ls; } //! Key in data cache - static const char *key() { return "dbmappingcomponent"; } + static const char *key() { return "dbownmodelscomponent"; } }; } // ns } // ns } // ns -Q_DECLARE_METATYPE(BlackGui::Components::Data::CDbMappingComponent) -BLACK_DECLARE_TUPLE_CONVERSION(BlackGui::Components::Data::CDbMappingComponent, ( +Q_DECLARE_METATYPE(BlackGui::Components::Data::CDbOwnModelsComponent) +BLACK_DECLARE_TUPLE_CONVERSION(BlackGui::Components::Data::CDbOwnModelsComponent, ( attr(o.m_simulator) )) diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index 5d2c0e632..17d1f0a5a 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -18,7 +18,6 @@ #include "blackmisc/logmessage.h" #include #include -#include using namespace BlackCore; using namespace BlackMisc; @@ -47,41 +46,27 @@ namespace BlackGui this->ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel); this->ui->tvp_AircraftModelsForVPilot->addFilterDialog(); - this->ui->tvp_OwnAircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping); - this->ui->tvp_OwnAircraftModels->addFilterDialog(); + + // own models + ui->comp_OwnAircraftModels->view()->setCustomMenu(new CModelStashTools(this, false)); // connects connect(ui->editor_Model, &CModelMappingForm::requestStash, this, &CDbMappingComponent::ps_stashCurrentModel); - connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); - connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onOwnModelsCountChanged); - connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels); - connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged); - connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::requestUpdate, this, &CDbMappingComponent::ps_requestOwnModelsUpdate); + connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); + connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onOwnModelsCountChanged); + connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels); + connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged); - connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onStashCountChanged); - connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); - connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::requestHandlingOfStashDrop, this, &CDbMappingComponent::ps_handleStashDropRequest); + connect(ui->comp_StashAircraft->view(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onStashCountChanged); + connect(ui->comp_StashAircraft->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); + connect(ui->comp_StashAircraft->view(), &CAircraftModelView::requestHandlingOfStashDrop, this, &CDbMappingComponent::ps_handleStashDropRequest); connect(ui->comp_StashAircraft, &CDbStashComponent::stashedModelsChanged, this, &CDbMappingComponent::ps_onStashedModelsChanged); connect(ui->comp_StashAircraft, &CDbStashComponent::modelsSuccessfullyPublished, this, &CDbMappingComponent::ps_onModelsSuccessfullyPublished); - connect(ui->comp_OwnModelSet->getView(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onModelSetCountChanged); + connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onModelSetCountChanged); connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, this, &CDbMappingComponent::tabIndexChanged); - ui->tvp_OwnAircraftModels->setDisplayAutomatically(true); - ui->tvp_OwnAircraftModels->setCustomMenu(new CShowSimulatorFile(this), false); - ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingOwnSimulatorModelMenu(this)); - ui->tvp_OwnAircraftModels->setCustomMenu(new CModelStashTools(this, false)); - - this->m_lastInteractions.synchronize(); - const CSimulatorInfo sim = this->m_lastInteractions.get().getLastSimulatorSelection(); - if (sim.isSingleSimulator()) - { - // if we have already use this before, use it again, but only from cache - this->initModelLoader(sim); - this->m_modelLoader->startLoading(IAircraftModelLoader::CacheOnly); - } - // how to display forms ui->editor_AircraftIcao->setSelectOnly(); ui->editor_Distributor->setSelectOnly(); @@ -89,7 +74,7 @@ namespace BlackGui this->ui->tw_ModelsToBeMapped->setTabIcon(TabStash, CIcons::appDbStash16()); this->ui->tw_ModelsToBeMapped->setTabIcon(TabOwnModels, CIcons::appModels16()); - this->ui->comp_StashAircraft->getView()->setCustomMenu(new CApplyDbDataMenu(this)); + this->ui->comp_StashAircraft->view()->setCustomMenu(new CApplyDbDataMenu(this)); // vPilot this->initVPilotLoading(); @@ -141,34 +126,6 @@ namespace BlackGui } } - bool CDbMappingComponent::initModelLoader(const CSimulatorInfo &simInfo) - { - // already loaded - Q_ASSERT_X(simInfo.isSingleSimulator(), Q_FUNC_INFO, "need single simulator"); - if (this->m_modelLoader && this->m_modelLoader->supportsSimulator(simInfo)) - { - return true; - } - - // unload old - if (this->m_modelLoader) { this->m_modelLoader->cancelLoading(); } - - this->m_modelLoader = IAircraftModelLoader::createModelLoader(simInfo); - if (!this->m_modelLoader || !this->m_modelLoader->supportsSimulator(simInfo)) - { - CLogMessage(this).error("Failed to init model loader %1") << simInfo.toQString(); - this->m_modelLoader.reset(); - return false; - } - else - { - bool c = connect(this->m_modelLoader.get(), &IAircraftModelLoader::loadingFinished, this, &CDbMappingComponent::ps_onOwnModelsLoadingFinished); - Q_ASSERT_X(c, Q_FUNC_INFO, "Failed connect for model loader"); - Q_UNUSED(c); - return true; - } - } - CAircraftModel CDbMappingComponent::getModelFromView(const QModelIndex &index) const { if (!index.isValid()) { return CAircraftModel(); } @@ -177,13 +134,13 @@ namespace BlackGui { return this->ui->tvp_AircraftModelsForVPilot->at(index); } - else if (sender == this->ui->tvp_OwnAircraftModels) + else if (sender == this->ui->comp_OwnAircraftModels->view()) { - return this->ui->tvp_OwnAircraftModels->at(index); + return this->ui->comp_OwnAircraftModels->view()->at(index); } - else if (sender == this->ui->comp_StashAircraft || sender == this->ui->comp_StashAircraft->getView()) + else if (sender == this->ui->comp_StashAircraft || sender == this->ui->comp_StashAircraft->view()) { - return this->ui->comp_StashAircraft->getView()->at(index); + return this->ui->comp_StashAircraft->view()->at(index); } // no sender, use current tab @@ -196,7 +153,7 @@ namespace BlackGui { this->disconnect(); this->m_vPilotReader.gracefulShutdown(); - if (this->m_modelLoader) { this->m_modelLoader->gracefulShutdown(); } + ui->comp_OwnAircraftModels->gracefulShutdown(); } bool CDbMappingComponent::hasSelectedModelsToStash() const @@ -205,7 +162,7 @@ namespace BlackGui switch (tab) { case TabOwnModels: - return ui->tvp_OwnAircraftModels->hasSelectedModelsToStash(); + return ui->comp_OwnAircraftModels->view()->hasSelectedModelsToStash(); case TabVPilot: return ui->tvp_AircraftModelsForVPilot->hasSelectedModelsToStash(); default: @@ -220,13 +177,13 @@ namespace BlackGui switch (tab) { case TabOwnModels: - return ui->tvp_OwnAircraftModels; + return ui->comp_OwnAircraftModels->view(); case TabVPilot: return ui->tvp_AircraftModelsForVPilot; case TabStash: - return ui->comp_StashAircraft->getView(); + return ui->comp_StashAircraft->view(); case TabOwnModelSet: - return ui->comp_OwnModelSet->getView(); + return ui->comp_OwnModelSet->view(); default: return nullptr; } @@ -245,7 +202,7 @@ namespace BlackGui switch (tab) { case TabOwnModels: - return ui->tvp_OwnAircraftModels->selectedObjects(); + return ui->comp_OwnAircraftModels->view()->selectedObjects(); case TabVPilot: return ui->tvp_AircraftModelsForVPilot->selectedObjects(); default: @@ -264,32 +221,6 @@ namespace BlackGui return ui->comp_StashAircraft->getStashedModelStrings(); } - CAircraftModel CDbMappingComponent::getOwnModelForModelString(const QString &modelString) const - { - if (!this->m_modelLoader) { return CAircraftModel(); } - return this->m_modelLoader->getAircraftModels().findFirstByModelString(modelString); - } - - CAircraftModelList CDbMappingComponent::getOwnModels() const - { - static const CAircraftModelList empty; - if (!this->m_modelLoader) { return empty; } - return this->m_modelLoader->getAircraftModels(); - } - - const CSimulatorInfo &CDbMappingComponent::getOwnModelsSimulator() const - { - static const CSimulatorInfo noSim; - if (!this->m_modelLoader) { return noSim; } - return this->m_modelLoader->getSimulator(); - } - - int CDbMappingComponent::getOwnModelsCount() const - { - if (!this->m_modelLoader) { return 0; } - return this->m_modelLoader->getAircraftModelsCount(); - } - CDbMappingComponent::TabIndex CDbMappingComponent::currentTabIndex() const { if (!ui->tw_ModelsToBeMapped) { return CDbMappingComponent::NoValidTab; } @@ -363,7 +294,7 @@ namespace BlackGui if (!sender) { return; } QString cn(sender->data().toString()); if (cn.isEmpty()) { return; } - if (this->ui->comp_StashAircraft->getView()->selectedRowCount() < 1) { return; } + if (this->ui->comp_StashAircraft->view()->selectedRowCount() < 1) { return; } CStatusMessageList msgs; if (CLivery().getClassName() == cn) @@ -409,9 +340,9 @@ namespace BlackGui void CDbMappingComponent::ps_modifyModelDialog() { // only one model selected, use as default - if (this->ui->comp_StashAircraft->getView()->hasSingleSelectedRow()) + if (this->ui->comp_StashAircraft->view()->hasSingleSelectedRow()) { - this->m_modelModifyDialog->setValue(this->ui->comp_StashAircraft->getView()->selectedObject()); + this->m_modelModifyDialog->setValue(this->ui->comp_StashAircraft->view()->selectedObject()); } QDialog::DialogCode s = static_cast(this->m_modelModifyDialog->exec()); @@ -420,26 +351,6 @@ namespace BlackGui this->ui->comp_StashAircraft->applyToSelected(vm); } - void CDbMappingComponent::ps_showSimulatorFile() - { - if (!this->currentModelView()->hasSelection()) { return; } - const CAircraftModelList models(this->currentModelView()->selectedObjects().findWithFileName()); - if (models.isEmpty()) { return; } - int trails = 0; - - for (const CAircraftModel &model : models) - { - trails++; - if (QFile::exists(model.getFileName())) - { - const QString url("file:///" + model.getFileName()); - QDesktopServices::openUrl(QUrl(url)); - break; - } - if (trails > 10) { break; } - } - } - void CDbMappingComponent::resizeForSelect() { this->maxTableView(); @@ -515,7 +426,7 @@ namespace BlackGui { CLogMessage(this).error("Loading vPilot ruleset failed"); } - this->ui->tvp_OwnAircraftModels->hideLoadIndicator(); + this->ui->comp_OwnAircraftModels->view()->hideLoadIndicator(); } void CDbMappingComponent::ps_onVPilotCacheChanged() @@ -531,18 +442,10 @@ namespace BlackGui this->ps_onVPilotCacheChanged(); } - void CDbMappingComponent::ps_requestOwnModelsUpdate() - { - if (!this->m_modelLoader) { return; } - this->ui->tvp_OwnAircraftModels->updateContainerMaybeAsync( - this->m_modelLoader->getAircraftModels() - ); - } - void CDbMappingComponent::ps_onStashedModelsChanged() { const bool hlvp = this->ui->tvp_AircraftModelsForVPilot->derivedModel()->highlightModelStrings(); - const bool hlom = this->ui->tvp_OwnAircraftModels->derivedModel()->highlightModelStrings(); + const bool hlom = this->ui->comp_OwnAircraftModels->view()->derivedModel()->highlightModelStrings(); const bool highlight = hlom || hlvp; if (!highlight) { return; } const QStringList stashedModels(this->ui->comp_StashAircraft->getStashedModelStrings()); @@ -552,7 +455,7 @@ namespace BlackGui } if (hlom) { - this->ui->tvp_OwnAircraftModels->derivedModel()->setHighlightModelStrings(stashedModels); + this->ui->comp_OwnAircraftModels->view()->derivedModel()->setHighlightModelStrings(stashedModels); } } @@ -580,13 +483,10 @@ namespace BlackGui const int i = this->ui->tw_ModelsToBeMapped->indexOf(this->ui->tab_OwnModels); static const QString ot(this->ui->tw_ModelsToBeMapped->tabText(i)); QString o(ot); - if (this->m_modelLoader) - { - QString sims(this->m_modelLoader->getSimulatorAsString()); - if (!sims.isEmpty()) { o = o.append(" ").append(sims); } - } - QString f = this->ui->tvp_OwnAircraftModels->hasFilter() ? "F" : ""; - o = CGuiUtility::replaceTabCountValue(o, this->ui->tvp_OwnAircraftModels->rowCount()) + f; + const QString sim(ui->comp_OwnAircraftModels->getOwnModelsSimulator().toQString(true)); + if (!sim.isEmpty()) { o = o.append(" ").append(sim); } + QString f = this->ui->comp_OwnAircraftModels->view()->hasFilter() ? "F" : ""; + o = CGuiUtility::replaceTabCountValue(o, this->ui->comp_OwnAircraftModels->view()->rowCount()) + f; this->ui->tw_ModelsToBeMapped->setTabText(i, o); } @@ -596,8 +496,8 @@ namespace BlackGui Q_UNUSED(withFilter); int i = this->ui->tw_ModelsToBeMapped->indexOf(this->ui->tab_StashAircraftModels); QString o = this->ui->tw_ModelsToBeMapped->tabText(i); - QString f = this->ui->comp_StashAircraft->getView()->hasFilter() ? "F" : ""; - o = CGuiUtility::replaceTabCountValue(o, this->ui->comp_StashAircraft->getView()->rowCount()) + f; + const QString f = this->ui->comp_StashAircraft->view()->hasFilter() ? "F" : ""; + o = CGuiUtility::replaceTabCountValue(o, this->ui->comp_StashAircraft->view()->rowCount()) + f; this->ui->tw_ModelsToBeMapped->setTabText(i, o); } @@ -606,17 +506,12 @@ namespace BlackGui Q_UNUSED(count); Q_UNUSED(withFilter); int i = this->ui->tw_ModelsToBeMapped->indexOf(this->ui->tab_OwnModelSet); - QString o = this->ui->tw_ModelsToBeMapped->tabText(i); - QString f = this->ui->comp_StashAircraft->getView()->hasFilter() ? "F" : ""; - o = CGuiUtility::replaceTabCountValue(o, this->ui->comp_OwnModelSet->getView()->rowCount()) + f; + QString o = "Model set " + ui->comp_OwnModelSet->getModelSetSimulator().toQString(true); + const QString f = this->ui->comp_StashAircraft->view()->hasFilter() ? "F" : ""; + o = CGuiUtility::replaceTabCountValue(o, this->ui->comp_OwnModelSet->view()->rowCount()) + f; this->ui->tw_ModelsToBeMapped->setTabText(i, o); } - void CDbMappingComponent::ps_requestSimulatorModels(const CSimulatorInfo &simInfo, IAircraftModelLoader::LoadMode mode) - { - this->ps_loadInstalledModels(simInfo, mode); - } - void CDbMappingComponent::ps_userChanged() { this->initVPilotLoading(); @@ -684,58 +579,6 @@ namespace BlackGui } } - void CDbMappingComponent::ps_loadInstalledModels(const CSimulatorInfo &simInfo, IAircraftModelLoader::LoadMode mode) - { - if (!this->initModelLoader(simInfo)) - { - CLogMessage(this).error("Cannot load model loader for %1") << simInfo.toQString(); - return; - } - - if (!this->m_modelLoader->isLoadingFinished()) - { - CLogMessage(this).info("Loading for %1 already in progress") << simInfo.toQString(); - return; - } - - CLogMessage(this).info("Starting loading for %1") << simInfo.toQString(); - this->ui->tvp_OwnAircraftModels->showLoadIndicator(); - Q_ASSERT_X(sGui && sGui->getWebDataServices(), Q_FUNC_INFO, "missing web data services"); - this->m_modelLoader->startLoading(mode, sGui->getWebDataServices()->getModels()); - } - - void CDbMappingComponent::ps_onOwnModelsLoadingFinished(bool success, const CSimulatorInfo &simInfo) - { - Q_ASSERT_X(simInfo.isSingleSimulator(), Q_FUNC_INFO, "Expect single simulator"); - if (success && this->m_modelLoader) - { - const CAircraftModelList models(this->m_modelLoader->getAircraftModels()); - const int modelsLoaded = models.size(); - this->ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(models); - if (modelsLoaded > 0) - { - // store for later - Data::CDbMappingComponent mc(this->m_lastInteractions.get()); - if (simInfo.isSingleSimulator() && mc.getLastSimulatorSelection() != simInfo) - { - mc.setLastSimulatorSelection(simInfo); - this->m_lastInteractions.set(mc); - } - } - else - { - // loading ok, but no data - CLogMessage(this).warning("Loading completed, but no models"); - } - } - else - { - this->ui->tvp_OwnAircraftModels->hideLoadIndicator(); - CLogMessage(this).error("Loading of models failed, simulator %1") << simInfo.toQString(); - } - this->ui->tvp_OwnAircraftModels->hideLoadIndicator(); - } - CAircraftModel CDbMappingComponent::getEditorAircraftModel() const { CAircraftModel model(ui->editor_Model->getValue()); @@ -745,6 +588,26 @@ namespace BlackGui return model; } + CAircraftModelList CDbMappingComponent::getOwnModels() const + { + return this->ui->comp_OwnAircraftModels->getOwnModels(); + } + + CAircraftModel CDbMappingComponent::getOwnModelForModelString(const QString &modelString) const + { + return this->ui->comp_OwnAircraftModels->getOwnModelForModelString(modelString); + } + + const CSimulatorInfo &CDbMappingComponent::getOwnModelsSimulator() const + { + return this->ui->comp_OwnAircraftModels->getOwnModelsSimulator(); + } + + int CDbMappingComponent::getOwnModelsCount() const + { + return this->ui->comp_OwnAircraftModels->getOwnModelsCount(); + } + CStatusMessage CDbMappingComponent::stashModel(const CAircraftModel &model, bool replace) { return this->ui->comp_StashAircraft->stashModel(model, replace); @@ -765,82 +628,6 @@ namespace BlackGui this->ui->comp_StashAircraft->replaceModelsUnvalidated(models); } - void CDbMappingComponent::CMappingOwnSimulatorModelMenu::customMenu(QMenu &menu) const - { - CSimulatorInfo sims = CSimulatorInfo::getLocallyInstalledSimulators(); - bool noSims = sims.isNoSimulator() || sims.isUnspecified(); - if (!noSims) - { - this->addSeparator(menu); - QMenu *load = menu.addMenu(CIcons::appModels16(), "Load installed models"); - CDbMappingComponent *mapComp = qobject_cast(this->parent()); - Q_ASSERT_X(mapComp, Q_FUNC_INFO, "Cannot access parent"); - if (sims.fsx()) - { - load->addAction(CIcons::appModels16(), "FSX models", mapComp, [mapComp]() - { - mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FSX), IAircraftModelLoader::InBackgroundWithCache); - }); - } - if (sims.p3d()) - { - load->addAction(CIcons::appModels16(), "P3D models", mapComp, [mapComp]() - { - mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::P3D), IAircraftModelLoader::InBackgroundWithCache); - }); - } - if (sims.fs9()) - { - load->addAction(CIcons::appModels16(), "FS9 models", mapComp, [mapComp]() - { - mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FS9), IAircraftModelLoader::InBackgroundWithCache); - }); - } - if (sims.xplane()) - { - load->addAction(CIcons::appModels16(), "XP models", mapComp, [mapComp]() - { - mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::XPLANE), IAircraftModelLoader::InBackgroundWithCache); - }); - } - - // with models loaded I allow a refresh reload - if (sGui->getWebDataServices() && sGui->getWebDataServices()->getModelsCount() > 0) - { - QMenu *reloadMenu = load->addMenu("Force reload"); - if (sims.fsx()) - { - reloadMenu->addAction(CIcons::appModels16(), "FSX models", mapComp, [mapComp]() - { - mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FSX), IAircraftModelLoader::InBackgroundNoCache); - }); - } - if (sims.p3d()) - { - reloadMenu->addAction(CIcons::appModels16(), "P3D models", mapComp, [mapComp]() - { - mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::P3D), IAircraftModelLoader::InBackgroundNoCache); - }); - } - if (sims.fs9()) - { - reloadMenu->addAction(CIcons::appModels16(), "FS9 models", mapComp, [mapComp]() - { - mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FS9), IAircraftModelLoader::InBackgroundNoCache); - }); - } - if (sims.xplane()) - { - reloadMenu->addAction(CIcons::appModels16(), "XP models", mapComp, [mapComp]() - { - mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::XPLANE), IAircraftModelLoader::InBackgroundNoCache); - }); - } - } - } - this->nestedCustomMenu(menu); - } - void CDbMappingComponent::CMappingVPilotMenu::customMenu(QMenu &menu) const { CDbMappingComponent *mapComp = qobject_cast(this->parent()); @@ -873,22 +660,22 @@ namespace BlackGui int dbModels = sGui->getWebDataServices()->getModelsCount(); if (dbModels > 0) { - // we have keys and data where we could delete them from + // we have keys and data where we could delete them from view const QString msgDelete("Delete " + QString::number(dbModels) + " DB model(s) from " + mapComp->currentTabText()); - menu.addAction(CIcons::delete16(), msgDelete, mapComp, SLOT(ps_removeDbModelsFromView())); + menu.addAction(CIcons::delete16(), msgDelete, mapComp, &CDbMappingComponent::ps_removeDbModelsFromView); } // we have keys and data where we could delete them from const QString msgAutoStash("Auto stashing"); - menu.addAction(CIcons::appDbStash16(), msgAutoStash, mapComp, SLOT(ps_displayAutoStashingDialog())); + menu.addAction(CIcons::appDbStash16(), msgAutoStash, mapComp, &CDbMappingComponent::ps_displayAutoStashingDialog); if (mapComp->m_autoStashDialog && mapComp->m_autoStashDialog->isCompleted()) { - menu.addAction(CIcons::appDbStash16(), "Last auto stash run", mapComp->m_autoStashDialog.data(), SLOT(showLastResults())); + menu.addAction(CIcons::appDbStash16(), "Last auto stash run", mapComp->m_autoStashDialog.data(), &CDbAutoStashingComponent::showLastResults); } // auto filter in DB views - QAction *a = menu.addAction(CIcons::filter16(), "Auto filtering in DB views (on/off)", mapComp, SLOT(ps_toggleAutoFiltering())); + QAction *a = menu.addAction(CIcons::filter16(), "Auto filtering in DB views (on/off)", mapComp, &CDbMappingComponent::ps_toggleAutoFiltering); a->setCheckable(true); a->setChecked(mapComp->m_autoFilterInDbViews); } @@ -914,16 +701,20 @@ namespace BlackGui QMenu *subMenu = menu.addMenu(CIcons::database16(), "Apply DB data (to selected)"); QAction *a = nullptr; - a = subMenu->addAction(CIcons::appAircraftIcao16(), "Current aircraft ICAO", mapComp, SLOT(ps_applyDbData())); + a = subMenu->addAction(CIcons::appAircraftIcao16(), "Current aircraft ICAO", mapComp, &CDbMappingComponent::ps_applyDbData); a->setData(CAircraftIcaoCode().getClassName()); - a = subMenu->addAction(CIcons::appDistributors16(), "Current distributor", mapComp, SLOT(ps_applyDbData())); + a = subMenu->addAction(CIcons::appDistributors16(), "Current distributor", mapComp, &CDbMappingComponent::ps_applyDbData); a->setData(CDistributor().getClassName()); - a = subMenu->addAction(CIcons::appLiveries16(), "Current livery", mapComp, SLOT(ps_applyDbData())); + a = subMenu->addAction(CIcons::appLiveries16(), "Current livery", mapComp, &CDbMappingComponent::ps_applyDbData); a->setData(CLivery().getClassName()); - menu.addAction(CIcons::databaseTable16(), "Modify model data", mapComp, SLOT(ps_modifyModelDialog())); + // a = subMenu->addAction(CIcons::appAirlineIcao16(), "Current airline ICAO", mapComp, &CDbMappingComponent::ps_applyDbData); + // a->setData(CAirlineIcaoCode().getClassName()); + + menu.addAction(CIcons::databaseTable16(), "Modify model data", mapComp, &CDbMappingComponent::ps_applyDbData); + a->setData(CAircraftModel().getClassName()); } this->nestedCustomMenu(menu); } @@ -932,25 +723,5 @@ namespace BlackGui { return qobject_cast(this->parent()); } - - void CDbMappingComponent::CShowSimulatorFile::customMenu(QMenu &menu) const - { - CDbMappingComponent *mapComp = mappingComponent(); - Q_ASSERT_X(mapComp, Q_FUNC_INFO, "no mapping component"); - - if (mapComp->currentTabIndex() == CDbMappingComponent::TabOwnModels && mapComp->currentModelView()->hasSelection()) - { - this->addSeparator(menu); - menu.addAction(CIcons::text16(), "Open simulator file", mapComp, SLOT(ps_showSimulatorFile())); - } - - this->nestedCustomMenu(menu); - } - - CDbMappingComponent *CDbMappingComponent::CShowSimulatorFile::mappingComponent() const - { - return qobject_cast(this->parent()); - } - } // ns } // ns diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index 279cbe31b..f2b3b642a 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -15,7 +15,7 @@ #include "blackcore/data/authenticateduser.h" #include "blackgui/blackguiexport.h" #include "blackgui/overlaymessagesframe.h" -#include "blackgui/menudelegate.h" +#include "blackgui/menus/menudelegate.h" #include "blackgui/enableforviewbasedindicator.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/data/lastselections.h" @@ -83,18 +83,6 @@ namespace BlackGui //! Stashed model strings QStringList getStashedModelStrings() const; - //! Own (installed) model for given model string - BlackMisc::Simulation::CAircraftModel getOwnModelForModelString(const QString &modelString) const; - - //! Own models - BlackMisc::Simulation::CAircraftModelList getOwnModels() const; - - //! Own models for simulator - const BlackMisc::Simulation::CSimulatorInfo &getOwnModelsSimulator() const; - - //! Number of own models - int getOwnModelsCount() const; - //! Current tab index TabIndex currentTabIndex() const; @@ -108,6 +96,22 @@ namespace BlackGui //! \note not guaranteed to be valid, just a snapshot of its current editor state BlackMisc::Simulation::CAircraftModel getEditorAircraftModel() const; + //! \name Own models from BlackGui::Components::CDbOwnModelsComponent + //! @{ + + //! Own models + BlackMisc::Simulation::CAircraftModelList getOwnModels() const; + + //! Own (installed) model for given model string + BlackMisc::Simulation::CAircraftModel getOwnModelForModelString(const QString &modelString) const; + + //! Own models for simulator + const BlackMisc::Simulation::CSimulatorInfo &getOwnModelsSimulator() const; + + //! Number of own models + int getOwnModelsCount() const; + //! @} + public slots: //! \copydoc CDbStashComponent::stashModel BlackMisc::CStatusMessage stashModel(const BlackMisc::Simulation::CAircraftModel &model, bool replace = false); @@ -165,9 +169,6 @@ namespace BlackGui //! Request update of vPilot data void ps_requestVPilotDataUpdate(); - //! Request own models - void ps_requestOwnModelsUpdate(); - //! Stashed models changed void ps_onStashedModelsChanged(); @@ -189,18 +190,6 @@ namespace BlackGui //! Row has been selected void ps_onModelRowSelected(const QModelIndex &index); - //! Load the models - void ps_loadInstalledModels(const BlackMisc::Simulation::CSimulatorInfo &simInfo, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode); - - //! Model loading finished - void ps_onOwnModelsLoadingFinished(bool success, const BlackMisc::Simulation::CSimulatorInfo &simInfo); - - //! Own model count changed - void ps_onOwnModelsCountChanged(int count, bool withFilter); - - //! Request simulator models - void ps_requestSimulatorModels(const BlackMisc::Simulation::CSimulatorInfo &simInfo, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode); - //! User object changed void ps_userChanged(); @@ -222,18 +211,16 @@ namespace BlackGui //! Open model modify dialog void ps_modifyModelDialog(); - //! Open simulator file - void ps_showSimulatorFile(); + //! Own models have been changed + void ps_onOwnModelsCountChanged(int count, bool withFilter); private: QScopedPointer ui; QScopedPointer m_autoStashDialog; //!< dialog auto stashing QScopedPointer m_modelModifyDialog; //!< dialog when modifying models BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules - std::unique_ptr m_modelLoader; //!< read own aircraft models BlackMisc::CData m_cachedVPilotModels { this, &CDbMappingComponent::ps_onVPilotCacheChanged }; //!< cache for latest vPilot rules BlackMisc::CData m_swiftDbUser {this, &CDbMappingComponent::ps_userChanged}; - BlackMisc::CData m_lastInteractions {this}; //!< last interactions bool m_vPilot1stInit = true; bool m_withVPilot = false; bool m_autoFilterInDbViews = false; //!< automatically filter the DB view by the current model @@ -241,9 +228,6 @@ namespace BlackGui //! Init vPilot if rights and suitable void initVPilotLoading(); - //! Init model loader - bool initModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo); - //! Model for given index from sender/current view BlackMisc::Simulation::CAircraftModel getModelFromView(const QModelIndex &index) const; @@ -252,28 +236,14 @@ namespace BlackGui // -------------------- component specific menus -------------------------- - //! The menu for loading and handling own models for mapping tasks - //! \note This is specific for that very component - class CMappingOwnSimulatorModelMenu : public BlackGui::IMenuDelegate - { - public: - //! Constructor - CMappingOwnSimulatorModelMenu(CDbMappingComponent *mappingComponent, bool separator = true) : - BlackGui::IMenuDelegate(mappingComponent, separator) - {} - - //! \copydoc IMenuDelegate::customMenu - virtual void customMenu(QMenu &menu) const override; - }; - //! The menu for loading and handling VPilot rules for mapping tasks //! \note This is a specific menu for that very component - class CMappingVPilotMenu : public BlackGui::IMenuDelegate + class CMappingVPilotMenu : public BlackGui::Menus::IMenuDelegate { public: //! Constructor CMappingVPilotMenu(CDbMappingComponent *mappingComponent, bool separator = true) : - BlackGui::IMenuDelegate(mappingComponent, separator) + BlackGui::Menus::IMenuDelegate(mappingComponent, separator) {} //! \copydoc IMenuDelegate::customMenu @@ -289,12 +259,12 @@ namespace BlackGui //! -# for auto stashing //! -# toggle auto filtering //! \note This is a specific menu for that very component - class CModelStashTools : public BlackGui::IMenuDelegate + class CModelStashTools : public BlackGui::Menus::IMenuDelegate { public: //! Constructor CModelStashTools(CDbMappingComponent *mappingComponent, bool separator = true) : - BlackGui::IMenuDelegate(mappingComponent, separator) + BlackGui::Menus::IMenuDelegate(mappingComponent, separator) {} //! \copydoc IMenuDelegate::customMenu @@ -306,29 +276,12 @@ namespace BlackGui }; //! Apply DB data to selected models - class CApplyDbDataMenu : public BlackGui::IMenuDelegate + class CApplyDbDataMenu : public BlackGui::Menus::IMenuDelegate { public: //! Constructor CApplyDbDataMenu(CDbMappingComponent *mappingComponent, bool separator = true) : - BlackGui::IMenuDelegate(mappingComponent, separator) - {} - - //! \copydoc IMenuDelegate::customMenu - virtual void customMenu(QMenu &menu) const override; - - private: - //! Mapping component - CDbMappingComponent *mappingComponent() const; - }; - - //! Open up the simulator file (e.g. aircraft.cfg) in the standard text editor - class CShowSimulatorFile : public BlackGui::IMenuDelegate - { - public: - //! Constructor - CShowSimulatorFile(CDbMappingComponent *mappingComponent, bool separator = true) : - BlackGui::IMenuDelegate(mappingComponent, separator) + BlackGui::Menus::IMenuDelegate(mappingComponent, separator) {} //! \copydoc IMenuDelegate::customMenu diff --git a/src/blackgui/components/dbmappingcomponent.ui b/src/blackgui/components/dbmappingcomponent.ui index 83b1f76dc..4d824ff5b 100644 --- a/src/blackgui/components/dbmappingcomponent.ui +++ b/src/blackgui/components/dbmappingcomponent.ui @@ -66,7 +66,7 @@ - 3 + 0 @@ -104,7 +104,7 @@ Own models - + 4 @@ -121,22 +121,13 @@ 0 - - - - 0 - 0 - + + + QFrame::StyledPanel - - QAbstractItemView::MultiSelection + + QFrame::Raised - - QAbstractItemView::SelectRows - - - false - @@ -442,6 +433,12 @@
blackgui/components/dbownmodelsetcomponent.h
1 + + BlackGui::Components::CDbOwnModelsComponent + QFrame +
blackgui/components/dbownmodelscomponent.h
+ 1 +
diff --git a/src/blackgui/components/dbmodelcomponent.h b/src/blackgui/components/dbmodelcomponent.h index f754b585c..d65718477 100644 --- a/src/blackgui/components/dbmodelcomponent.h +++ b/src/blackgui/components/dbmodelcomponent.h @@ -16,7 +16,7 @@ #include "blackgui/enableforviewbasedindicator.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/dbmappingcomponentaware.h" -#include "blackgui/menudelegate.h" +#include "blackgui/menus/menudelegate.h" #include "blackmisc/network/entityflags.h" #include #include @@ -28,7 +28,7 @@ namespace BlackGui namespace Components { /** - * Database models from DB + * Database models. Those are the models loaaded from the DB. */ class BLACKGUI_EXPORT CDbModelComponent : public QFrame, diff --git a/src/blackgui/components/dbownmodelscomponent.cpp b/src/blackgui/components/dbownmodelscomponent.cpp new file mode 100644 index 000000000..062ef6361 --- /dev/null +++ b/src/blackgui/components/dbownmodelscomponent.cpp @@ -0,0 +1,271 @@ +/* Copyright (C) 2016 + * 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 "dbownmodelscomponent.h" +#include "blackgui/guiapplication.h" +#include "blackgui/menus/aircraftmodelmenus.h" +#include "blackmisc/statusmessage.h" +#include "blackmisc/logmessage.h" +#include "ui_dbownmodelscomponent.h" + +using namespace BlackMisc; +using namespace BlackMisc::Simulation; +using namespace BlackGui::Menus; +using namespace BlackGui::Views; +using namespace BlackGui::Models; + +namespace BlackGui +{ + namespace Components + { + CDbOwnModelsComponent::CDbOwnModelsComponent(QWidget *parent) : + QFrame(parent), + ui(new Ui::CDbOwnModelsComponent) + { + ui->setupUi(this); + ui->tvp_OwnAircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping); + ui->tvp_OwnAircraftModels->addFilterDialog(); + ui->tvp_OwnAircraftModels->setDisplayAutomatically(true); + ui->tvp_OwnAircraftModels->setCustomMenu(new CShowSimulatorFileMenu(ui->tvp_OwnAircraftModels, false), true); + + connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::requestUpdate, this, &CDbOwnModelsComponent::ps_requestOwnModelsUpdate); + + this->m_lastInteractions.synchronize(); + const CSimulatorInfo sim = this->m_lastInteractions.get().getLastSimulatorSelection(); + if (sim.isSingleSimulator()) + { + // if we have already use this before, use it again, but only from cache + this->initModelLoader(sim); + this->m_modelLoader->startLoading(IAircraftModelLoader::CacheOnly); + } + + ui->tvp_OwnAircraftModels->setCustomMenu(new CMergeWithDbDataMenu(ui->tvp_OwnAircraftModels, this->m_modelLoader.get(), false)); + ui->tvp_OwnAircraftModels->setCustomMenu(new CLoadModelsMenu(this, true)); + } + + CDbOwnModelsComponent::~CDbOwnModelsComponent() + { + // void + } + + CAircraftModelView *CDbOwnModelsComponent::view() const + { + return ui->tvp_OwnAircraftModels; + } + + CAircraftModelListModel *CDbOwnModelsComponent::model() const + { + return ui->tvp_OwnAircraftModels->derivedModel(); + } + + CAircraftModel CDbOwnModelsComponent::getOwnModelForModelString(const QString &modelString) const + { + if (!this->m_modelLoader) { return CAircraftModel(); } + return this->m_modelLoader->getAircraftModels().findFirstByModelStringOrDefault(modelString); + } + + CAircraftModelList CDbOwnModelsComponent::getOwnModels() const + { + static const CAircraftModelList empty; + if (!this->m_modelLoader) { return empty; } + return this->m_modelLoader->getAircraftModels(); + } + + const CSimulatorInfo &CDbOwnModelsComponent::getOwnModelsSimulator() const + { + static const CSimulatorInfo noSim; + if (!this->m_modelLoader) { return noSim; } + return this->m_modelLoader->getSimulator(); + } + + int CDbOwnModelsComponent::getOwnModelsCount() const + { + if (!this->m_modelLoader) { return 0; } + return this->m_modelLoader->getAircraftModelsCount(); + } + + void CDbOwnModelsComponent::gracefulShutdown() + { + if (this->m_modelLoader) { this->m_modelLoader->gracefulShutdown(); } + } + + bool CDbOwnModelsComponent::initModelLoader(const CSimulatorInfo &simInfo) + { + // already loaded + Q_ASSERT_X(simInfo.isSingleSimulator(), Q_FUNC_INFO, "need single simulator"); + if (this->m_modelLoader && this->m_modelLoader->supportsSimulator(simInfo)) + { + return true; + } + + // unload old + if (this->m_modelLoader) + { + this->m_modelLoader->gracefulShutdown(); + } + + // create loader, also syncronizes the caches + this->m_modelLoader = IAircraftModelLoader::createModelLoader(simInfo); + if (!this->m_modelLoader || !this->m_modelLoader->supportsSimulator(simInfo)) + { + CLogMessage(this).error("Failed to init model loader %1") << simInfo.toQString(); + this->m_modelLoader.reset(); + return false; + } + else + { + bool c = connect(this->m_modelLoader.get(), &IAircraftModelLoader::loadingFinished, this, &CDbOwnModelsComponent::ps_onOwnModelsLoadingFinished); + Q_ASSERT_X(c, Q_FUNC_INFO, "Failed connect for model loader"); + Q_UNUSED(c); + return true; + } + } + + void CDbOwnModelsComponent::CLoadModelsMenu::customMenu(QMenu &menu) const + { + CSimulatorInfo sims = CSimulatorInfo::getLocallyInstalledSimulators(); + bool noSims = sims.isNoSimulator() || sims.isUnspecified(); + if (!noSims) + { + this->addSeparator(menu); + QMenu *load = menu.addMenu(CIcons::appModels16(), "Load installed models"); + CDbOwnModelsComponent *ownModelsComp = qobject_cast(this->parent()); + Q_ASSERT_X(ownModelsComp, Q_FUNC_INFO, "Cannot access parent"); + if (sims.fsx()) + { + load->addAction(CIcons::appModels16(), "FSX models", ownModelsComp, [ownModelsComp]() + { + ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FSX), IAircraftModelLoader::InBackgroundWithCache); + }); + } + if (sims.p3d()) + { + load->addAction(CIcons::appModels16(), "P3D models", ownModelsComp, [ownModelsComp]() + { + ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::P3D), IAircraftModelLoader::InBackgroundWithCache); + }); + } + if (sims.fs9()) + { + load->addAction(CIcons::appModels16(), "FS9 models", ownModelsComp, [ownModelsComp]() + { + ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FS9), IAircraftModelLoader::InBackgroundWithCache); + }); + } + if (sims.xplane()) + { + load->addAction(CIcons::appModels16(), "XP models", ownModelsComp, [ownModelsComp]() + { + ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::XPLANE), IAircraftModelLoader::InBackgroundWithCache); + }); + } + + // with models loaded I allow a refresh reload + if (sGui->getWebDataServices() && sGui->getWebDataServices()->getModelsCount() > 0) + { + QMenu *reloadMenu = load->addMenu("Force reload"); + if (sims.fsx()) + { + reloadMenu->addAction(CIcons::appModels16(), "FSX models", ownModelsComp, [ownModelsComp]() + { + ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FSX), IAircraftModelLoader::InBackgroundNoCache); + }); + } + if (sims.p3d()) + { + reloadMenu->addAction(CIcons::appModels16(), "P3D models", ownModelsComp, [ownModelsComp]() + { + ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::P3D), IAircraftModelLoader::InBackgroundNoCache); + }); + } + if (sims.fs9()) + { + reloadMenu->addAction(CIcons::appModels16(), "FS9 models", ownModelsComp, [ownModelsComp]() + { + ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FS9), IAircraftModelLoader::InBackgroundNoCache); + }); + } + if (sims.xplane()) + { + reloadMenu->addAction(CIcons::appModels16(), "XP models", ownModelsComp, [ownModelsComp]() + { + ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::XPLANE), IAircraftModelLoader::InBackgroundNoCache); + }); + } + } + } + this->nestedCustomMenu(menu); + } + + void CDbOwnModelsComponent::ps_requestOwnModelsUpdate() + { + if (!this->m_modelLoader) { return; } + this->ui->tvp_OwnAircraftModels->updateContainerMaybeAsync( + this->m_modelLoader->getAircraftModels() + ); + } + + void CDbOwnModelsComponent::ps_loadInstalledModels(const CSimulatorInfo &simInfo, IAircraftModelLoader::LoadMode mode) + { + if (!this->initModelLoader(simInfo)) + { + CLogMessage(this).error("Cannot load model loader for %1") << simInfo.toQString(); + return; + } + + if (!this->m_modelLoader->isLoadingFinished()) + { + CLogMessage(this).info("Loading for %1 already in progress") << simInfo.toQString(); + return; + } + + CLogMessage(this).info("Starting loading for %1") << simInfo.toQString(); + this->ui->tvp_OwnAircraftModels->showLoadIndicator(); + Q_ASSERT_X(sGui && sGui->getWebDataServices(), Q_FUNC_INFO, "missing web data services"); + this->m_modelLoader->startLoading(mode, sGui->getWebDataServices()->getModels()); + } + + void CDbOwnModelsComponent::ps_onOwnModelsLoadingFinished(bool success, const CSimulatorInfo &simInfo) + { + Q_ASSERT_X(simInfo.isSingleSimulator(), Q_FUNC_INFO, "Expect single simulator"); + if (success && this->m_modelLoader) + { + const CAircraftModelList models(this->m_modelLoader->getAircraftModels()); + const int modelsLoaded = models.size(); + this->ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(models); + if (modelsLoaded > 0) + { + // store for later + Data::CDbOwnModelsComponent mc(this->m_lastInteractions.get()); + if (simInfo.isSingleSimulator() && mc.getLastSimulatorSelection() != simInfo) + { + mc.setLastSimulatorSelection(simInfo); + this->m_lastInteractions.set(mc); + } + } + else + { + // loading ok, but no data + CLogMessage(this).warning("Loading completed, but no models"); + } + } + else + { + this->ui->tvp_OwnAircraftModels->hideLoadIndicator(); + CLogMessage(this).error("Loading of models failed, simulator %1") << simInfo.toQString(); + } + this->ui->tvp_OwnAircraftModels->hideLoadIndicator(); + } + + void CDbOwnModelsComponent::ps_requestSimulatorModels(const CSimulatorInfo &simInfo, IAircraftModelLoader::LoadMode mode) + { + this->ps_loadInstalledModels(simInfo, mode); + } + } // ns +} // ns diff --git a/src/blackgui/components/dbownmodelscomponent.h b/src/blackgui/components/dbownmodelscomponent.h new file mode 100644 index 000000000..ad8b1959d --- /dev/null +++ b/src/blackgui/components/dbownmodelscomponent.h @@ -0,0 +1,101 @@ +/* Copyright (C) 2016 + * 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_DBOWNMODELSCOMPONENT_H +#define BLACKGUI_COMPONENTS_DBOWNMODELSCOMPONENT_H + +#include "blackgui/models/aircraftmodellistmodel.h" +#include "blackgui/components/data/lastselections.h" +#include "blackgui/menus/menudelegate.h" +#include "blackmisc/simulation/aircraftmodelloader.h" +#include +#include + +namespace Ui { class CDbOwnModelsComponent; } + +namespace BlackGui +{ + namespace Views { class CAircraftModelView; } + namespace Components + { + /*! + * Handling of own models on disk (the models installed for the simulator) + */ + class CDbOwnModelsComponent : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CDbOwnModelsComponent(QWidget *parent = nullptr); + + //! Destructor + ~CDbOwnModelsComponent(); + + //! Own (installed) model for given model string + BlackMisc::Simulation::CAircraftModel getOwnModelForModelString(const QString &modelString) const; + + //! Own models + BlackMisc::Simulation::CAircraftModelList getOwnModels() const; + + //! Own models for simulator + const BlackMisc::Simulation::CSimulatorInfo &getOwnModelsSimulator() const; + + //! Number of own models + int getOwnModelsCount() const; + + //! Models view + BlackGui::Views::CAircraftModelView *view() const; + + //! Access to aircraft model + Models::CAircraftModelListModel *model() const; + + //! Graceful shutdown + void gracefulShutdown(); + + private slots: + //! Request own models + void ps_requestOwnModelsUpdate(); + + //! Load the models + void ps_loadInstalledModels(const BlackMisc::Simulation::CSimulatorInfo &simInfo, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode); + + //! Model loading finished + void ps_onOwnModelsLoadingFinished(bool success, const BlackMisc::Simulation::CSimulatorInfo &simInfo); + + //! Request simulator models + void ps_requestSimulatorModels(const BlackMisc::Simulation::CSimulatorInfo &simInfo, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode); + + private: + QScopedPointer ui; + std::unique_ptr m_modelLoader; //!< read own aircraft models + BlackMisc::CData m_lastInteractions {this}; //!< last interactions + + //! Init model loader + bool initModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo); + + //! The menu for loading and handling own models for mapping tasks + //! \note This is specific for that very component + class CLoadModelsMenu : public BlackGui::Menus::IMenuDelegate + { + public: + //! Constructor + CLoadModelsMenu(CDbOwnModelsComponent *ownModelsComponent, bool separator = true) : + BlackGui::Menus::IMenuDelegate(ownModelsComponent, separator) + {} + + //! \copydoc IMenuDelegate::customMenu + virtual void customMenu(QMenu &menu) const override; + }; + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/components/dbownmodelscomponent.ui b/src/blackgui/components/dbownmodelscomponent.ui new file mode 100644 index 000000000..4231cf434 --- /dev/null +++ b/src/blackgui/components/dbownmodelscomponent.ui @@ -0,0 +1,56 @@ + + + CDbOwnModelsComponent + + + + 0 + 0 + 400 + 300 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::SelectRows + + + false + + + + + + + + BlackGui::Views::CAircraftModelView + QTableView +
blackgui/views/aircraftmodelview.h
+
+
+ + +
diff --git a/src/blackgui/components/dbownmodelsetcomponent.cpp b/src/blackgui/components/dbownmodelsetcomponent.cpp index 492ce42ba..286c035b6 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.cpp +++ b/src/blackgui/components/dbownmodelsetcomponent.cpp @@ -41,7 +41,7 @@ namespace BlackGui // void } - Views::CAircraftModelView *CDbOwnModelSetComponent::getView() const + Views::CAircraftModelView *CDbOwnModelSetComponent::view() const { return ui->tvp_OwnModelSet; } diff --git a/src/blackgui/components/dbownmodelsetcomponent.h b/src/blackgui/components/dbownmodelsetcomponent.h index 776419416..56d4aec6d 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.h +++ b/src/blackgui/components/dbownmodelsetcomponent.h @@ -7,6 +7,8 @@ * contained in the LICENSE file. */ +//! \file + #ifndef BLACKGUI_COMPONENTS_DBOWNMODELSETCOMPONENT_H #define BLACKGUI_COMPONENTS_DBOWNMODELSETCOMPONENT_H @@ -15,7 +17,6 @@ #include #include - namespace Ui { class CDbOwnModelSetComponent; } namespace BlackGui @@ -42,7 +43,7 @@ namespace BlackGui virtual ~CDbOwnModelSetComponent(); //! Corresponding view - Views::CAircraftModelView *getView() const; + Views::CAircraftModelView *view() const; //! Set the model set void setModelSet(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator); @@ -50,6 +51,9 @@ namespace BlackGui //! \copydoc CDbMappingComponentAware::setMappingComponent virtual void setMappingComponent(CDbMappingComponent *component) override; + //! Model set is for simulator + const BlackMisc::Simulation::CSimulatorInfo &getModelSetSimulator() const { return m_simulator; } + private slots: //! Tab has been changed void ps_tabChanged(int index); diff --git a/src/blackgui/components/dbstashcomponent.cpp b/src/blackgui/components/dbstashcomponent.cpp index d0f4814e4..a1ed1c2f7 100644 --- a/src/blackgui/components/dbstashcomponent.cpp +++ b/src/blackgui/components/dbstashcomponent.cpp @@ -125,7 +125,7 @@ namespace BlackGui return this->ui->tvp_StashAircraftModels->removeModelsWithModelString(modelStrings); } - Views::CAircraftModelView *CDbStashComponent::getView() const + CAircraftModelView *CDbStashComponent::view() const { return ui->tvp_StashAircraftModels; } diff --git a/src/blackgui/components/dbstashcomponent.h b/src/blackgui/components/dbstashcomponent.h index b447b5d8b..f516fd4d9 100644 --- a/src/blackgui/components/dbstashcomponent.h +++ b/src/blackgui/components/dbstashcomponent.h @@ -14,7 +14,7 @@ #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/dbmappingcomponentaware.h" -#include "blackgui/menudelegate.h" +#include "blackgui/menus/menudelegate.h" #include "blackmisc/verify.h" #include #include @@ -60,7 +60,7 @@ namespace BlackGui int unstashModels(QStringList modelStrings); //! The embedded view - BlackGui::Views::CAircraftModelView *getView() const; + BlackGui::Views::CAircraftModelView *view() const; //! Has stashed models bool hasStashedModels() const; diff --git a/src/blackgui/components/registermetadatacomponents.cpp b/src/blackgui/components/registermetadatacomponents.cpp index 10e288e19..83bf1b1c1 100644 --- a/src/blackgui/components/registermetadatacomponents.cpp +++ b/src/blackgui/components/registermetadatacomponents.cpp @@ -16,7 +16,7 @@ namespace BlackGui { void registerMetadata() { - Data::CDbMappingComponent::registerMetadata(); + Data::CDbOwnModelsComponent::registerMetadata(); } } // ns