qt5base-lts/tests/auto/corelib/itemmodels
Giuseppe D'Angelo 39e07ebf64 Long live QAIM::multiData!
Views / delegates absolutely *adore* hammering data(). A simple
QListView showing a couple of dozens entries can call data()
a hundred of times on the first show.

Back of the hand calculation,

* 2 times per visible item (sizeHint() + paint()),
* times 9 roles used by the default delegate,
* times 20 visible items

= 360 as a bare minimum, assuming the view doesn't redraw twice
accidentally. Move the mouse over the view, and that'll cause
a full update with certain styles: 360 calls to data() per update.

This has an overhead visible in profilers. The model's data()
has to re-fetch the index from its data structure and extract
the requested field every time.

Also, QVariant is used for the data interexchange,
meaning anything that won't fit in one is also a memory allocation.
This problem will likely be gone in Qt6Variant as that
will store sizeof(void*) * 3, meaning QImage/QPixmap and similar
polymorphic classes will fit in a QVariant now...

So I'm trying to to remove part of that overhead by allowing
views to request all the data they need in one go. For now,
one index a a time.

A view might also store the data returned. The idea is that
the same role on different indexes will _very likely_
return variants of the same type. So a model could move-assign
the data into the variant, avoiding the memory allocation
/deallocation for the variant's private.

This patch:

1) Introduces QModelRoleData as a holder for role+data.

2) Introduces QModelRoleDataSpan as a span over QModelRoleData.
The idea of a span type is twofold. First and foremost, we are
in no position to choose which kind of container a view should
use to store the QModelRoleData objects for a multiData() call;
a span abstracts any contiguous sequence, leaving the view free
to do whatever it wants (statically allocate, use a vector, etc.).
It also solves the problem of efficient passing the roles and
gathering the returned variants from multiData().

3) Add multiData(), which populates a span of roles for a given
model index. The main advantage here is that a model can fetch
all the needed information for a given index just once, then
iterate on the span and provide data for each requested role.
Cf. this with data(), where every call has to re-fetch
the information for the index.

A couple of models have been ported to multiData(), as well as
QStyledItemDelegate.

[ChangeLog][QtCore][QModelRoleData] New class.

[ChangeLog][QtCore][QModelRoleDataSpan] New class.

[ChangeLog][QtCore][QAbstractItemModel] Added the multiData()
function.

Change-Id: Icce0d108ad4e156c9fb05c83ce6df5f58f99f118
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-02 22:51:42 +02:00
..
qabstractitemmodel Long live QAIM::multiData! 2020-09-02 22:51:42 +02:00
qabstractproxymodel CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
qconcatenatetablesproxymodel CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
qidentityproxymodel CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
qitemmodel CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
qitemselectionmodel Automatically register data/debug stream operations in QMetaType 2020-08-24 00:17:03 +02:00
qsortfilterproxymodel_common Add missing override in tst_QSortFilterProxyModel 2020-07-29 14:33:48 +02:00
qsortfilterproxymodel_recursive CMake: Regenerate tests with new qt_ prefixed APIs 2020-07-09 09:38:35 +02:00
qsortfilterproxymodel_regularexpression Fix CaseSensitivity handling for QRegularExpression in QSortFilterProxyModel 2020-08-23 02:35:37 +02:00
qstringlistmodel Fix compiler warning in tst_qstringlistmodel 2020-07-20 09:38:58 +02:00
qtransposeproxymodel Restrict QVariant::isNull() behavior 2020-08-13 08:48:32 +02:00
CMakeLists.txt Remove QRegExp support from QSortFilterProxyModel 2020-04-15 14:38:40 +02:00
itemmodels.pro Remove QRegExp support from QSortFilterProxyModel 2020-04-15 14:38:40 +02:00