.. _object_List: :index:`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 :ref:`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 :ref:`dataChanged() ` signal of the list as well. Wrapping another list is possible through the :ref:`reference ` property. :**› Inherits**: :ref:`Object ` :**› Inherited by**: :ref:`FifoBuffer ` Overview ******** Properties ++++++++++ .. hlist:: :columns: 1 * :ref:`count ` * :ref:`items ` * :ref:`reference ` * :ref:`Object.objectId ` * :ref:`Object.parent ` Methods +++++++ .. hlist:: :columns: 1 * :ref:`setItem() ` * :ref:`Object.deserializeProperties() ` * :ref:`Object.fromJson() ` * :ref:`Object.serializeProperties() ` * :ref:`Object.toJson() ` Signals +++++++ .. hlist:: :columns: 1 * :ref:`changed() ` * :ref:`dataChanged() ` * :ref:`itemAppended() ` * :ref:`itemsCleared() ` * :ref:`objectAppended() ` * :ref:`Object.completed() ` Properties ********** .. _property_List_count: .. _signal_List_countChanged: .. index:: single: count 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 .. _property_List_items: .. _signal_List_itemsChanged: .. index:: single: items items +++++ This property holds a custom list of items stored as ECMAScript/QML arrays. Wrapping such arrays with a :ref:`List ` object allows using :ref:`property modifiers ` such as :ref:`Repeater ` and :ref:`Gather ` on them. :**› Type**: List :**› Signal**: itemsChanged() :**› Attributes**: Writable .. _property_List_reference: .. _signal_List_referenceChanged: .. index:: single: reference reference +++++++++ This property holds a reference to a another :ref:`List ` object. This makes this list behave exactly as the referenced list. This is usually only required when using :ref:`Gather ` to flatten hierarchical object lists. :**› Type**: ListReference :**› Signal**: referenceChanged() :**› Attributes**: Writable Methods ******* .. _method_List_setItem: .. index:: single: setItem setItem(SignedInteger index, Variant data) ++++++++++++++++++++++++++++++++++++++++++ This method changes a single element of the :ref:`custom item list `. Use this method instead of writing ``list.items[n] = ...`` in order to properly emit the :ref:`dataChanged() ` signal. Signals ******* .. _signal_List_changed: .. index:: single: changed changed() +++++++++ This signal is emitted whenever the list is changed, i.e. items have been appended, changed or cleared. .. _signal_List_dataChanged: .. index:: single: dataChanged dataChanged(SignedInteger index) ++++++++++++++++++++++++++++++++ This signal is emitted when an item at ``index`` has been updated or changed its value. .. _signal_List_itemAppended: .. index:: single: itemAppended 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. .. _signal_List_itemsCleared: .. index:: single: itemsCleared itemsCleared() ++++++++++++++ This signal is emitted when the list has been cleared, i.e. contains no more items. .. _signal_List_objectAppended: .. index:: single: objectAppended objectAppended(:ref:`Object ` object) ++++++++++++++++++++++++++++++++++++++++++++++++++++ This signal is emitted when an item of type :ref:`Object ` or an inheriting object has been appended to the list. This special case is primarily used for internal purposes. .. _example_List: Example ******* .. code-block:: qml 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" ] } }