DelegateModelGroup QML Type

Encapsulates a filtered set of visual data items More...

Import Statement: import QtQml.Models 2.2

Properties

Signals

  • void changed(array removed, array inserted)

Methods

  • void addGroups(int index, int count, stringlist groups)
  • void create(jsdict data, array groups)
  • void create(int index, jsdict data, array groups)
  • void create(int index)
  • object get(int index)
  • void insert(jsdict data, var groups)
  • void insert(int index, jsdict data, array groups)
  • void move(var from, var to, int count)
  • void remove(int index, int count)
  • void removeGroups(int index, int count, stringlist groups)
  • void resolve(int from, int to)
  • void setGroups(int index, int count, stringlist groups)
  • void setGroups(int index, int count, stringlist groups)

Detailed Description

The DelegateModelGroup type provides a means to address the model data of a DelegateModel's delegate items, as well as sort and filter these delegate items.

The initial set of instantiable delegate items in a DelegateModel is represented by its items group, which normally directly reflects the contents of the model assigned to DelegateModel::model. This set can be changed to the contents of any other member of DelegateModel::groups by assigning the name of that DelegateModelGroup to the DelegateModel::filterOnGroup property.

The data of an item in a DelegateModelGroup can be accessed using the get() function, which returns information about group membership and indexes as well as model data. In combination with the move() function this can be used to implement view sorting, with remove() to filter items out of a view, or with setGroups() and Package delegates to categorize items into different views.

Data from models can be supplemented by inserting data directly into a DelegateModelGroup with the insert() function. This can be used to introduce mock items into a view, or placeholder items that are later resolved to real model data when it becomes available.

Delegate items can also be instantiated directly from a DelegateModelGroup using the create() function, making it possible to use DelegateModel without an accompanying view type or to cherry-pick specific items that should be instantiated irregardless of whether they're currently within a view's visible area.

Note: This type is also available as VisualDataGroup in the Qt QML module due to compatibility reasons.

See also QML Dynamic View Ordering Tutorial.

Property Documentation

count : int

This property holds the number of items in the group.


includeByDefault : bool

This property holds whether new items are assigned to this group by default.


name : string

This property holds the name of the group.

Each group in a model must have a unique name starting with a lower case letter.


Signal Documentation

void changed(array removed, array inserted)

This signal is emitted when items have been removed from or inserted into the group.

Each object in the removed and inserted arrays has two values; the index of the first item inserted or removed and a count of the number of consecutive items inserted or removed.

Each index is adjusted for previous changes with all removed items preceding any inserted items.

The corresponding handler is onChanged.


Method Documentation

void addGroups(int index, int count, stringlist groups)

Adds count items starting at index to groups.


void create(jsdict data, array groups = undefined)

Returns a reference to the instantiated item at index in the group.

If a data object is provided it will be inserted at index and an item referencing this new entry will be returned. The optional groups parameter identifies the groups the new entry should belong to, if unspecified this is equal to the group create() was called on.

All items returned by create are added to the persistedItems group. Items in this group remain instantiated when not referenced by any view.


void create(int index, jsdict data, array groups = undefined)

Returns a reference to the instantiated item at index in the group.

If a data object is provided it will be inserted at index and an item referencing this new entry will be returned. The optional groups parameter identifies the groups the new entry should belong to, if unspecified this is equal to the group create() was called on.

All items returned by create are added to the persistedItems group. Items in this group remain instantiated when not referenced by any view.


void create(int index)

Returns a reference to the instantiated item at index in the group.

If a data object is provided it will be inserted at index and an item referencing this new entry will be returned. The optional groups parameter identifies the groups the new entry should belong to, if unspecified this is equal to the group create() was called on.

All items returned by create are added to the persistedItems group. Items in this group remain instantiated when not referenced by any view.


object get(int index)

Returns a javascript object describing the item at index in the group.

The returned object contains the same information that is available to a delegate from the DelegateModel attached as well as the model for that item. It has the properties:

  • model The model data of the item. This is the same as the model context property in a delegate
  • groups A list the of names of groups the item is a member of. This property can be written to change the item's membership.
  • inItems Whether the item belongs to the items group. Writing to this property will add or remove the item from the group.
  • itemsIndex The index of the item within the items group.
  • in<GroupName> Whether the item belongs to the dynamic group groupName. Writing to this property will add or remove the item from the group.
  • <groupName>Index The index of the item within the dynamic group groupName.
  • isUnresolved Whether the item is bound to an index in the model assigned to DelegateModel::model. Returns true if the item is not bound to the model, and false if it is.

void insert(jsdict data, var groups = undefined)

Creates a new entry at index in a DelegateModel with the values from data that correspond to roles in the model assigned to DelegateModel::model.

If no index is supplied the data is appended to the model.

The optional groups parameter identifies the groups the new entry should belong to, if unspecified this is equal to the group insert was called on.

Data inserted into a DelegateModel can later be merged with an existing entry in DelegateModel::model using the resolve() function. This can be used to create placeholder items that are later replaced by actual data.


void insert(int index, jsdict data, array groups = undefined)

Creates a new entry at index in a DelegateModel with the values from data that correspond to roles in the model assigned to DelegateModel::model.

If no index is supplied the data is appended to the model.

The optional groups parameter identifies the groups the new entry should belong to, if unspecified this is equal to the group insert was called on.

Data inserted into a DelegateModel can later be merged with an existing entry in DelegateModel::model using the resolve() function. This can be used to create placeholder items that are later replaced by actual data.


void move(var from, var to, int count)

Moves count at from in a group to a new position.


void remove(int index, int count)

Removes count items starting at index from the group.


void removeGroups(int index, int count, stringlist groups)

Removes count items starting at index from groups.


void resolve(int from, int to)

Binds an unresolved item at from to an item in DelegateModel::model at index to.

Unresolved items are entries whose data has been inserted into a DelegateModelGroup instead of being derived from a DelegateModel::model index. Resolving an item will replace the item at the target index with the unresolved item. A resolved an item will reflect the data of the source model at its bound index and will move when that index moves like any other item.

If a new item is replaced in the DelegateModelGroup onChanged() handler its insertion and replacement will be communicated to views as an atomic operation, creating the appearance that the model contents have not changed, or if the unresolved and model item are not adjacent that the previously unresolved item has simply moved.


void setGroups(int index, int count, stringlist groups)

Sets the groups count items starting at index belong to.


void setGroups(int index, int count, stringlist groups)

Sets the groups count items starting at index belong to.


© 2017 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.