From f3ac18257f4e3a79d94dfc878837b6948da58952 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 6 May 2016 18:16:47 +0200 Subject: [PATCH] Update editor data when stashed data are modified (e.g. by drag and drop) This issue was discovered during testing for #640 --- .../components/dbmappingcomponent.cpp | 60 +++++++++++++++---- src/blackgui/components/dbmappingcomponent.h | 28 +++++---- src/blackgui/components/dbstashcomponent.cpp | 6 ++ src/blackgui/components/dbstashcomponent.h | 3 + src/blackgui/editors/aircrafticaoform.cpp | 5 +- src/blackgui/editors/aircrafticaoform.h | 2 +- src/blackgui/editors/distributorform.cpp | 6 +- src/blackgui/editors/distributorform.h | 2 +- src/blackgui/editors/liveryform.cpp | 5 +- src/blackgui/editors/liveryform.h | 2 +- 10 files changed, 87 insertions(+), 32 deletions(-) diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index c26bd02cf..2a6ee89fc 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -68,25 +68,25 @@ namespace BlackGui connect(ui->editor_Model, &CModelMappingForm::requestStash, this, &CDbMappingComponent::ps_stashCurrentModel); connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); - connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onOwnModelsCountChanged); + connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onOwnModelsChanged); 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->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onStashCountChanged); + connect(ui->comp_StashAircraft->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onStashedModelsDataChanged); 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->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onModelSetCountChanged); + connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onModelSetChanged); connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, this, &CDbMappingComponent::ps_tabIndexChanged); connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, ui->comp_ModelMatcher , &CModelMatcherComponent::tabIndexChanged); connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); // initial values - this->ps_onModelSetCountChanged(ui->comp_OwnModelSet->view()->rowCount(), ui->comp_OwnModelSet->view()->hasFilter()); - this->ps_onStashCountChanged(ui->comp_StashAircraft->view()->rowCount(), ui->comp_StashAircraft->view()->hasFilter()); + this->ps_onModelSetChanged(ui->comp_OwnModelSet->view()->rowCount(), ui->comp_OwnModelSet->view()->hasFilter()); + this->ps_onStashedModelsDataChanged(ui->comp_StashAircraft->view()->rowCount(), ui->comp_StashAircraft->view()->hasFilter()); // how to display forms ui->editor_AircraftIcao->setSelectOnly(); @@ -120,7 +120,7 @@ namespace BlackGui { this->m_vPilot1stInit = false; connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); - connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onVPilotCountChanged); + connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::modelDataChanged, this, &CDbMappingComponent::ps_onVPilotDataChanged); connect(&m_vPilotReader, &CVPilotRulesReader::readFinished, this, &CDbMappingComponent::ps_onLoadVPilotDataFinished); connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels); connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged); @@ -142,7 +142,7 @@ namespace BlackGui { // create / restore tab this->ui->tw_ModelsToBeMapped->addTab(this->ui->tab_VPilot, tabName); - this->ps_onVPilotCountChanged( + this->ps_onVPilotDataChanged( this->ui->tvp_AircraftModelsForVPilot->rowCount(), this->ui->tvp_AircraftModelsForVPilot->hasFilter()); } @@ -227,6 +227,41 @@ namespace BlackGui return this->ui->tw_ModelsToBeMapped->tabText(i); } + void CDbMappingComponent::updateEditorsWhenApplicable() + { + const CAircraftModel currentEditorModel(ui->editor_Model->getValue()); + if (!currentEditorModel.hasModelString()) { return; } // no related model + const QString modelString(currentEditorModel.getModelString()); + const CAircraftModel currentStashedModel(ui->comp_StashAircraft->getStashedModel(modelString)); + if (!currentStashedModel.hasModelString()) { return; } + + // we have found a model in the stashed models and this is the one currently displayed + // in the editors + bool updated = false; + const CLivery stashedLivery(currentStashedModel.getLivery()); + if (stashedLivery.hasValidDbKey()) + { + if (ui->editor_Livery->setValue(stashedLivery)) { updated = true; } + } + + const CDistributor stashedDistributor(currentStashedModel.getDistributor()); + if (stashedDistributor.hasValidDbKey()) + { + if (ui->editor_Distributor->setValue(stashedDistributor)) { updated = true; } + } + + const CAircraftIcaoCode stashedIcaoCode(currentStashedModel.getAircraftIcaoCode()); + if (stashedIcaoCode.hasValidDbKey()) + { + if (ui->editor_AircraftIcao->setValue(stashedIcaoCode)) { updated = true; } + } + + if (updated) + { + CLogMessage(this).info("Updated editor data for '%1'") << modelString; + } + } + CAircraftModelList CDbMappingComponent::getSelectedModelsToStash() const { if (!hasSelectedModelsToStash()) { return CAircraftModelList(); } @@ -516,7 +551,7 @@ namespace BlackGui emit this->requestUpdatedData(CEntityFlags::ModelEntity); } - void CDbMappingComponent::ps_onVPilotCountChanged(int count, bool withFilter) + void CDbMappingComponent::ps_onVPilotDataChanged(int count, bool withFilter) { Q_UNUSED(count); Q_UNUSED(withFilter); @@ -527,7 +562,7 @@ namespace BlackGui this->ui->tw_ModelsToBeMapped->setTabText(i, o); } - void CDbMappingComponent::ps_onOwnModelsCountChanged(int count, bool withFilter) + void CDbMappingComponent::ps_onOwnModelsChanged(int count, bool withFilter) { Q_UNUSED(count); Q_UNUSED(withFilter); @@ -592,7 +627,7 @@ namespace BlackGui Q_UNUSED(selectedItem); } - void CDbMappingComponent::ps_onStashCountChanged(int count, bool withFilter) + void CDbMappingComponent::ps_onStashedModelsDataChanged(int count, bool withFilter) { Q_UNUSED(count); Q_UNUSED(withFilter); @@ -601,9 +636,12 @@ namespace BlackGui 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); + + // update editors + this->updateEditorsWhenApplicable(); } - void CDbMappingComponent::ps_onModelSetCountChanged(int count, bool withFilter) + void CDbMappingComponent::ps_onModelSetChanged(int count, bool withFilter) { Q_UNUSED(count); Q_UNUSED(withFilter); diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index c7233e0c3..6496f1274 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -169,6 +169,9 @@ namespace BlackGui void ps_digestStashedModelsChanged(); private slots: + //! Tab index changed + void ps_tabIndexChanged(int index); + //! Load the vPilot rules void ps_loadVPilotData(); @@ -178,6 +181,9 @@ namespace BlackGui //! vPilot cached models changed void ps_onVPilotCacheChanged(); + //! vPilot data changed + void ps_onVPilotDataChanged(int count, bool withFilter); + //! Request update of vPilot data void ps_requestVPilotDataUpdate(); @@ -187,8 +193,8 @@ namespace BlackGui //! Stashed models changed void ps_onStashedModelsChangedDigest(); - //! Tab index changed - void ps_tabIndexChanged(int index); + //! Stash has been changed + void ps_onStashedModelsDataChanged(int count, bool withFilter); //! Models have been published successfully void ps_onModelsSuccessfullyPublished(const BlackMisc::Simulation::CAircraftModelList &models); @@ -196,14 +202,11 @@ namespace BlackGui //! Stash drop request void ps_handleStashDropRequest(const BlackMisc::Aviation::CAirlineIcaoCode &code) const; - //! Row count for vPilot data changed - void ps_onVPilotCountChanged(int count, bool withFilter); + //! Model set has been changed + void ps_onModelSetChanged(int count, bool withFilter); - //! 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); + //! Own models have been changed + void ps_onOwnModelsChanged(int count, bool withFilter); //! Row has been selected void ps_onModelRowSelected(const QModelIndex &index); @@ -229,9 +232,6 @@ namespace BlackGui //! Open model modify dialog void ps_modifyModelDialog(); - //! Own models have been changed - void ps_onOwnModelsCountChanged(int count, bool withFilter); - //! Add to own model set void ps_addToOwnModelSet(); @@ -255,7 +255,6 @@ namespace BlackGui bool m_withVPilot = false; //!< use vPilot extensions bool m_autoFilterInDbViews = false; //!< automatically filter the DB view by the current model - //! Init vPilot if rights and suitable void initVPilotLoading(); @@ -265,6 +264,9 @@ namespace BlackGui //! Current tab text QString currentTabText() const; + //! Data have been changed and the editor data might need an update + void updateEditorsWhenApplicable(); + // -------------------- component specific menus -------------------------- //! The menu for loading and handling VPilot rules for mapping tasks diff --git a/src/blackgui/components/dbstashcomponent.cpp b/src/blackgui/components/dbstashcomponent.cpp index bf6f12192..fc395bdaf 100644 --- a/src/blackgui/components/dbstashcomponent.cpp +++ b/src/blackgui/components/dbstashcomponent.cpp @@ -150,6 +150,12 @@ namespace BlackGui return this->ui->tvp_StashAircraftModels->derivedModel()->container(); } + CAircraftModel CDbStashComponent::getStashedModel(const QString &modelString) const + { + if (modelString.isEmpty() || ui->tvp_StashAircraftModels->isEmpty()) { return CAircraftModel(); } + return ui->tvp_StashAircraftModels->container().findFirstByModelStringOrDefault(modelString); + } + void CDbStashComponent::applyToSelected(const CLivery &livery, bool acceptWarnings) { if (!this->ui->tvp_StashAircraftModels->hasSelection()) { return; } diff --git a/src/blackgui/components/dbstashcomponent.h b/src/blackgui/components/dbstashcomponent.h index f516fd4d9..1e9bbbb7d 100644 --- a/src/blackgui/components/dbstashcomponent.h +++ b/src/blackgui/components/dbstashcomponent.h @@ -74,6 +74,9 @@ namespace BlackGui //! The stashed models const BlackMisc::Simulation::CAircraftModelList &getStashedModels() const; + //! Model for model string + Simulation::CAircraftModel getStashedModel(const QString &modelString) const; + //! Apply livery to selected objects void applyToSelected(const BlackMisc::Aviation::CLivery &livery, bool acceptWarnings = true); diff --git a/src/blackgui/editors/aircrafticaoform.cpp b/src/blackgui/editors/aircrafticaoform.cpp index f95033792..94444162b 100644 --- a/src/blackgui/editors/aircrafticaoform.cpp +++ b/src/blackgui/editors/aircrafticaoform.cpp @@ -42,9 +42,9 @@ namespace BlackGui CAircraftIcaoForm::~CAircraftIcaoForm() { } - void CAircraftIcaoForm::setValue(const BlackMisc::Aviation::CAircraftIcaoCode &icao) + bool CAircraftIcaoForm::setValue(const BlackMisc::Aviation::CAircraftIcaoCode &icao) { - if (icao == this->m_originalCode) { return; } + if (icao == this->m_originalCode) { return false; } this->m_originalCode = icao; this->ui->le_Id->setText(icao.getDbKeyAsString()); @@ -65,6 +65,7 @@ namespace BlackGui CGuiUtility::setComboBoxValueByStartingString(this->ui->cb_Wtc, wtc, "unspecified"); this->ui->le_Updated->setText(icao.getFormattedUtcTimestampYmdhms()); + return true; } CAircraftIcaoCode CAircraftIcaoForm::getValue() const diff --git a/src/blackgui/editors/aircrafticaoform.h b/src/blackgui/editors/aircrafticaoform.h index 58cdce1b2..0176e3a69 100644 --- a/src/blackgui/editors/aircrafticaoform.h +++ b/src/blackgui/editors/aircrafticaoform.h @@ -62,7 +62,7 @@ namespace BlackGui public slots: //! Set value - void setValue(const BlackMisc::Aviation::CAircraftIcaoCode &icao); + bool setValue(const BlackMisc::Aviation::CAircraftIcaoCode &icao); private slots: //! Variant has been dropped diff --git a/src/blackgui/editors/distributorform.cpp b/src/blackgui/editors/distributorform.cpp index a68edc8dd..50960830b 100644 --- a/src/blackgui/editors/distributorform.cpp +++ b/src/blackgui/editors/distributorform.cpp @@ -39,13 +39,17 @@ namespace BlackGui CDistributorForm::~CDistributorForm() { } - void CDistributorForm::setValue(const BlackMisc::Simulation::CDistributor &distributor) + bool CDistributorForm::setValue(const BlackMisc::Simulation::CDistributor &distributor) { + const CDistributor currentDistributor(this->getValue()); + if (currentDistributor == distributor) { return false; } + this->ui->distributor_Selector->setDistributor(distributor); this->ui->le_Description->setText(distributor.getDescription()); this->ui->le_Alias1->setText(distributor.getAlias1()); this->ui->le_Alias2->setText(distributor.getAlias2()); this->ui->le_Updated->setText(distributor.getFormattedUtcTimestampYmdhms()); + return true; } CDistributor CDistributorForm::getValue() const diff --git a/src/blackgui/editors/distributorform.h b/src/blackgui/editors/distributorform.h index 526b780bc..2e2a107b5 100644 --- a/src/blackgui/editors/distributorform.h +++ b/src/blackgui/editors/distributorform.h @@ -62,7 +62,7 @@ namespace BlackGui public slots: //! Set value - void setValue(const BlackMisc::Simulation::CDistributor &distributor = BlackMisc::Simulation::CDistributor()); + bool setValue(const BlackMisc::Simulation::CDistributor &distributor = BlackMisc::Simulation::CDistributor()); private slots: //! Variant has been dropped diff --git a/src/blackgui/editors/liveryform.cpp b/src/blackgui/editors/liveryform.cpp index 7c636e3c0..9e1e54c8d 100644 --- a/src/blackgui/editors/liveryform.cpp +++ b/src/blackgui/editors/liveryform.cpp @@ -67,9 +67,9 @@ namespace BlackGui return this->ui->editor_AirlineIcao->getValue(); } - void CLiveryForm::setValue(const CLivery &livery) + bool CLiveryForm::setValue(const CLivery &livery) { - if (this->m_originalLivery == livery) { return; } + if (this->m_originalLivery == livery) { return false; } this->m_originalLivery = livery; this->ui->comp_LiverySelector->setLivery(livery); @@ -88,6 +88,7 @@ namespace BlackGui { this->ui->editor_AirlineIcao->setValue(livery.getAirlineIcaoCode()); } + return true; } CStatusMessageList CLiveryForm::validate(bool withNestedForms) const diff --git a/src/blackgui/editors/liveryform.h b/src/blackgui/editors/liveryform.h index d6166f540..c0f7537f7 100644 --- a/src/blackgui/editors/liveryform.h +++ b/src/blackgui/editors/liveryform.h @@ -67,7 +67,7 @@ namespace BlackGui public slots: //! Value - void setValue(const BlackMisc::Aviation::CLivery &livery); + bool setValue(const BlackMisc::Aviation::CLivery &livery); private slots: //! Livery dropped