mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
refs #618, allow to update/add models based on model string
* functionality in list * access via view * fixed count for changed objects in datastoreobjectlist (now detects replacements)
This commit is contained in:
@@ -122,10 +122,10 @@ namespace BlackMisc
|
||||
CONTAINER newValues(this->container());
|
||||
const QList<KEYTYPE> keys(container.toDbKeyList());
|
||||
newValues.removeObjectsWithKeys(keys);
|
||||
int removeSize = newValues.size(); // size after removing data
|
||||
newValues.push_back(container);
|
||||
int delta = newValues.size() - this->container().size();
|
||||
this->container() = newValues;
|
||||
return delta;
|
||||
return newValues.size() - removeSize;
|
||||
}
|
||||
|
||||
template <class OBJ, class CONTAINER, typename KEYTYPE>
|
||||
|
||||
@@ -160,6 +160,23 @@ namespace BlackMisc
|
||||
return d;
|
||||
}
|
||||
|
||||
int CAircraftModelList::replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity)
|
||||
{
|
||||
if (addOrReplaceList.isEmpty()) { return 0; }
|
||||
if (this->isEmpty())
|
||||
{
|
||||
*this = addOrReplaceList;
|
||||
return addOrReplaceList.size();
|
||||
}
|
||||
CAircraftModelList newModels(*this);
|
||||
const QStringList keys(addOrReplaceList.getModelStrings(false));
|
||||
newModels.removeModelsWithString(keys, sensitivity);
|
||||
int removed = newModels.size(); // size after removing
|
||||
newModels.push_back(addOrReplaceList);
|
||||
*this = newModels;
|
||||
return this->size() - removed;
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::findModelsStartingWith(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
||||
{
|
||||
return this->findBy([ = ](const CAircraftModel & model)
|
||||
|
||||
@@ -92,6 +92,10 @@ namespace BlackMisc
|
||||
//! \return number of elements removed
|
||||
int removeModelsWithString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity);
|
||||
|
||||
//! Replace or add based on model string
|
||||
//! \return number of elements removed
|
||||
int replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity);
|
||||
|
||||
//! Model strings
|
||||
QStringList getModelStrings(bool sort = true) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user