DelegateModelGroup QML Type

封装经过筛选的可视化数据项集。更多

Import Statement: import QtQml.Models

属性

信号

  • changed(array removed, array inserted)

方法

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

详细描述

DelegateModelGroup 类型提供了一种方法来处理DelegateModel 的委托项的模型数据,以及对这些委托项进行排序和过滤。

DelegateModel 中可实例化的委托项的初始集由items 组表示,该组通常直接反映分配给DelegateModel::model 的模型内容。通过将该 DelegateModelGroup 的name 分配给DelegateModel::filterOnGroup 属性,可将该组更改为DelegateModel::groups 的任何其他成员的内容。

可以使用get() 函数访问 DelegateModelGroup 中项目的数据,该函数会返回有关组成员和索引以及模型数据的信息。结合move() 函数,可使用remove() 实现视图排序,将项目从视图中过滤出来,或使用setGroups() 和Package 委托将项目分类到不同的视图中。不同的组只有在互不关联的情况下才能独立排序。移动一个组中的项目也会移动它所属的所有其他组。

可以使用insert() 函数将数据直接插入 DelegateModelGroup,从而补充模型中的数据。这可用于在视图中引入模拟项或占位符项,当真正的模型数据可用时,resolved

委托项目也可以使用create() 函数直接从 DelegateModelGroup 实例化,这样就可以在没有附带视图类型的情况下使用DelegateModel ,或挑选应被实例化的特定项目,而不管它们当前是否在视图的可见区域内。

另请参阅 《QML 动态视图排序教程》

属性文档

count : int [read-only]

此属性表示组中项目的数量。


includeByDefault : bool

该属性显示新项目是否默认分配给该组。


name : string

该属性显示组的名称。

模型中的每个组必须有一个以小写字母开头的唯一名称。


信号文档

changed(array removed, array inserted)

当项目从组移出或插入组时,将发出该信号。

removedinserted 数组中的每个对象都有两个值:第一个插入或移除项的索引,以及连续插入或移除项的计数

每个索引都会根据之前的更改进行调整,所有移除的项目都在任何插入的项目之前。

注: 相应的处理程序是onChanged


方法文档

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

insert(jsdict data, var groups = undefined)

DelegateModel 中的index 处创建一个新条目,其中包含data 中与分配给DelegateModel::model 的模型中的角色相对应的值。

如果没有提供索引,数据将附加到模型中。

可选的groups 参数用于确定新条目所属的组,如果未指定,则等于插入时调用的组。

插入DelegateModel 的数据随后可以使用resolve() 函数与DelegateModel::model 中的现有条目合并。这可用于创建占位项,随后由实际数据取代。


create(int index)

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

create(jsdict data, array groups = undefined)

返回组中index 的实例化项目的引用。

如果提供了data 对象,它将被inserted ,地址为index ,并将返回一个引用该新条目的项目。可选的groups 参数用于确定新条目所属的组,如果未指定,则等于调用create() 的组。

创建返回的所有条目都将添加到persistedItems 组。该组中的项目在未被任何视图引用时保持实例化。


addGroups(int index, int count, stringlist groups)

将从index 开始的count 项目添加到groups


object get(int index)

返回一个 javascript 对象,描述组中位于index 的项目。

返回的对象包含的信息与DelegateModel 附加给代表的信息以及该项目模型相同。它具有以下属性

  • 模型项目的模型数据。这与委托中的模型上下文属性相同
  • groups项目所属组的名称列表。可以写入此属性来更改项目的成员身份。
  • inItems项目是否属于items 组。写入此属性将从组中添加或删除项目。
  • itemsIndex items 组中项目的索引。
  • in<GroupName>项目是否属于动态组groupName。向该属性写入内容将从组中添加或删除项目。
  • <groupName>Index项目在动态组groupName 中的索引。
  • isUnresolved项目是否与分配给DelegateModel::model 的模型中的索引绑定。如果项目未绑定到模型,则返回 true;如果绑定到模型,则返回 false。

move(var from, var to, int count)

count 在组to 中的from 移动到一个新位置。

注意: DelegateModel 充当代理模型:它持有委托的顺序与underlying model 持有委托的顺序不同。对底层模型的任何后续更改都不会撤销您通过此函数进行的重新排序。


remove(int index, int count)

index 开始删除count 项目。


removeGroups(int index, int count, stringlist groups)

groups 删除从index 开始的count 项目。


resolve(int from, int to)

from 中的未解决项与DelegateModel::model 中索引为to 的项绑定。

未解决项是指数据被insertedDelegateModelGroup ,而不是来自DelegateModel::model 索引的条目。解决项目将用未解决项目替换目标索引中的项目。已解决的项将在其绑定索引中反映源模型的数据,并在该索引移动时像其他项一样移动。

如果在DelegateModelGroup onChanged() 处理程序中替换了新项目,则其插入和替换将作为原子操作传达给视图,从而造成模型内容未发生变化的假象,或者如果未解决项目和模型项目不相邻,则先前未解决项目只是发生了移动。


setGroups(int index, int count, stringlist groups)

index 开始更改count 项目的组成员资格。这些项目将从现有组中删除,并添加到groups 中。


© 2025 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.