import Quickshell ScriptModel is a QML Data Model that generates model operations based on changes to a javascript expression attached to values.
ScriptModel should be used when you would otherwise use a javascript expression as a model, QAbstractItemModel is accepted, and the data is likely to change over the lifetime of the program.
When directly using a javascript expression as a model, types like Repeater or ListView will destroy all created delegates, and re-create the entire list. In the case of ListView this will also prevent animations from working. If you wrap your expression with ScriptModel, only new items will be created, and ListView animations will work as expected.
// Will cause all delegates to be re-created every time filterText changes.
Repeater {
model: myList.filter(entry => entry.name.startsWith(filterText))
delegate: // ...
}
// Will add and remove delegates only when required.
Repeater {
model: ScriptModel {
values: myList.filter(entry => entry.name.startsWith(filterText))
}
delegate: // ...
}The property that javascript objects passed into the model will be compared with.
For example, if objectProp is "myprop" then { myprop: "a", other: "y" } and
{ myprop: "a", other: "z" } will be considered equal.
Defaults to "", meaning no key.
How values should be compared. Defaults to ObjectComparison.Structure.
Identity based comparison is faster if usable for a given model, and often achievable with objectProp.