mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-12 07:15:34 +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:
@@ -143,6 +143,16 @@ namespace BlackGui
|
|||||||
return this->removeModelsWithModelString(models.getModelStrings(), sensitivity);
|
return this->removeModelsWithModelString(models.getModelStrings(), sensitivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CAircraftModelView::replaceOrAddModelsWithString(const CAircraftModelList &models, Qt::CaseSensitivity sensitivity)
|
||||||
|
{
|
||||||
|
if (models.isEmpty()) { return 0; }
|
||||||
|
CAircraftModelList copy(this->container());
|
||||||
|
int c = copy.replaceOrAddModelsWithString(models, sensitivity);
|
||||||
|
if (c == 0) { return 0; }
|
||||||
|
this->updateContainerMaybeAsync(copy);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
void CAircraftModelView::setHighlightModelStrings(const QStringList &highlightModels)
|
void CAircraftModelView::setHighlightModelStrings(const QStringList &highlightModels)
|
||||||
{
|
{
|
||||||
this->derivedModel()->setHighlightModelStrings(highlightModels);
|
this->derivedModel()->setHighlightModelStrings(highlightModels);
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ namespace BlackGui
|
|||||||
//! Remove models with model strings
|
//! Remove models with model strings
|
||||||
int removeModelsWithModelString(const BlackMisc::Simulation::CAircraftModelList &models, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive);
|
int removeModelsWithModelString(const BlackMisc::Simulation::CAircraftModelList &models, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive);
|
||||||
|
|
||||||
|
//! Replace models with sme model string, otherwise add
|
||||||
|
int replaceOrAddModelsWithString(const BlackMisc::Simulation::CAircraftModelList &models, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive);
|
||||||
|
|
||||||
//! \copydoc BlackGui::Models::CAircraftModelListModel::setHighlightModelStrings(const QStringList &)
|
//! \copydoc BlackGui::Models::CAircraftModelListModel::setHighlightModelStrings(const QStringList &)
|
||||||
void setHighlightModelStrings(const QStringList &highlightModels);
|
void setHighlightModelStrings(const QStringList &highlightModels);
|
||||||
|
|
||||||
|
|||||||
@@ -122,10 +122,10 @@ namespace BlackMisc
|
|||||||
CONTAINER newValues(this->container());
|
CONTAINER newValues(this->container());
|
||||||
const QList<KEYTYPE> keys(container.toDbKeyList());
|
const QList<KEYTYPE> keys(container.toDbKeyList());
|
||||||
newValues.removeObjectsWithKeys(keys);
|
newValues.removeObjectsWithKeys(keys);
|
||||||
|
int removeSize = newValues.size(); // size after removing data
|
||||||
newValues.push_back(container);
|
newValues.push_back(container);
|
||||||
int delta = newValues.size() - this->container().size();
|
|
||||||
this->container() = newValues;
|
this->container() = newValues;
|
||||||
return delta;
|
return newValues.size() - removeSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class OBJ, class CONTAINER, typename KEYTYPE>
|
template <class OBJ, class CONTAINER, typename KEYTYPE>
|
||||||
|
|||||||
@@ -160,6 +160,23 @@ namespace BlackMisc
|
|||||||
return d;
|
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
|
CAircraftModelList CAircraftModelList::findModelsStartingWith(const QString &modelString, Qt::CaseSensitivity sensitivity) const
|
||||||
{
|
{
|
||||||
return this->findBy([ = ](const CAircraftModel & model)
|
return this->findBy([ = ](const CAircraftModel & model)
|
||||||
|
|||||||
@@ -92,6 +92,10 @@ namespace BlackMisc
|
|||||||
//! \return number of elements removed
|
//! \return number of elements removed
|
||||||
int removeModelsWithString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity);
|
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
|
//! Model strings
|
||||||
QStringList getModelStrings(bool sort = true) const;
|
QStringList getModelStrings(bool sort = true) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user