diff --git a/src/blackgui/components/dbownmodelsetcomponent.cpp b/src/blackgui/components/dbownmodelsetcomponent.cpp index 330371f29..e4b9dcbd1 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.cpp +++ b/src/blackgui/components/dbownmodelsetcomponent.cpp @@ -11,6 +11,7 @@ #include "blackgui/components/dbmappingcomponent.h" #include "blackgui/components/dbownmodelsetcomponent.h" #include "blackgui/components/dbownmodelsetformdialog.h" +#include "blackgui/components/dbreducemodelduplicates.h" #include "blackgui/components/firstmodelsetdialog.h" #include "blackgui/components/copymodelsfromotherswiftversionsdialog.h" #include "blackgui/menus/aircraftmodelmenus.h" @@ -18,6 +19,7 @@ #include "blackgui/models/aircraftmodellistmodel.h" #include "blackgui/views/aircraftmodelview.h" #include "blackgui/views/viewbase.h" +#include "blackgui/views/aircraftmodelstatisticsdialog.h" #include "blackmisc/simulation/aircraftmodelutils.h" #include "blackmisc/simulation/aircraftmodellist.h" #include "blackmisc/simulation/distributorlist.h" @@ -81,7 +83,7 @@ namespace BlackGui connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked); connect(ui->pb_LoadExistingSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked); connect(ui->pb_SaveAsSetForSimulator, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked); - connect(ui->pb_ShowMatrix, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked); + connect(ui->pb_ShowStatistics, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked); connect(ui->pb_CopyFromAnotherSwift, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked); connect(ui->pb_FirstSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked); connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDbOwnModelSetComponent::setSimulator, Qt::QueuedConnection); @@ -236,9 +238,9 @@ namespace BlackGui return; } - if (sender == ui->pb_ShowMatrix) + if (sender == ui->pb_ShowStatistics) { - this->showAirlineAircraftMatrix(); + this->showModelStatistics(); return; } @@ -292,6 +294,27 @@ namespace BlackGui } } + void CDbOwnModelSetComponent::reduceModels() + { + if (!m_reduceModelsDialog) + { + m_reduceModelsDialog.reset(new CDbReduceModelDuplicates(this)); + } + + // CAircraftModelList models = this->getModelSet(); // saved set + CAircraftModelList models = ui->tvp_OwnModelSet->containerOrFilteredContainer(); + const CSimulatorInfo simulator = this->getModelSetSimulator(); + m_reduceModelsDialog->setModels(models, simulator); + QDialog::DialogCode ret = static_cast(m_reduceModelsDialog->exec()); + if (ret != QDialog::Accepted) { return; } + const CAircraftModelList removeModels = m_reduceModelsDialog->getRemoveCandidates(); + const CSimulatorInfo removeSimulator = m_reduceModelsDialog->getSimulator(); + if (removeModels.isEmpty()) { return; } + const QSet keys = removeModels.toDbKeySet(); + models.removeObjectsWithKeys(keys); + this->setModelSet(models, removeSimulator); + } + void CDbOwnModelSetComponent::viewModelChanged() { const bool hasData = ui->tvp_OwnModelSet->rowCount() > 0; @@ -349,20 +372,20 @@ namespace BlackGui void CDbOwnModelSetComponent::firstSet() { - if (!m_firstModelSet) + if (!m_firstModelSetDialog) { - m_firstModelSet.reset(new CFirstModelSetDialog(this)); + m_firstModelSetDialog.reset(new CFirstModelSetDialog(this)); } - m_firstModelSet->show(); + m_firstModelSetDialog->show(); } void CDbOwnModelSetComponent::copyFromAnotherSwift() { - if (!m_copyFromAnotherSwift) + if (!m_copyFromAnotherSwiftDialog) { - m_copyFromAnotherSwift.reset(new CCopyModelsFromOtherSwiftVersionsDialog(this)); + m_copyFromAnotherSwiftDialog.reset(new CCopyModelsFromOtherSwiftVersionsDialog(this)); } - m_copyFromAnotherSwift->show(); + m_copyFromAnotherSwiftDialog->show(); } void CDbOwnModelSetComponent::setSimulator(const CSimulatorInfo &simulator) @@ -392,12 +415,15 @@ namespace BlackGui }); } - void CDbOwnModelSetComponent::showAirlineAircraftMatrix() const + void CDbOwnModelSetComponent::showModelStatistics() { const CAircraftModelList set(this->getModelSetFromView()); - const QString file = CAircraftModelUtilities::createIcaoAirlineAircraftHtmlMatrixFile(set, CGuiApplication::getTemporaryDirectory()); - if (file.isEmpty()) { return; } - QDesktopServices::openUrl(QUrl::fromLocalFile(file)); + if (!m_modelStatisticsDialog) + { + m_modelStatisticsDialog.reset(new CAircraftModelStatisticsDialog(this)); + } + m_modelStatisticsDialog->analyzeModels(set); + m_modelStatisticsDialog->show(); } void CDbOwnModelSetComponent::updateDistributorOrder(const CSimulatorInfo &simulator) @@ -505,6 +531,10 @@ namespace BlackGui QAction *a = new QAction(CIcons::appDistributors16(), "Apply distributor preferences", this); connect(a, &QAction::triggered, ownModelSetComp, &CDbOwnModelSetComponent::distributorPreferencesChanged); m_setActions.append(a); + + a = new QAction(CIcons::delete16(), "Reduce models (remove duplicates)", this); + connect(a, &QAction::triggered, ownModelSetComp, &CDbOwnModelSetComponent::reduceModels); + m_setActions.append(a); } menuActions.addMenuModelSet(); menuActions.addActions(m_setActions, CMenuAction::pathModelSet()); diff --git a/src/blackgui/components/dbownmodelsetcomponent.h b/src/blackgui/components/dbownmodelsetcomponent.h index 59db5a533..655c13e8d 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.h +++ b/src/blackgui/components/dbownmodelsetcomponent.h @@ -33,11 +33,16 @@ namespace BlackMisc { namespace Simulation { class CAircraftModel; } } namespace BlackGui { namespace Menus { class CMenuActions; } - namespace Views { class CAircraftModelView; } + namespace Views + { + class CAircraftModelView; + class CAircraftModelStatisticsDialog; + } namespace Components { class CDbMappingComponent; class CDbOwnModelSetFormDialog; + class CDbReduceModelDuplicates; class CCopyModelsFromOtherSwiftVersionsDialog; class CFirstModelSetDialog; @@ -140,6 +145,9 @@ namespace BlackGui //! Preferences changed void distributorPreferencesChanged(); + //! Reduce models + void reduceModels(); + //! Default file name void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &simulator); @@ -156,15 +164,18 @@ namespace BlackGui void copyFromAnotherSwift(); //! Show the airline/aircraft matrix - void showAirlineAircraftMatrix() const; + void showModelStatistics(); //! Update distributor order void updateDistributorOrder(const BlackMisc::Simulation::CSimulatorInfo &simulator); QScopedPointer ui; QScopedPointer m_modelSetFormDialog; - QScopedPointer m_firstModelSet; - QScopedPointer m_copyFromAnotherSwift; + QScopedPointer m_firstModelSetDialog; + QScopedPointer m_reduceModelsDialog; + QScopedPointer m_copyFromAnotherSwiftDialog; + QScopedPointer m_modelStatisticsDialog; + BlackMisc::Simulation::CSimulatorInfo m_simulator; //!< currently set simulator BlackMisc::CSettingReadOnly m_distributorPreferences { this, &CDbOwnModelSetComponent::distributorPreferencesChanged }; //!< distributor preferences BlackMisc::CSettingReadOnly m_modelSettings { this }; //!< settings for models diff --git a/src/blackgui/components/dbownmodelsetcomponent.ui b/src/blackgui/components/dbownmodelsetcomponent.ui index 3af2cf4f2..b4a6b7cb6 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.ui +++ b/src/blackgui/components/dbownmodelsetcomponent.ui @@ -110,9 +110,9 @@ - + - matrix + statistics