qt5base-lts/tests
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
..
auto Long live QAIM::multiData! 2020-09-02 22:51:42 +02:00
baselineserver Use QList instead of QVector in benchmarks tests 2020-06-25 10:13:31 +02:00
benchmarks Purge qalgorithm.h of deprecated API 2020-08-28 21:22:32 +02:00
global tst_bic: Add linux-gcc-ia32 bic data for QtXml 2013-01-16 08:25:28 +01:00
libfuzzer Add ; to Q_UNUSED 2020-07-07 11:51:48 +02:00
manual Deprecate and remove uses of AA_DisableHighDpiScaling 2020-08-31 19:14:55 +02:00
shared Remove winrt 2020-06-06 20:25:49 +02:00
testserver Fix perl script warning 2020-03-19 14:15:04 +00:00
.prev_CMakeLists.txt Make standalone tests build via top level repo project 2019-11-08 15:42:32 +00:00
CMakeLists.txt CMake: Properly handle CONFIG += thread aka Threads::Threads 2020-08-06 19:15:39 +02:00
README Doc: Fix references to Qt Test 2013-01-30 01:35:06 +01:00
tests.pro Build examples and tests only if their requirements are met 2017-03-22 15:55:55 +00:00

This directory contains autotests and benchmarks based on Qt Test. In order
to run the autotests reliably, you need to configure a desktop to match the
test environment that these tests are written for.

Linux X11:

   * The user must be logged in to an active desktop; you can't run the
     autotests without a valid DISPLAY that allows X11 connections.

   * The tests are run against a KDE3 or KDE4 desktop.

   * Window manager uses "click to focus", and not "focus follows mouse". Many
     tests move the mouse cursor around and expect this to not affect focus
     and activation.

   * Disable "click to activate", i.e., when a window is opened, the window
     manager should automatically activate it (give it input focus) and not
     wait for the user to click the window.