From 109c1554f959e9f3166263af9b79a164f5095d2c Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 23 Aug 2018 17:49:15 +0200 Subject: [PATCH] Ref T298, exclude models --- src/blackmisc/db/datastoreobjectlist.h | 2 +- .../simulation/aircraftmodellist.cpp | 42 ++++++++----------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/blackmisc/db/datastoreobjectlist.h b/src/blackmisc/db/datastoreobjectlist.h index 3684e48d4..9a604b343 100644 --- a/src/blackmisc/db/datastoreobjectlist.h +++ b/src/blackmisc/db/datastoreobjectlist.h @@ -48,7 +48,7 @@ namespace BlackMisc //! Max.key value (making sense with integer key) KEYTYPE getMaxKey(bool *ok = nullptr) const; - //! Remove objects with key + //! Remove objects with keys int removeObjectsWithKeys(const QSet &keys); //! Remove objects without key diff --git a/src/blackmisc/simulation/aircraftmodellist.cpp b/src/blackmisc/simulation/aircraftmodellist.cpp index 8068c5c77..6f091651f 100644 --- a/src/blackmisc/simulation/aircraftmodellist.cpp +++ b/src/blackmisc/simulation/aircraftmodellist.cpp @@ -523,39 +523,33 @@ namespace BlackMisc int CAircraftModelList::removeAllWithoutModelString() { if (this->isEmpty()) { return 0; } - int c = 0; - for (auto it = this->begin(); it != this->end();) + const int s = this->size(); + CAircraftModelList withModelStr; + for (const CAircraftModel &model : *this) { - if (it->hasModelString()) - { - ++it; - } - else - { - c++; - it = this->erase(it); - } + if (!model.hasModelString()) { continue; } + withModelStr.push_back(model); } - return c; + const int diff = s - withModelStr.size(); + if (diff < 1) { return 0; } + *this = withModelStr; + return diff; } int CAircraftModelList::removeIfExcluded() { if (this->isEmpty()) { return 0; } - int c = 0; - for (auto it = this->begin(); it != this->end();) + const int s = this->size(); + CAircraftModelList onlyIncluded; + for (const CAircraftModel &model : *this) { - if (it->getModelMode() != CAircraftModel::Exclude) - { - ++it; - } - else - { - c++; - it = this->erase(it); - } + if (model.getModelMode() == CAircraftModel::Exclude) { continue; } + onlyIncluded.push_back(model); } - return c; + const int diff = s - onlyIncluded.size(); + if (diff < 1) { return 0; } + *this = onlyIncluded; + return diff; } int CAircraftModelList::replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity)