diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index 8016323fd..5d2c0e632 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -43,6 +43,7 @@ namespace BlackGui { ui->setupUi(this); this->ui->comp_StashAircraft->setMappingComponent(this); + this->ui->comp_OwnModelSet->setMappingComponent(this); this->ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel); this->ui->tvp_AircraftModelsForVPilot->addFilterDialog(); @@ -64,13 +65,21 @@ namespace BlackGui 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->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)); - if (this->m_modelLoader) + + this->m_lastInteractions.synchronize(); + const CSimulatorInfo sim = this->m_lastInteractions.get().getLastSimulatorSelection(); + if (sim.isSingleSimulator()) { - ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(this->m_modelLoader->getAircraftModels()); + // 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 @@ -84,21 +93,6 @@ namespace BlackGui // vPilot this->initVPilotLoading(); - QTimer::singleShot(1000, this, &CDbMappingComponent::ps_deferredInit); - } - - void CDbMappingComponent::ps_deferredInit() - { - // deferred - 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); - } } CDbMappingComponent::~CDbMappingComponent() @@ -169,7 +163,6 @@ namespace BlackGui 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; @@ -221,23 +214,7 @@ namespace BlackGui return false; } - const CAircraftModelView *CDbMappingComponent::currentModelView() const - { - TabIndex tab = currentTabIndex(); - switch (tab) - { - case TabOwnModels: - return ui->tvp_OwnAircraftModels; - case TabVPilot: - return ui->tvp_AircraftModelsForVPilot; - case TabStash: - return ui->comp_StashAircraft->getView(); - default: - return nullptr; - } - } - - CAircraftModelView *CDbMappingComponent::currentModelView() + CAircraftModelView *CDbMappingComponent::currentModelView() const { TabIndex tab = currentTabIndex(); switch (tab) @@ -248,6 +225,8 @@ namespace BlackGui return ui->tvp_AircraftModelsForVPilot; case TabStash: return ui->comp_StashAircraft->getView(); + case TabOwnModelSet: + return ui->comp_OwnModelSet->getView(); default: return nullptr; } @@ -291,6 +270,26 @@ namespace BlackGui 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; } @@ -583,7 +582,7 @@ namespace BlackGui QString o(ot); if (this->m_modelLoader) { - QString sims(this->m_modelLoader->supportedSimulatorsAsString()); + QString sims(this->m_modelLoader->getSimulatorAsString()); if (!sims.isEmpty()) { o = o.append(" ").append(sims); } } QString f = this->ui->tvp_OwnAircraftModels->hasFilter() ? "F" : ""; @@ -602,6 +601,17 @@ namespace BlackGui this->ui->tw_ModelsToBeMapped->setTabText(i, o); } + void CDbMappingComponent::ps_onModelSetCountChanged(int count, bool withFilter) + { + 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; + this->ui->tw_ModelsToBeMapped->setTabText(i, o); + } + void CDbMappingComponent::ps_requestSimulatorModels(const CSimulatorInfo &simInfo, IAircraftModelLoader::LoadMode mode) { this->ps_loadInstalledModels(simInfo, mode); @@ -696,6 +706,7 @@ namespace BlackGui 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()); @@ -764,21 +775,21 @@ namespace BlackGui 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.fs9()) + if (sims.fsx()) { - load->addAction(CIcons::appModels16(), "FS9 models", mapComp, [mapComp]() + load->addAction(CIcons::appModels16(), "FSX models", mapComp, [mapComp]() { mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FSX), IAircraftModelLoader::InBackgroundWithCache); }); } - if (sims.fsx()) + if (sims.p3d()) { load->addAction(CIcons::appModels16(), "P3D models", mapComp, [mapComp]() { mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::P3D), IAircraftModelLoader::InBackgroundWithCache); }); } - if (sims.p3d()) + if (sims.fs9()) { load->addAction(CIcons::appModels16(), "FS9 models", mapComp, [mapComp]() { @@ -797,21 +808,21 @@ namespace BlackGui if (sGui->getWebDataServices() && sGui->getWebDataServices()->getModelsCount() > 0) { QMenu *reloadMenu = load->addMenu("Force reload"); - if (sims.fs9()) + if (sims.fsx()) { - reloadMenu->addAction(CIcons::appModels16(), "FS9 models", mapComp, [mapComp]() + reloadMenu->addAction(CIcons::appModels16(), "FSX models", mapComp, [mapComp]() { mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FSX), IAircraftModelLoader::InBackgroundNoCache); }); } - if (sims.fsx()) + if (sims.p3d()) { reloadMenu->addAction(CIcons::appModels16(), "P3D models", mapComp, [mapComp]() { mapComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::P3D), IAircraftModelLoader::InBackgroundNoCache); }); } - if (sims.p3d()) + if (sims.fs9()) { reloadMenu->addAction(CIcons::appModels16(), "FS9 models", mapComp, [mapComp]() { @@ -912,9 +923,6 @@ namespace BlackGui a = subMenu->addAction(CIcons::appLiveries16(), "Current livery", mapComp, SLOT(ps_applyDbData())); a->setData(CLivery().getClassName()); - // a = subMenu->addAction(CIcons::appAirlineIcao16(), "Current airline ICAO", mapComp, SLOT(ps_applyDbData())); - // a->setData(CAirlineIcaoCode().getClassName()); - menu.addAction(CIcons::databaseTable16(), "Modify model data", mapComp, SLOT(ps_modifyModelDialog())); } this->nestedCustomMenu(menu); diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index f0c3f17d5..279cbe31b 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -13,7 +13,6 @@ #define BLACKGUI_COMPONENTS_DBMAPPINGCOMPONENT_H #include "blackcore/data/authenticateduser.h" -#include "blackcore/data/aircraftmodels.h" #include "blackgui/blackguiexport.h" #include "blackgui/overlaymessagesframe.h" #include "blackgui/menudelegate.h" @@ -23,6 +22,7 @@ #include "blackgui/views/aircraftmodelview.h" #include "blackmisc/simulation/aircraftmodelloader.h" #include "blackmisc/simulation/fscommon/vpilotrulesreader.h" +#include "blackmisc/simulation/data/modelcaches.h" #include "blackmisc/network/entityflags.h" #include "blackmisc/statusmessagelist.h" #include @@ -52,10 +52,11 @@ namespace BlackGui //! Must match real tab index enum TabIndex { - NoValidTab = -1, - TabStash = 0, - TabOwnModels = 1, - TabVPilot = 2 + NoValidTab = -1, + TabStash = 0, + TabOwnModels = 1, + TabOwnModelSet = 2, + TabVPilot = 3 }; //! Constructor @@ -85,14 +86,20 @@ namespace BlackGui //! 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; //! Current model view - const BlackGui::Views::CAircraftModelView *currentModelView() const; - - //! Current model view - BlackGui::Views::CAircraftModelView *currentModelView(); + BlackGui::Views::CAircraftModelView *currentModelView() const; //! Is stashed view bool isStashedTab() const; @@ -142,6 +149,9 @@ namespace BlackGui //! Request latest (incremental) data from backend void requestUpdatedData(BlackMisc::Network::CEntityFlags::Entity entities); + //! Tab index has been changed + void tabIndexChanged(int index); + private slots: //! Load the vPilot rules void ps_loadVPilotData(); @@ -173,6 +183,9 @@ namespace BlackGui //! Stash count has been changed void ps_onStashCountChanged(int count, bool withFilter); + //! Model set count has been changed + void ps_onModelSetCountChanged(int count, bool withFilter); + //! Row has been selected void ps_onModelRowSelected(const QModelIndex &index); @@ -212,18 +225,15 @@ namespace BlackGui //! Open simulator file void ps_showSimulatorFile(); - //! When main GUI application has been started - void ps_deferredInit(); - private: - QScopedPointer ui; - QScopedPointer m_autoStashDialog; //!< dialog auto stashing - QScopedPointer m_modelModifyDialog; - 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 + 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 diff --git a/src/blackgui/components/dbmappingcomponent.ui b/src/blackgui/components/dbmappingcomponent.ui index 16d0106cd..83b1f76dc 100644 --- a/src/blackgui/components/dbmappingcomponent.ui +++ b/src/blackgui/components/dbmappingcomponent.ui @@ -66,7 +66,7 @@ - 0 + 3 @@ -141,6 +141,38 @@ + + + My model set + + + + 4 + + + 0 + + + 2 + + + 0 + + + 0 + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + vPilot rules @@ -404,6 +436,12 @@
blackgui/components/dbstashcomponent.h
1 + + BlackGui::Components::CDbOwnModelSetComponent + QFrame +
blackgui/components/dbownmodelsetcomponent.h
+ 1 +
diff --git a/src/blackgui/components/dbmappingcomponentaware.cpp b/src/blackgui/components/dbmappingcomponentaware.cpp index 817c400d6..f4a09378a 100644 --- a/src/blackgui/components/dbmappingcomponentaware.cpp +++ b/src/blackgui/components/dbmappingcomponentaware.cpp @@ -14,6 +14,11 @@ namespace BlackGui { namespace Components { + void CDbMappingComponentAware::setMappingComponent(CDbMappingComponent *component) + { + m_mappingComponent = component; + } + CDbMappingComponentAware::CDbMappingComponentAware(QObject *parent) { // if we get a mapping component we use it @@ -23,5 +28,6 @@ namespace BlackGui if (!m) { return; } m_mappingComponent = m; } + } // ns } // ns diff --git a/src/blackgui/components/dbmappingcomponentaware.h b/src/blackgui/components/dbmappingcomponentaware.h index d94d31bb7..6afdf0f9b 100644 --- a/src/blackgui/components/dbmappingcomponentaware.h +++ b/src/blackgui/components/dbmappingcomponentaware.h @@ -26,20 +26,17 @@ namespace BlackGui { public: //! Set the corresponding component - void setMappingComponent(CDbMappingComponent *component) { m_mappingComponent = component; } + virtual void setMappingComponent(CDbMappingComponent *component); protected: //! Constructor CDbMappingComponentAware(QObject *parent); //! Get the mapping component - const CDbMappingComponent *getMappingComponent() const { return m_mappingComponent; } - - //! Get mapping component - CDbMappingComponent *getMappingComponent() { return m_mappingComponent; } + CDbMappingComponent *getMappingComponent() const { return m_mappingComponent; } private : - CDbMappingComponent *m_mappingComponent = nullptr; + CDbMappingComponent *m_mappingComponent = nullptr; //!< reference to component }; } // ns } // ns diff --git a/src/blackgui/components/dbownmodelsetcomponent.cpp b/src/blackgui/components/dbownmodelsetcomponent.cpp new file mode 100644 index 000000000..492ce42ba --- /dev/null +++ b/src/blackgui/components/dbownmodelsetcomponent.cpp @@ -0,0 +1,115 @@ +/* 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 "dbownmodelsetcomponent.h" +#include "blackmisc/simulation/aircraftmodellist.h" +#include "blackgui/models/aircrafticaolistmodel.h" +#include "dbmappingcomponent.h" +#include "dbownmodelsetdialog.h" +#include "ui_dbownmodelsetcomponent.h" + +using namespace BlackMisc; +using namespace BlackMisc::Simulation; +using namespace BlackGui::Models; +using namespace BlackGui::Views; + +namespace BlackGui +{ + namespace Components + { + CDbOwnModelSetComponent::CDbOwnModelSetComponent(QWidget *parent) : + QFrame(parent), + CDbMappingComponentAware(parent), + ui(new Ui::CDbOwnModelSetComponent) + { + ui->setupUi(this); + ui->tvp_OwnModelSet->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping); + ui->tvp_OwnModelSet->menuRemoveItems(CAircraftModelView::MenuDisplayAutomaticallyAndRefresh | CAircraftModelView::MenuStashing | CAircraftModelView::MenuBackend | CAircraftModelView::MenuRefresh); + ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows); + connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked); + connect(ui->pb_LoadExistingSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked); + } + + CDbOwnModelSetComponent::~CDbOwnModelSetComponent() + { + // void + } + + Views::CAircraftModelView *CDbOwnModelSetComponent::getView() const + { + return ui->tvp_OwnModelSet; + } + + void CDbOwnModelSetComponent::setModelSet(const CAircraftModelList &models, const CSimulatorInfo &simulator) + { + this->ui->tvp_OwnModelSet->updateContainerMaybeAsync(models); + this->ui->pb_SaveAsSetForSimulator->setText("save for " + simulator.toQString()); + this->ui->pb_SaveAsSetForSimulator->setEnabled(!models.isEmpty()); + this->m_simulator = simulator; + } + + void CDbOwnModelSetComponent::setMappingComponent(CDbMappingComponent *component) + { + CDbMappingComponentAware::setMappingComponent(component); + if (component) + { + connect(this->getMappingComponent(), &CDbMappingComponent::tabIndexChanged, this, &CDbOwnModelSetComponent::ps_tabChanged); + } + } + + void CDbOwnModelSetComponent::ps_tabChanged(int index) + { + CDbMappingComponent::TabIndex ti = static_cast(index); + if (ti == CDbMappingComponent::TabOwnModelSet) + { + // myself + this->getMappingComponent()->resizeForSelect(); + } + else + { + // others + } + } + + void CDbOwnModelSetComponent::ps_buttonClicked() + { + const QObject *sender = QObject::sender(); + if (sender == ui->pb_CreateNewSet) + { + if (!this->m_modelSetDialog) + { + this->m_modelSetDialog.reset(new CDbOwnModelSetDialog(this)); + this->m_modelSetDialog->setMappingComponent(this->getMappingComponent()); + } + + if (this->getMappingComponent()->getOwnModelsCount() > 0) + { + this->m_modelSetDialog->setModal(true); + this->m_modelSetDialog->reloadData(); + QDialog::DialogCode rc = static_cast( + this->m_modelSetDialog->exec() + ); + if (rc == QDialog::Accepted) + { + this->setModelSet(this->m_modelSetDialog->getModelSet(), this->m_modelSetDialog->getSimulatorInfo()); + } + } + else + { + static const CStatusMessage m(CStatusMessage(this, CStatusMessage::SeverityError, "No model data")); + this->getMappingComponent()->showOverlayMessage(m); + } + } + else if (sender == ui->pb_LoadExistingSet) + { + this->ui->tvp_OwnModelSet->showFileLoadDialog(); + } + } + } // ns +} // ns diff --git a/src/blackgui/components/dbownmodelsetcomponent.h b/src/blackgui/components/dbownmodelsetcomponent.h new file mode 100644 index 000000000..776419416 --- /dev/null +++ b/src/blackgui/components/dbownmodelsetcomponent.h @@ -0,0 +1,69 @@ +/* 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. + */ + +#ifndef BLACKGUI_COMPONENTS_DBOWNMODELSETCOMPONENT_H +#define BLACKGUI_COMPONENTS_DBOWNMODELSETCOMPONENT_H + +#include "blackmisc/simulation/aircraftmodellist.h" +#include "dbmappingcomponentaware.h" +#include +#include + + +namespace Ui { class CDbOwnModelSetComponent; } + +namespace BlackGui +{ + namespace Views { class CAircraftModelView; } + namespace Components + { + class CDbOwnModelSetDialog; + + /*! + * Handling of the own model set + */ + class CDbOwnModelSetComponent : + public QFrame, + public CDbMappingComponentAware + { + Q_OBJECT + + public: + //! Constructor + explicit CDbOwnModelSetComponent(QWidget *parent = nullptr); + + //! Destructor + virtual ~CDbOwnModelSetComponent(); + + //! Corresponding view + Views::CAircraftModelView *getView() const; + + //! Set the model set + void setModelSet(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator); + + //! \copydoc CDbMappingComponentAware::setMappingComponent + virtual void setMappingComponent(CDbMappingComponent *component) override; + + private slots: + //! Tab has been changed + void ps_tabChanged(int index); + + //! Button was clicked + void ps_buttonClicked(); + + private: + QScopedPointer ui; + QScopedPointer m_modelSetDialog; + BlackMisc::Simulation::CSimulatorInfo m_simulator; + }; + + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/dbownmodelsetcomponent.ui b/src/blackgui/components/dbownmodelsetcomponent.ui new file mode 100644 index 000000000..5f9fbde9d --- /dev/null +++ b/src/blackgui/components/dbownmodelsetcomponent.ui @@ -0,0 +1,141 @@ + + + CDbOwnModelSetComponent + + + + 0 + 0 + 600 + 400 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::SelectRows + + + false + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 125 + 0 + + + + create a new set + + + new set + + + + + + + + 125 + 0 + + + + load an existing set + + + load + + + + + + + false + + + + 125 + 0 + + + + save + + + + + + + + + + + BlackGui::Views::CAircraftModelView + QTableView +
blackgui/views/aircraftmodelview.h
+
+
+ + +
diff --git a/src/blackgui/components/dbownmodelsetdialog.cpp b/src/blackgui/components/dbownmodelsetdialog.cpp new file mode 100644 index 000000000..26a72992a --- /dev/null +++ b/src/blackgui/components/dbownmodelsetdialog.cpp @@ -0,0 +1,91 @@ +/* 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 "dbownmodelsetdialog.h" +#include "ui_dbownmodelsetdialog.h" +#include "blackgui/components/dbmappingcomponent.h" +#include "blackcore/modelsetbuilder.h" +#include "blackmisc/simulation/distributorlist.h" + +using namespace BlackMisc; +using namespace BlackMisc::Simulation; +using namespace BlackCore; + +namespace BlackGui +{ + namespace Components + { + const CLogCategoryList &CDbOwnModelSetDialog::getLogCategories() + { + static const CLogCategoryList cats({ CLogCategory("swift.ownmodelset"), CLogCategory::guiComponent()}); + return cats; + } + + CDbOwnModelSetDialog::CDbOwnModelSetDialog(QWidget *parent) : + QDialog(parent), + CDbMappingComponentAware(parent), + ui(new Ui::CDbOwnModelSetDialog) + { + ui->setupUi(this); + connect(ui->pb_Cancel, &QPushButton::clicked, this, &CDbOwnModelSetDialog::ps_buttonClicked); + connect(ui->pb_Ok, &QPushButton::clicked, this, &CDbOwnModelSetDialog::ps_buttonClicked); + } + + CDbOwnModelSetDialog::~CDbOwnModelSetDialog() + { + // void + } + + void CDbOwnModelSetDialog::reloadData() + { + this->ui->form_OwnModelSet->reloadData(); + } + + int CDbOwnModelSetDialog::exec() + { + Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component"); + this->m_simulatorInfo = this->getMappingComponent()->getOwnModelsSimulator(); + this->setWindowTitle("Create model set for " + this->m_simulatorInfo.toQString(true)); + return QDialog::exec(); + } + + void CDbOwnModelSetDialog::ps_buttonClicked() + { + const QObject *sender = QObject::sender(); + if (sender == ui->pb_Cancel) + { + this->reject(); + } + else if (sender == ui->pb_Ok) + { + this->m_modelSet = this->buildSet(); + this->accept(); + } + } + + CAircraftModelList CDbOwnModelSetDialog::buildSet() + { + Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component"); + const bool selectedProviders = this->ui->form_OwnModelSet->selectedDistributors(); + const bool dbDataOnly = this->ui->form_OwnModelSet->dbDataOnly(); + const bool dbIcaoOnly = this->ui->form_OwnModelSet->dbIcaoCodesOnly(); + + const CAircraftModelList models = this->getMappingComponent()->getOwnModels(); + this->m_simulatorInfo = this->getMappingComponent()->getOwnModelsSimulator(); + const CDistributorList distributors = selectedProviders ? + this->ui->form_OwnModelSet->getSelectedDistributors() : + CDistributorList(); + const CModelSetBuilder builder(this); + CModelSetBuilder::Builder options = selectedProviders ? CModelSetBuilder::FilterDistributos : CModelSetBuilder::NoOptions; + if (dbDataOnly) { options |= CModelSetBuilder::OnlyDbData; } + if (dbIcaoOnly) { options |= CModelSetBuilder::OnlyDbIcaoCodes; } + return builder.buildModelSet(models, options, distributors); + } + } // ns +} // ns diff --git a/src/blackgui/components/dbownmodelsetdialog.h b/src/blackgui/components/dbownmodelsetdialog.h new file mode 100644 index 000000000..f0e15ce3f --- /dev/null +++ b/src/blackgui/components/dbownmodelsetdialog.h @@ -0,0 +1,74 @@ +/* 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_DBOWNMODELSETDIALOG_H +#define BLACKGUI_COMPONENTS_DBOWNMODELSETDIALOG_H + +#include +#include + +#include "blackmisc/logcategorylist.h" +#include "blackmisc/simulation/aircraftmodellist.h" +#include "blackgui/components/dbmappingcomponentaware.h" + +namespace Ui { class CDbOwnModelSetDialog; } + +namespace BlackGui +{ + namespace Components + { + /*! + * Dialog to create new model set + */ + class CDbOwnModelSetDialog : + public QDialog, + public CDbMappingComponentAware + { + Q_OBJECT + + public: + //! Categories + static const BlackMisc::CLogCategoryList &getLogCategories(); + + //! Constructor + explicit CDbOwnModelSetDialog(QWidget *parent = nullptr); + + //! Destructor + virtual ~CDbOwnModelSetDialog(); + + //! Last build set + const BlackMisc::Simulation::CAircraftModelList &getModelSet() const { return m_modelSet; } + + //! Simulator info + const BlackMisc::Simulation::CSimulatorInfo &getSimulatorInfo() const { return m_simulatorInfo; } + + //! Reload data + void reloadData(); + + //! Exec and display simulator + virtual int exec() override; + + private slots: + //! Button clicked + void ps_buttonClicked(); + + private: + QScopedPointer ui; + BlackMisc::Simulation::CAircraftModelList m_modelSet; + BlackMisc::Simulation::CSimulatorInfo m_simulatorInfo; + + //! Build the set + BlackMisc::Simulation::CAircraftModelList buildSet(); + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/components/dbownmodelsetdialog.ui b/src/blackgui/components/dbownmodelsetdialog.ui new file mode 100644 index 000000000..ff1e9e330 --- /dev/null +++ b/src/blackgui/components/dbownmodelsetdialog.ui @@ -0,0 +1,90 @@ + + + CDbOwnModelSetDialog + + + + 0 + 0 + 400 + 300 + + + + Create a model set + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 0 + 0 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Cancel + + + + + + + OK + + + + + + + + + + + BlackGui::Editors::COwnModelSetForm + QFrame +
blackgui/editors/ownmodelsetform.h
+ 1 +
+
+ + +
diff --git a/src/blackgui/editors/ownmodelsetform.cpp b/src/blackgui/editors/ownmodelsetform.cpp new file mode 100644 index 000000000..1259cd3e7 --- /dev/null +++ b/src/blackgui/editors/ownmodelsetform.cpp @@ -0,0 +1,67 @@ +/* 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 "ownmodelsetform.h" +#include "ui_ownmodelsetform.h" +#include "blackgui/models/distributorlistmodel.h" +#include "blackgui/guiapplication.h" +#include "blackmisc/simulation/distributorlist.h" + +using namespace BlackMisc::Simulation; +using namespace BlackGui::Models; + +namespace BlackGui +{ + namespace Editors + { + COwnModelSetForm::COwnModelSetForm(QWidget *parent) : + QFrame(parent), + ui(new Ui::COwnModelSetForm) + { + ui->setupUi(this); + this->ui->tvp_Distributors->setDistributorMode(CDistributorListModel::Minimal); + } + + COwnModelSetForm::~COwnModelSetForm() + { + // void + } + + void COwnModelSetForm::reloadData() + { + Q_ASSERT_X(sGui && sGui->hasWebDataServices(), Q_FUNC_INFO, "Missing web data services"); + const CDistributorList distributors(sGui->getWebDataServices()->getDistributors()); + if (!distributors.isEmpty()) + { + this->ui->tvp_Distributors->updateContainerMaybeAsync(distributors); + } + } + + bool COwnModelSetForm::selectedDistributors() const + { + return this->ui->rb_SelectedDistributors->isChecked(); + } + + bool COwnModelSetForm::dbDataOnly() const + { + return this->ui->rb_DbDataOnly->isChecked(); + } + + bool COwnModelSetForm::dbIcaoCodesOnly() const + { + return this->ui->rb_DbIcaoCodesOnly->isChecked(); + } + + CDistributorList COwnModelSetForm::getSelectedDistributors() const + { + return ui->tvp_Distributors->selectedObjects(); + } + } // ns +} // ns + diff --git a/src/blackgui/editors/ownmodelsetform.h b/src/blackgui/editors/ownmodelsetform.h new file mode 100644 index 000000000..d5c7389ff --- /dev/null +++ b/src/blackgui/editors/ownmodelsetform.h @@ -0,0 +1,60 @@ +/* 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_EDITORS_OWNMODELSETFORM_H +#define BLACKGUI_EDITORS_OWNMODELSETFORM_H + +#include "blackmisc/simulation/distributorlist.h" +#include +#include + +namespace Ui { class COwnModelSetForm; } + +namespace BlackGui +{ + namespace Editors + { + /*! + * Selection for own model set + */ + class COwnModelSetForm : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit COwnModelSetForm(QWidget *parent = nullptr); + + //! Destructor + ~COwnModelSetForm(); + + //! Reload data + void reloadData(); + + //! Selected providers? + bool selectedDistributors() const; + + //! Get selected providers + BlackMisc::Simulation::CDistributorList getSelectedDistributors() const; + + //! Only DB data + bool dbDataOnly() const; + + //! DB ICAO codes + bool dbIcaoCodesOnly() const; + + private: + QScopedPointer ui; + }; + } // ns +} // ns + +#endif // guard diff --git a/src/blackgui/editors/ownmodelsetform.ui b/src/blackgui/editors/ownmodelsetform.ui new file mode 100644 index 000000000..81e364fa9 --- /dev/null +++ b/src/blackgui/editors/ownmodelsetform.ui @@ -0,0 +1,152 @@ + + + COwnModelSetForm + + + + 0 + 0 + 400 + 300 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 3 + + + 3 + + + 3 + + + 3 + + + + + 3 + + + + + Model has ICAO code known in DB + + + DB ICAO data + + + true + + + bg_SourceSet + + + + + + + Distributors: + + + + + + + Model has ICAO code + + + ICAO data + + + false + + + bg_SourceSet + + + + + + + Source set: + + + + + + + selected + + + bg_Distributors + + + + + + + Own models for which DB data are available + + + DB data only + + + bg_SourceSet + + + + + + + default + + + true + + + bg_Distributors + + + + + + + + + QAbstractItemView::SelectRows + + + false + + + false + + + + + + + + BlackGui::Views::CDistributorView + QTableView +
blackgui/views/distributorview.h
+
+
+ + + + + + +