ListView、GridView、TableView继承QAbstractTableModel、QAbstractListModel等的目的是什么
What's the purpose of inheriting QAbstractTableModel, QAbstractListModel, etc. for ListView, GridView and TableView
我可以在 ListView
、GridView
和 TableView
和 add/edit/remove 项中显示 QObject
的简单 QVector, QList,
等in/from 那些 View
。对我来说,使用 QVector, QList,
等 QObject*
是实现最终目标的最简单方法。继承QAbstractTableModel
、QAbstractListModel
等的真正好处是什么?在 WPF 中,我们有 VirtualizingStackPanel
和一些属性来提高此类 View
的性能。继承那些 Abstract..Model
是否有相同的目的或任何一种方式(继承或使用普通 QVector/QList
),性能是否相同?
QAbstractItemModel 和子类的优点主要是在处理较大列表时提高了性能,并通过使用代理模型提高了灵活性:
部分更新:模型可以告诉视图单行或行范围是 inserted, moved, removed or updated,然后视图可以以比丢弃和重建所有内容更聪明的方式采取行动。例如,在 10k 个其他项目中间插入一个项目的成本很便宜。
更低的开销:一个大的列表,比如说,50k QObject*s 会有很大的开销,无论是对象本身的成本还是处理所有 signal/slot 连接的开销属性 更新。
模型可以充当现有数据结构的适配器,而不需要将所有数据保存在模型中(尽管这在实践中可能很棘手,以保证 correctness/consistency)
延迟加载:模型可以在用户浏览视图时按需加载数据,而无需所有数据都可用(参见 fetchMore()/canFetchMore())。
通过代理的灵活性:QAbstractProxyModel and subclasses (in particular, QSortFilterProxyModel) allow stacking of models to filter/sort/modify the data in the original model. With QSortFilterProxyModel sorting and filtering is usually much simpler to implement (and without changing the original data/model) than implementing it manually for a QList. Simple modifications like changing the returned data for a certain role can be implemented by subclassing QIdentityProxyModel.
更复杂的数据结构:QAbstractItemModel 还允许树(尽管实现起来很棘手)和表。这些在 "traditional"(基于 QWidget 的)桌面 UI 中比在 embedded/mobile 触摸 UI 中更常用。
我可以在 ListView
、GridView
和 TableView
和 add/edit/remove 项中显示 QObject
的简单 QVector, QList,
等in/from 那些 View
。对我来说,使用 QVector, QList,
等 QObject*
是实现最终目标的最简单方法。继承QAbstractTableModel
、QAbstractListModel
等的真正好处是什么?在 WPF 中,我们有 VirtualizingStackPanel
和一些属性来提高此类 View
的性能。继承那些 Abstract..Model
是否有相同的目的或任何一种方式(继承或使用普通 QVector/QList
),性能是否相同?
QAbstractItemModel 和子类的优点主要是在处理较大列表时提高了性能,并通过使用代理模型提高了灵活性:
部分更新:模型可以告诉视图单行或行范围是 inserted, moved, removed or updated,然后视图可以以比丢弃和重建所有内容更聪明的方式采取行动。例如,在 10k 个其他项目中间插入一个项目的成本很便宜。
更低的开销:一个大的列表,比如说,50k QObject*s 会有很大的开销,无论是对象本身的成本还是处理所有 signal/slot 连接的开销属性 更新。
模型可以充当现有数据结构的适配器,而不需要将所有数据保存在模型中(尽管这在实践中可能很棘手,以保证 correctness/consistency)
延迟加载:模型可以在用户浏览视图时按需加载数据,而无需所有数据都可用(参见 fetchMore()/canFetchMore())。
通过代理的灵活性:QAbstractProxyModel and subclasses (in particular, QSortFilterProxyModel) allow stacking of models to filter/sort/modify the data in the original model. With QSortFilterProxyModel sorting and filtering is usually much simpler to implement (and without changing the original data/model) than implementing it manually for a QList. Simple modifications like changing the returned data for a certain role can be implemented by subclassing QIdentityProxyModel.
更复杂的数据结构:QAbstractItemModel 还允许树(尽管实现起来很棘手)和表。这些在 "traditional"(基于 QWidget 的)桌面 UI 中比在 embedded/mobile 触摸 UI 中更常用。