From 873f5f04b9c1e9cf477d55e8596f5447900c3f01 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 29 Jan 2016 21:31:32 +0100 Subject: [PATCH] refs #587, allow to modify multiple properties at once functions to update a property map --- src/blackgui/components/dbstashcomponent.cpp | 7 ++++ src/blackgui/components/dbstashcomponent.h | 11 +++--- src/blackgui/views/aircraftmodelview.cpp | 7 ++++ src/blackgui/views/aircraftmodelview.h | 3 ++ src/blackgui/views/viewbase.cpp | 35 +++++++++++++++----- src/blackgui/views/viewbase.h | 3 ++ 6 files changed, 53 insertions(+), 13 deletions(-) diff --git a/src/blackgui/components/dbstashcomponent.cpp b/src/blackgui/components/dbstashcomponent.cpp index 18dc7714b..f1101c587 100644 --- a/src/blackgui/components/dbstashcomponent.cpp +++ b/src/blackgui/components/dbstashcomponent.cpp @@ -204,6 +204,13 @@ namespace BlackGui this->ui->tvp_StashAircraftModels->applyToSelected(distributor); } + void CDbStashComponent::applyToSelected(const CPropertyIndexVariantMap &vm) + { + if (vm.isEmpty()) { return; } + if (!this->ui->tvp_StashAircraftModels->hasSelection()) { return; } + this->ui->tvp_StashAircraftModels->applyToSelected(vm); + } + void CDbStashComponent::ps_onUnstashPressed() { this->ui->tvp_StashAircraftModels->removeSelectedRows(); diff --git a/src/blackgui/components/dbstashcomponent.h b/src/blackgui/components/dbstashcomponent.h index 877558813..46669d046 100644 --- a/src/blackgui/components/dbstashcomponent.h +++ b/src/blackgui/components/dbstashcomponent.h @@ -82,18 +82,21 @@ namespace BlackGui //! The stashed models const BlackMisc::Simulation::CAircraftModelList &getStashedModels() const; - //! Apply object to select objects + //! Apply livery to selected objects void applyToSelected(const BlackMisc::Aviation::CLivery &livery, bool acceptWarnings = true); - //! Apply object to select objects + //! Apply airline ICAO code to selected objects void applyToSelected(const BlackMisc::Aviation::CAircraftIcaoCode &icao, bool acceptWarnings = true); - //! Apply object to select objects + //! Apply aircraft ICAO code to selected objects void applyToSelected(const BlackMisc::Aviation::CAirlineIcaoCode &icao, bool acceptWarnings = true); - //! Apply object to select objects + //! Apply distributor to selected objects void applyToSelected(const BlackMisc::Simulation::CDistributor &distributor, bool acceptWarnings = true); + //! Apply set of properties to selected objects + void applyToSelected(const BlackMisc::CPropertyIndexVariantMap &vm); + //! Consolidate with other available data BlackMisc::Simulation::CAircraftModel consolidateModel(const BlackMisc::Simulation::CAircraftModel &model) const; diff --git a/src/blackgui/views/aircraftmodelview.cpp b/src/blackgui/views/aircraftmodelview.cpp index 475d2706d..9f080584d 100644 --- a/src/blackgui/views/aircraftmodelview.cpp +++ b/src/blackgui/views/aircraftmodelview.cpp @@ -91,6 +91,13 @@ namespace BlackGui return c; } + int CAircraftModelView::applyToSelected(const CPropertyIndexVariantMap &vm) + { + if (!hasSelection()) { return 0; } + int c = this->updateSelected(vm); + return c; + } + bool CAircraftModelView::hasSelectedModelsToStash() const { return m_menus.testFlag(MenuCanStashModels) && hasSelection(); diff --git a/src/blackgui/views/aircraftmodelview.h b/src/blackgui/views/aircraftmodelview.h index 3af718955..58050eaf6 100644 --- a/src/blackgui/views/aircraftmodelview.h +++ b/src/blackgui/views/aircraftmodelview.h @@ -43,6 +43,9 @@ namespace BlackGui //! Apply to selected objects int applyToSelected(const BlackMisc::Simulation::CDistributor &distributor); + //! Apply to selected objects + int applyToSelected(const BlackMisc::CPropertyIndexVariantMap &vm); + //! Has any models to stash and it is allowed to stash bool hasSelectedModelsToStash() const; diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index 04bf74a06..74ee9b509 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -731,21 +731,31 @@ namespace BlackGui } template - int CViewBase::updateSelected(const CVariant &variant, const CPropertyIndex &index) + int CViewBase::updateSelected(const CPropertyIndexVariantMap &vm) { + if (vm.isEmpty()) { return 0; } if (!hasSelection()) { return 0; } - QModelIndexList indexes = this->selectedRows(); int c = 0; - int lastRow = -1; - int firstRow = -1; + + QModelIndexList indexes = this->selectedRows(); + int lastUpdatedRow = -1; + int firstUpdatedRow = -1; + const CPropertyIndexList pis(vm.indexes()); for (const QModelIndex &i : indexes) { - if (i.row() == lastRow) { continue; } - lastRow = i.row(); - if (firstRow < 0 || lastRow < firstRow) { firstRow = lastRow; } + if (i.row() == lastUpdatedRow) { continue; } + lastUpdatedRow = i.row(); + if (firstUpdatedRow < 0 || lastUpdatedRow < firstUpdatedRow) { firstUpdatedRow = lastUpdatedRow; } ObjectType obj(this->at(i)); - obj.setPropertyByIndex(variant, index); + + // update all properties in map + for (const CPropertyIndex &pi : pis) + { + obj.setPropertyByIndex(vm.value(pi), pi); + } + + // and update container if (this->derivedModel()->setInContainer(i, obj)) { c++; @@ -754,11 +764,18 @@ namespace BlackGui if (c > 0) { - this->derivedModel()->sendDataChanged(firstRow, lastRow); + this->derivedModel()->sendDataChanged(firstUpdatedRow, lastUpdatedRow); } return c; } + template + int CViewBase::updateSelected(const CVariant &variant, const CPropertyIndex &index) + { + const CPropertyIndexVariantMap vm(index, variant); + return this->updateSelected(vm); + } + template ObjectType CViewBase::selectedObject() const { diff --git a/src/blackgui/views/viewbase.h b/src/blackgui/views/viewbase.h index 74b943390..a8a4fa716 100644 --- a/src/blackgui/views/viewbase.h +++ b/src/blackgui/views/viewbase.h @@ -434,6 +434,9 @@ namespace BlackGui //! Update selected objects int updateSelected(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index); + //! Update selected objects + int updateSelected(const BlackMisc::CPropertyIndexVariantMap &vm); + //! Selected object (or default) ObjectType selectedObject() const;