aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/util
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-06-06 10:57:37 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2018-07-30 13:10:02 +0000
commitcadae7a431a831a30963e1973bef9dfc8896061d (patch)
tree23dab64dfff0559a7f1e985f8152cf1db44da740 /src/qml/util
parentb65acdda3be6f71e54011b439a84235da060c1bb (diff)
QQmlAdaptorModel: prepare js list models for recycling support
This patch will enable delegate item recycling for js list models. So if you e.g set "model: [1, 2, 3, 4]" on a TableView, the delegates can be recycled. The patch will override the notify function. This function is called from QQmlDelegateModel whenever the modelData that the delegate item depends on, changes. This again is needed to trigger all the modelData bindings in the item to update. Note that this function will only be used for recycling items. The model classes don't listen for changes done to js list models, meaning that the function will otherwise never be called (which is why it was never implemented, I guess). Auto testing this will be included with the patches that implements delegate recycling for TableView. Change-Id: I49185bdbaaacc3ccbd94c99cc66d9a1998452f68 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/qml/util')
-rw-r--r--src/qml/util/qqmladaptormodel.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/qml/util/qqmladaptormodel.cpp b/src/qml/util/qqmladaptormodel.cpp
index 32bf43159a..e460c376da 100644
--- a/src/qml/util/qqmladaptormodel.cpp
+++ b/src/qml/util/qqmladaptormodel.cpp
@@ -566,10 +566,11 @@ public:
void setModelData(const QVariant &data)
{
- if (index == -1 && data != cachedData) {
- cachedData = data;
- emit modelDataChanged();
- }
+ if (data == cachedData)
+ return;
+
+ cachedData = data;
+ emit modelDataChanged();
}
static QV4::ReturnedValue get_modelData(const QV4::FunctionObject *b, const QV4::Value *thisObject, const QV4::Value *, int)
@@ -666,6 +667,20 @@ public:
index, row, column,
index >= 0 && index < model.list.count() ? model.list.at(index) : QVariant());
}
+
+ bool notify(const QQmlAdaptorModel &model, const QList<QQmlDelegateModelItem *> &items, int index, int count, const QVector<int> &) const override
+ {
+ for (auto modelItem : items) {
+ const int modelItemIndex = modelItem->index;
+ if (modelItemIndex < index || modelItemIndex >= index + count)
+ continue;
+
+ auto listModelItem = static_cast<QQmlDMListAccessorData *>(modelItem);
+ QVariant updatedModelData = model.list.at(listModelItem->index);
+ listModelItem->setModelData(updatedModelData);
+ }
+ return true;
+ }
};
//-----------------------------------------------------------------