1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5 \qmltype ItemSelectionModel
6 \instantiates QItemSelectionModel
7 \inqmlmodule QtQml.Models
9 \ingroup qtquick-models
11 \brief Instantiates a QItemSelectionModel to be used in conjunction
12 with a QAbstractItemModel and any view supporting it.
14 \sa QItemSelectionModel, {Models and Views in Qt Quick}
19 \qmlproperty QAbstractItemModel ItemSelectionModel::model
21 This property's value must match the view's model.
25 \qmlproperty bool ItemSelectionModel::hasSelection
28 It will trigger property binding updates every time \l selectionChanged()
29 is emitted, even though its value hasn't changed.
31 \sa selection, selectedIndexes, select(), selectionChanged()
35 \qmlproperty QModelIndex ItemSelectionModel::currentIndex
38 Use \l setCurrentIndex() to set its value.
40 \sa setCurrentIndex(), currentChanged()
44 \qmlproperty QModelIndexList ItemSelectionModel::selectedIndexes
47 Contains the list of all the indexes in the selection model.
51 \qmlmethod bool ItemSelectionModel::isSelected(QModelIndex index)
53 Returns \c true if the given model item \a index is selected.
57 \qmlmethod bool ItemSelectionModel::isRowSelected(int row, QModelIndex parent)
59 Returns \c true if all items are selected in the \a row with the given
62 Note that this function is usually faster than calling isSelected()
63 on all items in the same row, and that unselectable items are ignored.
67 \qmlmethod bool ItemSelectionModel::isColumnSelected(int column, QModelIndex parent)
69 Returns \c true if all items are selected in the \a column with the given
72 Note that this function is usually faster than calling isSelected()
73 on all items in the same column, and that unselectable items are ignored.
77 \qmlmethod bool ItemSelectionModel::rowIntersectsSelection(int row, QModelIndex parent)
79 Returns \c true if there are any items selected in the \a row with the
84 \qmlmethod bool ItemSelectionModel::columnIntersectsSelection(int column, QModelIndex parent)
86 Returns \c true if there are any items selected in the \a column with the
91 \qmlmethod QModelIndexList ItemSelectionModel::selectedRows(int column)
93 Returns the indexes in the given \a column for the rows where all columns
100 \qmlmethod QModelIndexList ItemSelectionModel::selectedColumns(int row)
102 Returns the indexes in the given \a row for columns where all rows are
109 \qmlproperty object ItemSelectionModel::selection
112 Holds the selection ranges stored in the selection model.
116 \qmlmethod void ItemSelectionModel::setCurrentIndex(QModelIndex index, SelectionFlags command)
118 Sets the model item \a index to be the current item, and emits
119 currentChanged(). The current item is used for keyboard navigation and
120 focus indication; it is independent of any selected items, although a
121 selected item can also be the current item.
123 Depending on the specified \a command, the \a index can also become part
124 of the current selection.
126 Valid \a command values are described in \l {itemselectionmodelselectindex}
127 {select(\e index, \e command)}.
133 \qmlmethod void ItemSelectionModel::select(QModelIndex index, SelectionFlags command)
134 \keyword itemselectionmodelselectindex
136 Selects the model item \a index using the specified \a command, and emits
139 Valid values for the \a command parameter, are:
141 \value NoUpdate No selection will be made.
142 \value Clear The complete selection will be cleared.
143 \value Select All specified indexes will be selected.
144 \value Deselect All specified indexes will be deselected.
145 \value Toggle All specified indexes will be selected or
146 deselected depending on their current state.
147 \value Current The current selection will be updated.
148 \value Rows All indexes will be expanded to span rows.
149 \value Columns All indexes will be expanded to span columns.
150 \value SelectCurrent A combination of Select and Current, provided for
152 \value ToggleCurrent A combination of Toggle and Current, provided for
154 \value ClearAndSelect A combination of Clear and Select, provided for
159 \qmlmethod void ItemSelectionModel::select(QItemSelection selection, SelectionFlags command)
161 Selects the item \a selection using the specified \a command, and emits
164 Valid \a command values are described in \l {itemselectionmodelselectindex}
165 {select(\e index, \e command)}.
169 \qmlmethod void ItemSelectionModel::clear()
171 Clears the selection model. Emits selectionChanged() and currentChanged().
175 \qmlmethod void ItemSelectionModel::reset()
177 Clears the selection model. Does not emit any signals.
181 \qmlmethod void ItemSelectionModel::clearSelection()
183 Clears the selection in the selection model. Emits selectionChanged().
187 \qmlmethod void ItemSelectionModel::clearCurrentIndex()
189 Clears the current index. Emits currentChanged().
193 \qmlsignal ItemSelectionModel::selectionChanged(QItemSelection selected, QItemSelection deselected)
195 This signal is emitted whenever the selection changes. The change in the
196 selection is represented as an item selection of \a deselected items and
197 an item selection of \a selected items.
199 Note the that the current index changes independently from the selection.
200 Also note that this signal will not be emitted when the item model is reset.
202 \sa select(), currentChanged()
206 \qmlsignal ItemSelectionModel::currentChanged(QModelIndex current, QModelIndex previous)
208 This signal is emitted whenever the current item changes. The \a previous
209 model item index is replaced by the \a current index as the selection's
212 Note that this signal will not be emitted when the item model is reset.
214 \sa currentIndex, setCurrentIndex(), selectionChanged()