qt5base-lts/tests/auto/corelib/itemmodels
Giuseppe D'Angelo 33c88f86b5 QAbstractProxyModel: do not access invalid indexes
QAbstractProxyModel::headerData tries to do the "smart" thing and
map sections in the proxy to sections in the source. However there's
no "mapSectionToSource" virtual. Instead, to map horizontal headers, the
code builds a proxy index at row 0 and section N, maps it to the source,
and finds out which source column it gets mapped to. (Same story
for the vertical headers).

... in general this can obviously fail, say you've got a "horizontal
scrambling" proxy model, but in the common case this is OK.

Except, if the proxy is empty (e.g. 0 rows or columns). In this case,
it asks for an illegal index, and if you reimplemented index() yourself
(which you must, since it's a pure virtual in QAPM) and you do bounds
checking, you'll not be pleased at the result.

This turns out to be a massive API liability. To fix this somehow properly,
we can decide that empty models don't get the section remapped (easy).
Less easy is the fact that, when the model does get some data, we have to
emit headerDataChanged() otherwise the views will get broken. So add
this logic too.

Note that QAPM does not normally forward any source model's signal -- a
subclass has to connect to them and handle them explicitly. That's
*another* API liability, all over the place -- data(), headerData(),
flags(), etc.

What I mean by this is that one can create a valid QAPM (by implementing
its pure virtuals) that however is immediately broken by the convenience
that QAPM provides for the rest (data(), headerData(), etc.).

This commit doesn't try and change this in any way, but I'm less and
less convinced of the usefulness of QAPM in its current shape.

Change-Id: I45a8c2139f2c1917ffbf429910fdb92f005f4feb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: David Faure <david.faure@kdab.com>
2022-04-13 18:08:38 +02:00
..
qabstractitemmodel Make sure QMimeData is fully declared 2021-01-11 16:57:41 +01:00
qabstractproxymodel QAbstractProxyModel: do not access invalid indexes 2022-04-13 18:08:38 +02:00
qconcatenatetablesproxymodel emit layoutAboutToBeChanged timely 2021-07-20 21:27:27 +01:00
qidentityproxymodel Make QAbstractProxyModel itemData() behave like data() 2021-11-26 17:12:07 +00:00
qitemmodel tst_QItemModel: fix memleaks 2022-01-05 08:22:00 +01:00
qitemselectionmodel Consistent handling of disabled items in QItemSelectionModel 2021-07-15 18:09:12 +02:00
qsortfilterproxymodel Fix test to pass with QT_FORCE_ASSERTS 2022-02-18 18:55:38 +01:00
qsortfilterproxymodel_recursive Shorten target name for qsortfilterproxymodel auto tests 2021-11-29 08:08:21 +01:00
qsortfilterproxymodel_regularexpression Shorten target name for qsortfilterproxymodel auto tests 2021-11-29 08:08:21 +01:00
qstringlistmodel emit layoutAboutToBeChanged timely 2021-07-20 21:27:27 +01:00
qtransposeproxymodel emit layoutAboutToBeChanged timely 2021-07-20 21:27:27 +01:00
CMakeLists.txt Untangle qsortfilterproxymodel unittests 2021-10-01 18:30:25 +02:00