Go to file
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
.github/workflows GitHub Actions: Fix actions build 2020-08-14 21:40:28 +02:00
bin Windows: Avoid syncqt needlessly re-generating headers 2020-08-19 12:46:09 +02:00
cmake CMake: Fix call to qt_apply_rpaths in qt_internal_add_app 2020-09-01 11:35:39 +00:00
coin CMake: Use CMAKE_AUTOGEN_VERBOSE to see moc invocations 2020-07-24 17:33:17 +02:00
config.tests CMake: Skip regeneration of manual compile test project 2020-04-09 11:26:46 +02:00
dist Remove last remainings of Qt Quick 1 imports 2020-05-25 11:48:12 +02:00
doc Doc: Fix documentation warnings for Qt GUI 2020-08-28 11:37:35 +02:00
examples Remove "fallback session management" 2020-09-01 10:16:15 +02:00
lib Purge all fonts 2015-08-18 19:59:14 +00:00
mkspecs qmake: Do not pass -mthreads to Clang 2020-08-28 12:58:04 +03:00
qmake Add a QMetaSequence interface 2020-09-01 13:35:39 +02:00
src Long live QAIM::multiData! 2020-09-02 22:51:42 +02:00
tests Long live QAIM::multiData! 2020-09-02 22:51:42 +02:00
util Use checked string iteration in case conversions 2020-08-29 18:15:27 +02:00
.cmake.conf pro2cmake.py: Generate .cmake.conf files for versioning 2020-04-30 17:44:03 +00:00
.gitattributes Update the git-archive export options 2012-09-07 15:39:31 +02:00
.gitignore Remove the QPF2 font engine 2020-08-24 07:08:45 +02:00
.lgtm.yml Skip LGTM analysis for the bootstrap library and tools 2020-07-16 01:04:34 +02:00
.prev_qt_cmdline.cmake CMake: Re-implement configure/qmake's command line handling in CMake 2020-08-17 08:08:20 +02:00
.qmake.conf Bump version 2020-02-02 13:41:14 +01:00
.tag Update the git-archive export options 2012-09-07 15:39:31 +02:00
CMakeLists.txt CMake: Fix tst_moc to build when tests are built as part of Qt tree 2020-08-23 11:04:20 +02:00
config_help.txt Make -qtlibinfix affect the names of plugins by default 2020-07-13 20:30:18 +02:00
configure CMake: Fix configure -redo on Unix 2020-08-20 17:07:09 +02:00
configure.bat CMake: Fix top-level configure 2020-07-16 15:00:37 +02:00
configure.cmake CMake: Implement configure -gdb-index 2020-08-23 11:05:01 +02:00
configure.json Remove Qt 5.1 binary-compatibility warning 2020-08-18 12:55:38 +02:00
configure.pri Treat -xplatform or -device-option as being a cross compilation 2020-07-08 19:18:09 +02:00
dependencies.yaml Re-add dependencies.yaml so repos outside qt5 can be built with Coin 2019-09-19 17:07:36 +00:00
header.BSD Use placeholder for year in header.* files 2018-04-16 11:02:22 +00:00
header.COMM Use placeholder for year in header.* files 2018-04-16 11:02:22 +00:00
header.FDL Use placeholder for year in header.* files 2018-04-16 11:02:22 +00:00
header.GPL Use placeholder for year in header.* files 2018-04-16 11:02:22 +00:00
header.GPL-EXCEPT Use placeholder for year in header.* files 2018-04-16 11:02:22 +00:00
header.LGPL Use placeholder for year in header.* files 2018-04-16 11:02:22 +00:00
header.LGPL3 Use placeholder for year in header.* files 2018-04-16 11:02:22 +00:00
header.LGPL3-COMM Use placeholder for year in header.* files 2018-04-16 11:02:22 +00:00
header.LGPL-NOGPL2 Use placeholder for year in header.* files 2018-04-16 11:02:22 +00:00
header.LGPL-ONLY Use placeholder for year in header.* files 2018-04-16 11:02:22 +00:00
header.MIT qsimd: add support for new x86 CPU features 2018-05-05 06:20:07 +00:00
INSTALL INSTALL: Remove outdated reference to Windows CE 2019-02-13 13:01:57 +00:00
LICENSE.FDL Initial import from the monolithic Qt. 2011-04-27 12:05:43 +02:00
LICENSE.GPL2 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPL3 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPL3-EXCEPT Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.LGPL3 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.LGPLv3 Remove LICENSE.GPLv3, LICENSE.LGPLv21, LGPL_EXCEPTION.txt 2018-04-16 11:02:14 +00:00
LICENSE.QT-LICENSE-AGREEMENT Update enterprise license agreement v4.2.1 2019-12-18 13:07:19 +02:00
qt_cmdline.cmake CMake: Re-implement configure/qmake's command line handling in CMake 2020-08-17 08:08:20 +02:00
qtbase.pro Update qmake before building src 2020-08-19 18:25:51 +02:00
sync.profile Remove last remaining bits of QtPlatformHeaders 2020-08-04 07:12:32 +02:00