By changing the model (adding or subtracting or editing a member of the model), the repeater removes all the created items (delegates) and rebuilds them again. For heavy models, this is a big problem.
How can I change the repeater, so that instead of removing all delegates, it only deletes the item related to the deleted member, and when a member is added, it creates only the item related to it, and in case of editing a member of the model, only that member is removed and recreated.
I studied the code related to the Repeater, but due to the use of private methods and classes in its source, I cannot reimplement it.
You can test the problem with the bellow code:
import QtQuick
import QtQuick.Controls
Window {
width: 640
height: 480
visible: true
title: qsTr("Ronia Components")
property var repeatreModel: [1, 2]
Timer {
interval: 2000
running: true
repeat: true
property int count: 0
onTriggered: {
count++;
// Add an item into ,odel
repeatreModel.push(count);
}
}
Column {
anchors.fill: parent
Repeater {
id: repeater
model: repeatreModel
clip: true
onItemRemoved: (item, index) => {
console.log("Remove : (item, index) ", item, index)
}
onItemAdded: (item, index) => {
console.log("Add : (item, index) = ", item, index)
}
delegate: Rectangle {
width: 50
height: 40
Text {
id: name
anchors.centerIn: parent
text: modelData
}
}
onModelChanged: console.log("modelChanged")
}
}
}
SMR said:
Based on that, I figured out one of the possible solutions:
Note:
I do not to want change the model, because my model is used a lot in the software, and needs drastic changes.