List¶
Description¶
The List object provides a generic container for storing items or references to items. When instantiated explicitely it can be used to wrap simple ECMAScript/QML value arrays to properly support partial updates (i.e. emit the dataChanged() signal for individual items). Alternatively it can contain references to other objects. If these objects have a dataChanged() signal it is forwarded to the dataChanged() signal of the list as well. Wrapping another list is possible through the reference property.
› Inherits: | Object |
---|---|
› Inherited by: | FifoBuffer |
Properties¶
count¶
This property holds the current number of items in the list. This property changes everytime the list is cleared or items are appended to the list.
› Type: | SignedInteger |
---|---|
› Signal: | countChanged() |
› Attributes: | Readonly |
items¶
This property holds a custom list of items stored as ECMAScript/QML arrays. Wrapping such arrays with a List object allows using property modifiers such as Repeater and Gather on them.
› Type: | List |
---|---|
› Signal: | itemsChanged() |
› Attributes: | Writable |
Methods¶
setItem(SignedInteger index, Variant data)¶
This method changes a single element of the custom item list. Use this method instead of writing list.items[n] = ...
in order to properly emit the dataChanged() signal.
Signals¶
changed()¶
This signal is emitted whenever the list is changed, i.e. items have been appended, changed or cleared.
dataChanged(SignedInteger index)¶
This signal is emitted when an item at index
has been updated or changed its value.
itemAppended(SignedInteger index)¶
This signal is emitted when an item has been appended to the list. The index of the newly appended item is specified through the index
parameter.
itemsCleared()¶
This signal is emitted when the list has been cleared, i.e. contains no more items.
Example¶
import InCore.Foundation 2.5
Application {
// wrap value array into List object
List {
id: list
items: [ 1, 2, 3 ]
onChanged: console.log("List items:", items)
onCountChanged: console.log("List has now", count, "items")
}
onCompleted: {
list.setItem(1, 123)
list.items = [ 2, 3, 4, 5 ];
list.items = [ "A", "B", "C" ]
}
}