![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qitemselectionmodel.h>
Static Public Member Functions | |
static Q_CORE_EXPORT void | split (const QItemSelectionRange &range, const QItemSelectionRange &other, QItemSelection *result) |
Splits the selection range using the selection other range. | |
![]() | |
static QList< QItemSelectionRange > | fromList (const QList< QItemSelectionRange > &list) noexcept |
static QList< QItemSelectionRange > | fromVector (const QList< QItemSelectionRange > &vector) noexcept |
static QList< QItemSelectionRange > | fromReadOnlyData (const QItemSelectionRange(&t)[N]) noexcept |
\inmodule QtCore
The QItemSelection class manages information about selected items in a model.
A QItemSelection describes the items in a model that have been selected by the user. A QItemSelection is basically a list of selection ranges, see QItemSelectionRange. It provides functions for creating and manipulating selections, and selecting a range of items from a model.
The QItemSelection class is one of the \l{Model/View Classes} and is part of Qt's \l{Model/View Programming}{model/view framework}.
An item selection can be constructed and initialized to contain a range of items from an existing model. The following example constructs a selection that contains a range of items from the given model
, beginning at the topLeft
, and ending at the bottomRight
.
An empty item selection can be constructed, and later populated as required. So, if the model is going to be unavailable when we construct the item selection, we can rewrite the above code in the following way:
QItemSelection saves memory, and avoids unnecessary work, by working with selection ranges rather than recording the model item index for each item in the selection. Generally, an instance of this class will contain a list of non-overlapping selection ranges.
Use merge() to merge one item selection into another without making overlapping ranges. Use split() to split one selection range into smaller ranges based on a another selection range.
Definition at line 181 of file qitemselectionmodel.h.
QItemSelection::QItemSelection | ( | const QModelIndex & | topLeft, |
const QModelIndex & | bottomRight | ||
) |
Constructs an empty selection.
Constructs an item selection that extends from the top-left model item, specified by the topLeft index, to the bottom-right item, specified by bottomRight.
Definition at line 375 of file qitemselectionmodel.cpp.
References select().
bool QItemSelection::contains | ( | const QModelIndex & | index | ) | const |
Returns true
if the selection contains the given index; otherwise returns false
.
Definition at line 415 of file qitemselectionmodel.cpp.
References QList< QItemSelectionRange >::begin(), QList< QItemSelectionRange >::end(), isSelectableAndEnabled(), and it.
QModelIndexList QItemSelection::indexes | ( | ) | const |
Returns a list of model indexes that correspond to the selected items.
Definition at line 430 of file qitemselectionmodel.cpp.
Referenced by QCompleterPrivate::_q_completionSelected(), QTreeWidgetPrivate::_q_selectionChanged(), QAbstractItemViewPrivate::clearOrRemove(), QAbstractProxyModel::mapSelectionFromSource(), QAbstractProxyModel::mapSelectionToSource(), QItemSelectionModel::selectedIndexes(), QListView::selectionChanged(), QTableView::selectionChanged(), QTreeView::selectionChanged(), QQuickTableViewPrivate::selectionChangedInSelectionModel(), and MainWindow::updateSelection().
void QItemSelection::merge | ( | const QItemSelection & | other, |
QItemSelectionModel::SelectionFlags | command | ||
) |
Merges the other selection with this QItemSelection using the command given.
This method guarantees that no ranges are overlapping.
Note that only QItemSelectionModel::Select, QItemSelectionModel::Deselect, and QItemSelectionModel::Toggle are supported.
Definition at line 453 of file qitemselectionmodel.cpp.
References QList< T >::append(), QList< T >::at(), at, QItemSelectionModel::Deselect, i, QItemSelectionRange::intersects(), QList< QItemSelectionRange >::operator+=(), other(), QList< T >::push_back(), QList< QItemSelectionRange >::removeAt(), QList< T >::removeAt(), QList< T >::reserve(), QItemSelectionModel::Select, QList< T >::size(), QList< QItemSelectionRange >::size(), split(), and QItemSelectionModel::Toggle.
Referenced by QItemSelectionModel::columnIntersectsSelection(), QItemSelectionModelPrivate::expandSelection(), QItemSelectionModel::hasSelection(), QItemSelectionModel::rowIntersectsSelection(), QItemSelectionModel::select(), QItemSelectionModel::selectedIndexes(), QItemSelectionModel::selection(), and QListView::setSelection().
void QItemSelection::select | ( | const QModelIndex & | topLeft, |
const QModelIndex & | bottomRight | ||
) |
Adds the items in the range that extends from the top-left model item, specified by the topLeft index, to the bottom-right item, specified by bottomRight to the list.
Definition at line 387 of file qitemselectionmodel.cpp.
References QList< QItemSelectionRange >::append(), QModelIndex::column(), QModelIndex::isValid(), QModelIndex::model(), QModelIndex::parent(), qMax(), qMin(), qWarning, QModelIndex::row(), and QModelIndex::sibling().
Referenced by QItemSelection(), main(), QListViewPrivate::selection(), and QListView::setSelection().
|
static |
Splits the selection range using the selection other range.
Removes all items in other from range and puts the result in result. This can be compared with the semantics of the subtract operation of a set.
Definition at line 507 of file qitemselectionmodel.cpp.
References QAbstractTableModel::index(), model, other(), parent, and Q_ASSERT.
Referenced by QItemSelectionModelPrivate::_q_rowsAboutToBeRemoved(), QItemSelectionModel::emitSelectionChanged(), and merge().