qt5base-lts/tests/auto/corelib
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
..
animation Use a custom QAnimationDriver to take control over time 2017-12-02 19:58:30 +00:00
codecs Replace Q_DECL_OVERRIDE with override where possible 2017-09-19 11:53:42 +00:00
global Tests: Raise minimum supported MSVC version to 2015 2018-01-04 20:23:25 +00:00
io Merge remote-tracking branch 'origin/5.10' into dev 2018-01-04 19:49:26 +01:00
itemmodels Introduce QAbstractItemModel::checkIndex() 2018-01-08 09:41:53 +00:00
json Improve symmetry of variant json conversions 2017-07-25 09:00:46 +00:00
kernel Tests: Raise minimum supported MSVC version to 2015 2018-01-04 20:23:25 +00:00
mimetypes QMimeDatabase: only export var for unittests if QT_BUILD_INTERNAL 2018-01-02 09:31:37 +00:00
plugin Remove spurious execute permissions 2017-12-08 13:27:42 +00:00
statemachine Merge remote-tracking branch 'origin/5.10' into dev 2018-01-02 09:58:44 +01:00
thread Tests: Raise minimum supported MSVC version to 2015 2018-01-04 20:23:25 +00:00
tools QStringBuilder: add support for QStringView 2018-01-08 09:41:43 +00:00
xml QXmlStreamWriter: Avoid writing invalid characters 2017-09-13 07:29:00 +00:00
corelib.pro Add support for Apple tvOS 2016-05-17 16:11:23 +00:00