Ref T298, exclude models

This commit is contained in:
Klaus Basan
2018-08-23 17:49:15 +02:00
parent 5b7ec38b0a
commit 109c1554f9
2 changed files with 19 additions and 25 deletions

View File

@@ -48,7 +48,7 @@ namespace BlackMisc
//! Max.key value (making sense with integer key) //! Max.key value (making sense with integer key)
KEYTYPE getMaxKey(bool *ok = nullptr) const; KEYTYPE getMaxKey(bool *ok = nullptr) const;
//! Remove objects with key //! Remove objects with keys
int removeObjectsWithKeys(const QSet<KEYTYPE> &keys); int removeObjectsWithKeys(const QSet<KEYTYPE> &keys);
//! Remove objects without key //! Remove objects without key

View File

@@ -523,39 +523,33 @@ namespace BlackMisc
int CAircraftModelList::removeAllWithoutModelString() int CAircraftModelList::removeAllWithoutModelString()
{ {
if (this->isEmpty()) { return 0; } if (this->isEmpty()) { return 0; }
int c = 0; const int s = this->size();
for (auto it = this->begin(); it != this->end();) CAircraftModelList withModelStr;
for (const CAircraftModel &model : *this)
{ {
if (it->hasModelString()) if (!model.hasModelString()) { continue; }
{ withModelStr.push_back(model);
++it;
} }
else const int diff = s - withModelStr.size();
{ if (diff < 1) { return 0; }
c++; *this = withModelStr;
it = this->erase(it); return diff;
}
}
return c;
} }
int CAircraftModelList::removeIfExcluded() int CAircraftModelList::removeIfExcluded()
{ {
if (this->isEmpty()) { return 0; } if (this->isEmpty()) { return 0; }
int c = 0; const int s = this->size();
for (auto it = this->begin(); it != this->end();) CAircraftModelList onlyIncluded;
for (const CAircraftModel &model : *this)
{ {
if (it->getModelMode() != CAircraftModel::Exclude) if (model.getModelMode() == CAircraftModel::Exclude) { continue; }
{ onlyIncluded.push_back(model);
++it;
} }
else const int diff = s - onlyIncluded.size();
{ if (diff < 1) { return 0; }
c++; *this = onlyIncluded;
it = this->erase(it); return diff;
}
}
return c;
} }
int CAircraftModelList::replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity) int CAircraftModelList::replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity)