1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5 \page qmodelindex-and-related-classes-in-qml.html
6 \title QModelIndex and related Classes in QML
8 Since Qt 5.5, QModelIndex and QPersistentModelIndex are exposed in QML as
9 value-based types. Also exposed in a similar fashion are QModelIndexList,
10 QItemSelectionRange and QItemSelection. All objects from these types can
11 be passed back and forth between QML and C++ as \c var properties or plain
14 Below you will find an overview of the API exposed to QML for these classes.
15 For more information, refer to their C++ documentation.
17 \note Since all these types are exposed as \l{Q_GADGET}{gadgets}, there are no property
18 change notification signals emitted. Therefore binding to their properties
19 may not give the expected results. This is especially true for QPersistentModelIndex.
21 \section1 QModelIndex and QPersistentModelIndex Types
26 \li \b parent : QModelIndex
28 \li \b model : QAbstractItemModel
29 \li \b internalId : quint64
32 All these properties are read-only, as are their C++ counterparts.
34 \note The usual caveats apply to QModelIndex in QML. If the underlying model changes
35 or gets deleted, it may become dangerous to access its properties. Therefore, you
36 should not store any QModelIndex objects. You can, however, store QPersistentModelIndexe
37 objects in a safe way.
39 \section1 QModelIndexList Type
41 QModelIndexList is exposed in QML as a JavaScript array. Conversions are
42 automatically made from and to C++. In fact, any JavaScript array can be
43 converted back to QModelIndexList, with non-QModelIndex objects replaced by
44 invalid \l{QModelIndex}es.
46 \note QModelIndex to QPersistentModelIndex conversion happens when accessing
47 the array elements because any QModelIndexList property retains reference
48 semantics when exposed this way.
50 \section1 \l QItemSelectionRange Type
59 \li \b topLeft : QPersistentModelIndex
60 \li \b bottomRight : QPersistentModelIndex
61 \li \b parent : QModelIndex
64 \li \b model : QAbstractItemModel
67 All these properties are read-only, as are their C++ counterparts. In addition,
68 we also expose the following functions:
71 \li bool \b{contains}(QModelIndex \e index)
72 \li bool \b{contains}(int \e row, int \e column, QModelIndex \e parentIndex)
73 \li bool \b{intersects}(QItemSelectionRange \e other)
74 \li QItemSelectionRange \b{intersected}(QItemSelectionRange \e other)
77 \section1 QItemSelection Type
79 Similarly to QModelIndexList, \l QItemSelection is exposed in QML as a JavaScript
80 array of QItemSelectionRange objects. Conversions are automatically made from and to C++.
81 In fact, any JavaScript array can be converted back to QItemSelection, with
82 non-QItemSelectionRange objects replaced by empty \l {QItemSelectionRange}s.
85 \sa ItemSelectionModel