From d320f590b49110dbb1af8f29dd5bc39ee90f70ed Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 27 Aug 2018 15:25:53 +0200 Subject: [PATCH] Ref T311, avoid crash of model set dialog - check for nullptr mapping component - disable new set button in dialog --- .../components/dbownmodelsetcomponent.cpp | 16 ++++++++++++---- src/blackgui/components/dbownmodelsetcomponent.h | 2 +- src/blackgui/components/dbownmodelsetdialog.cpp | 4 ++-- src/blackgui/components/dbownmodelsetdialog.h | 2 +- .../components/firstmodelsetcomponent.cpp | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/blackgui/components/dbownmodelsetcomponent.cpp b/src/blackgui/components/dbownmodelsetcomponent.cpp index 0303d3ac9..86e181d35 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.cpp +++ b/src/blackgui/components/dbownmodelsetcomponent.cpp @@ -196,9 +196,10 @@ namespace BlackGui } } - void CDbOwnModelSetComponent::enableButtons(bool firstSet) + void CDbOwnModelSetComponent::enableButtons(bool firstSet, bool newSet) { ui->pb_FirstSet->setEnabled(firstSet); + ui->pb_CreateNewSet->setEnabled(newSet); } void CDbOwnModelSetComponent::tabIndexChanged(int index) @@ -209,6 +210,8 @@ namespace BlackGui void CDbOwnModelSetComponent::buttonClicked() { const QObject *sender = QObject::sender(); + if (!sender) { return; } + if (sender == ui->pb_CreateNewSet) { this->createNewSet(); @@ -312,15 +315,20 @@ namespace BlackGui // since we use the componet also in the launcher wizard, mc might not be existing const CSimulatorInfo simulator(this->getModelSetSimulator()); CDbMappingComponent *mc = this->getMappingComponent(); - if (mc) { mc->setOwnModelsSimulator(simulator); } + if (!mc) + { + CLogMessage(this).error("No mapping component available!"); + return; + } + mc->setOwnModelsSimulator(simulator); if (!m_modelSetFormDialog) { m_modelSetFormDialog.reset(new CDbOwnModelSetFormDialog(this)); m_modelSetFormDialog->setMappingComponent(this->getMappingComponent()); } - if (this->getMappingComponent()->getOwnModelsCount() > 0) + if (mc->getOwnModelsCount() > 0) { m_modelSetFormDialog->setModal(true); m_modelSetFormDialog->reloadData(); @@ -333,7 +341,7 @@ namespace BlackGui else { const CStatusMessage m = CStatusMessage(this).error("No model data for %1") << simulator.toQString(true); - if (mc) { mc->showOverlayMessage(m); } + mc->showOverlayMessage(m); } } diff --git a/src/blackgui/components/dbownmodelsetcomponent.h b/src/blackgui/components/dbownmodelsetcomponent.h index df3f1a5b9..59db5a533 100644 --- a/src/blackgui/components/dbownmodelsetcomponent.h +++ b/src/blackgui/components/dbownmodelsetcomponent.h @@ -113,7 +113,7 @@ namespace BlackGui //! @} //! Enable buttons - void enableButtons(bool firstSet); + void enableButtons(bool firstSet, bool newSet); //! Set the model set for a given simulator void setModelSet(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator); diff --git a/src/blackgui/components/dbownmodelsetdialog.cpp b/src/blackgui/components/dbownmodelsetdialog.cpp index c9a22f0fb..5c766acca 100644 --- a/src/blackgui/components/dbownmodelsetdialog.cpp +++ b/src/blackgui/components/dbownmodelsetdialog.cpp @@ -42,9 +42,9 @@ namespace BlackGui return ui->comp_OwnModelSet; } - void CDbOwnModelSetDialog::enableButtons(bool firstSet) + void CDbOwnModelSetDialog::enableButtons(bool firstSet, bool newSet) { - ui->comp_OwnModelSet->enableButtons(firstSet); + ui->comp_OwnModelSet->enableButtons(firstSet, newSet); } } // ns } // ns diff --git a/src/blackgui/components/dbownmodelsetdialog.h b/src/blackgui/components/dbownmodelsetdialog.h index ab7270a05..12c8dabdb 100644 --- a/src/blackgui/components/dbownmodelsetdialog.h +++ b/src/blackgui/components/dbownmodelsetdialog.h @@ -45,7 +45,7 @@ namespace BlackGui CDbOwnModelSetComponent *modelSetComponent(); //! Enable buttons - void enableButtons(bool firstSet); + void enableButtons(bool firstSet, bool newSet); private: QScopedPointer ui; diff --git a/src/blackgui/components/firstmodelsetcomponent.cpp b/src/blackgui/components/firstmodelsetcomponent.cpp index 0d593a852..f0d247023 100644 --- a/src/blackgui/components/firstmodelsetcomponent.cpp +++ b/src/blackgui/components/firstmodelsetcomponent.cpp @@ -177,7 +177,7 @@ namespace BlackGui { const CSimulatorInfo simulator = ui->comp_SimulatorSelector->getValue(); m_modelSetDialog->setSimulator(simulator); - m_modelSetDialog->enableButtons(false); + m_modelSetDialog->enableButtons(false, false); m_modelSetDialog->exec(); // force UI update