qt5base-lts/tests/auto/corelib/itemmodels
Giuseppe D'Angelo 69496d4e22 Introduce QAbstractItemModel::checkIndex()
When implementing a custom model there's the habit, in each and every
function that takes a QModelIndex, to carefully checking the index
passed by the caller. This index is checked for "legality" (*): does the
index belong to this model, is the index pointing to an existing row and
column, and so on.  These checks are hand-rolled and, as such, slightly
different and possibly incomplete (i.e. wrong) every time.

What's worse, these checks are implemented via "ordinary" code (if
statements). However, passing an illegal index to a QAIM function is a
precondition violation, and as such does not (and must not) be
checked in ordinary conditions, as it triggers undefined behavior. On
the other hand, while debugging a custom model or a custom hierarchy
of (proxy) models, having such checks in place can be a significant
aid.

Enter checkIndex(): a debugging helper for QAbstractItemModel and its
subclasses. checkIndex() centralizes the checks for legality of a
given index. User code is free to assert on it, or have some other
fallback mechanism in case a check fails.

(*) Using "legality" here instead of "validity" in order to avoid
confusion between QModelIndex::isValid() and what checkIndex() really
does.

[ChangeLog][QtCore][QAbstractItemModel] Added
QAbstractItemModel::checkIndex(), a debugging function for
QAbstractItemModel subclasses.

Change-Id: I1eea0586b1ac3ededdbfbf46759145022dc5ad86
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Reviewed-by: David Faure <david.faure@kdab.com>
2018-01-08 09:41:53 +00:00
..
qabstractitemmodel Introduce QAbstractItemModel::checkIndex() 2018-01-08 09:41:53 +00:00
qabstractproxymodel Updated license headers 2016-01-21 18:55:18 +00:00
qidentityproxymodel tst_qidentityproxymodel: map the index to the source model 2017-09-15 13:52:10 +00:00
qitemmodel tst_qitemmodel: do not pass illegal indices to QAbstractItemModel APIs 2017-11-24 18:23:37 +00:00
qitemselectionmodel Fix missing handling of columns when merging selection ranges 2017-05-09 13:46:51 +00:00
qsortfilterproxymodel QSortFilterProxyModel: Clear persistent indexes on source model change 2017-11-30 17:29:33 +00:00
qsortfilterproxymodel_recursive Fix naming of new property QSortFilterProxyModel::recursiveFiltering 2017-11-28 18:41:09 +00:00
qstringlistmodel tst_qstringlistmodel: remove an invalid test 2017-11-24 18:23:40 +00:00
itemmodels.pro Merge remote-tracking branch 'origin/5.9' into dev 2017-03-28 09:28:31 +02:00