Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QItemSelection Class Reference

\inmodule QtCore More...

#include <qitemselectionmodel.h>

+ Inheritance diagram for QItemSelection:
+ Collaboration diagram for QItemSelection:

Public Member Functions

Q_CORE_EXPORT QItemSelection (const QModelIndex &topLeft, const QModelIndex &bottomRight)
 Constructs an empty selection.
 
Q_CORE_EXPORT void 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.
 
Q_CORE_EXPORT bool contains (const QModelIndex &index) const
 Returns true if the selection contains the given index; otherwise returns false.
 
Q_CORE_EXPORT QModelIndexList indexes () const
 Returns a list of model indexes that correspond to the selected items.
 
Q_CORE_EXPORT void merge (const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
 Merges the other selection with this QItemSelection using the command given.
 
- Public Member Functions inherited from QList< QItemSelectionRange >
 QList (DataPointer dd) noexcept
 
 QList ()=default
 
 QList (qsizetype size)
 
 QList (qsizetype size, parameter_type t)
 
 QList (std::initializer_list< QItemSelectionRange > args)
 
 QList (InputIterator i1, InputIterator i2)
 
 QList (const String &str)
 
 QList (qsizetype size, Qt::Initialization)
 
QList< QItemSelectionRange > & operator= (std::initializer_list< QItemSelectionRange > args)
 
void swap (QList &other) noexcept
 
QTypeTraits::compare_eq_result_container< QList, U > operator== (const QList &other) const
 
QTypeTraits::compare_eq_result_container< QList, U > operator!= (const QList &other) const
 
QTypeTraits::compare_lt_result_container< QList, U > operator< (const QList &other) const noexcept(noexcept(std::lexicographical_compare< typename QList< U >::const_iterator, typename QList::const_iterator >(std::declval< QList< U > >().begin(), std::declval< QList< U > >().end(), other.begin(), other.end())))
 
QTypeTraits::compare_lt_result_container< QList, U > operator> (const QList &other) const noexcept(noexcept(other< std::declval< QList< U > >()))
 
QTypeTraits::compare_lt_result_container< QList, U > operator<= (const QList &other) const noexcept(noexcept(other< std::declval< QList< U > >()))
 
QTypeTraits::compare_lt_result_container< QList, U > operator>= (const QList &other) const noexcept(noexcept(std::declval< QList< U > >()< other))
 
qsizetype size () const noexcept
 
qsizetype count () const noexcept
 
qsizetype count (const AT &t) const noexcept
 
qsizetype length () const noexcept
 
bool isEmpty () const noexcept
 
void resize (qsizetype size)
 
void resize (qsizetype size, parameter_type c)
 
void resizeForOverwrite (qsizetype size)
 
qsizetype capacity () const
 
void reserve (qsizetype size)
 
void squeeze ()
 
void detach ()
 
bool isDetached () const noexcept
 
bool isSharedWith (const QList< QItemSelectionRange > &other) const
 
pointer data ()
 
const_pointer data () const noexcept
 
const_pointer constData () const noexcept
 
void clear ()
 
const_reference at (qsizetype i) const noexcept
 
reference operator[] (qsizetype i)
 
const_reference operator[] (qsizetype i) const noexcept
 
void append (parameter_type t)
 
void append (const_iterator i1, const_iterator i2)
 
void append (rvalue_ref t)
 
void append (const QList< QItemSelectionRange > &l)
 
void append (QList< QItemSelectionRange > &&l)
 
void prepend (rvalue_ref t)
 
void prepend (parameter_type t)
 
reference emplaceBack (Args &&... args)
 
reference emplaceFront (Args &&... args)
 
iterator insert (qsizetype i, parameter_type t)
 
iterator insert (qsizetype i, qsizetype n, parameter_type t)
 
iterator insert (const_iterator before, parameter_type t)
 
iterator insert (const_iterator before, qsizetype n, parameter_type t)
 
iterator insert (const_iterator before, rvalue_ref t)
 
iterator insert (qsizetype i, rvalue_ref t)
 
QListassign (qsizetype n, parameter_type t)
 
QListassign (InputIterator first, InputIterator last)
 
QListassign (std::initializer_list< QItemSelectionRange > l)
 
iterator emplace (const_iterator before, Args &&... args)
 
iterator emplace (qsizetype i, Args &&... args)
 
void replace (qsizetype i, parameter_type t)
 
void replace (qsizetype i, rvalue_ref t)
 
void remove (qsizetype i, qsizetype n=1)
 
void removeFirst () noexcept
 
void removeLast () noexcept
 
value_type takeFirst ()
 
value_type takeLast ()
 
QList< QItemSelectionRange > & fill (parameter_type t, qsizetype size=-1)
 
void removeAt (qsizetype i)
 
qsizetype removeAll (const AT &t)
 
bool removeOne (const AT &t)
 
qsizetype removeIf (Predicate pred)
 
QItemSelectionRange takeAt (qsizetype i)
 
void move (qsizetype from, qsizetype to)
 
iterator begin ()
 
const_iterator begin () const noexcept
 
iterator end ()
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
const_iterator constBegin () const noexcept
 
const_iterator constEnd () const noexcept
 
reverse_iterator rbegin ()
 
const_reverse_iterator rbegin () const noexcept
 
reverse_iterator rend ()
 
const_reverse_iterator rend () const noexcept
 
const_reverse_iterator crbegin () const noexcept
 
const_reverse_iterator crend () const noexcept
 
iterator erase (const_iterator begin, const_iterator end)
 
iterator erase (const_iterator pos)
 
QItemSelectionRangefirst ()
 
const QItemSelectionRangefirst () const noexcept
 
QList< QItemSelectionRangefirst (qsizetype n) const
 
const QItemSelectionRangeconstFirst () const noexcept
 
QItemSelectionRangelast ()
 
const QItemSelectionRangelast () const noexcept
 
QList< QItemSelectionRangelast (qsizetype n) const
 
const QItemSelectionRangeconstLast () const noexcept
 
bool startsWith (parameter_type t) const
 
bool endsWith (parameter_type t) const
 
QList< QItemSelectionRangemid (qsizetype pos, qsizetype len=-1) const
 
QList< QItemSelectionRangesliced (qsizetype pos) const
 
QList< QItemSelectionRangesliced (qsizetype pos, qsizetype n) const
 
QItemSelectionRange value (qsizetype i) const
 
QItemSelectionRange value (qsizetype i, parameter_type defaultValue) const
 
void swapItemsAt (qsizetype i, qsizetype j)
 
void push_back (parameter_type t)
 
void push_back (rvalue_ref t)
 
void push_front (rvalue_ref t)
 
void push_front (parameter_type t)
 
void pop_back () noexcept
 
void pop_front () noexcept
 
reference emplace_back (Args &&... args)
 
bool empty () const noexcept
 
reference front ()
 
const_reference front () const noexcept
 
reference back ()
 
const_reference back () const noexcept
 
void shrink_to_fit ()
 
QList< QItemSelectionRange > & operator+= (const QList< QItemSelectionRange > &l)
 
QList< QItemSelectionRange > & operator+= (QList< QItemSelectionRange > &&l)
 
QList< QItemSelectionRange > & operator+= (parameter_type t)
 
QList< QItemSelectionRange > & operator+= (rvalue_ref t)
 
QList< QItemSelectionRangeoperator+ (const QList< QItemSelectionRange > &l) const &
 
QList< QItemSelectionRangeoperator+ (const QList< QItemSelectionRange > &l) &&
 
QList< QItemSelectionRangeoperator+ (QList< QItemSelectionRange > &&l) const &
 
QList< QItemSelectionRangeoperator+ (QList< QItemSelectionRange > &&l) &&
 
QList< QItemSelectionRange > & operator<< (parameter_type t)
 
QList< QItemSelectionRange > & operator<< (const QList< QItemSelectionRange > &l)
 
QList< QItemSelectionRange > & operator<< (QList< QItemSelectionRange > &&l)
 
QList< QItemSelectionRange > & operator<< (rvalue_ref t)
 
QList< QItemSelectionRangetoList () const noexcept
 
QList< QItemSelectionRangetoVector () const noexcept
 
- Public Member Functions inherited from QListSpecialMethodsBase< T >
template<typename AT = T>
qsizetype indexOf (const AT &t, qsizetype from=0) const noexcept
 
template<typename AT = T>
qsizetype lastIndexOf (const AT &t, qsizetype from=-1) const noexcept
 
template<typename AT = T>
bool contains (const AT &t) const noexcept
 

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 Public Member Functions inherited from QList< QItemSelectionRange >
static qsizetype max_size () noexcept
 
static QList< QItemSelectionRangefromList (const QList< QItemSelectionRange > &list) noexcept
 
static QList< QItemSelectionRangefromVector (const QList< QItemSelectionRange > &vector) noexcept
 
static QList< QItemSelectionRangefromReadOnlyData (const QItemSelectionRange(&t)[N]) noexcept
 

Additional Inherited Members

- Public Types inherited from QList< QItemSelectionRange >
using Type
 
using value_type
 
using pointer
 
using const_pointer
 
using reference
 
using const_reference
 
using size_type
 
using difference_type
 
using parameter_type
 
using rvalue_ref
 
using Iterator
 
using ConstIterator
 
using reverse_iterator
 
using const_reverse_iterator
 
- Protected Types inherited from QListSpecialMethodsBase< T >
using Self = QList<T>
 
- Protected Member Functions inherited from QListSpecialMethods< T >
 ~QListSpecialMethods ()=default
 
- Protected Member Functions inherited from QListSpecialMethodsBase< T >
 ~QListSpecialMethodsBase ()=default
 
Selfself ()
 
const Selfself () const
 

Detailed Description

\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:

...
selection->select(topLeft, bottomRight);
\inmodule QtCore
QItemSelection * selection
[0]

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.

See also
{Model/View Programming}, QItemSelectionModel

Definition at line 180 of file qitemselectionmodel.h.

Constructor & Destructor Documentation

◆ QItemSelection()

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 377 of file qitemselectionmodel.cpp.

References select().

+ Here is the call graph for this function:

Member Function Documentation

◆ contains()

bool QItemSelection::contains ( const QModelIndex & index) const

Returns true if the selection contains the given index; otherwise returns false.

Definition at line 417 of file qitemselectionmodel.cpp.

References QList< QItemSelectionRange >::begin(), QList< QItemSelectionRange >::end(), isSelectableAndEnabled(), and it.

Referenced by QQuickTreeViewPrivate::updateSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ indexes()

QModelIndexList QItemSelection::indexes ( ) const

Returns a list of model indexes that correspond to the selected items.

Definition at line 432 of file qitemselectionmodel.cpp.

Referenced by QCompleterPrivate::_q_completionSelected(), QAbstractItemViewPrivate::clearOrRemove(), QItemSelectionModel::selectedIndexes(), QTreeWidgetPrivate::selectionChanged(), QListView::selectionChanged(), QTableView::selectionChanged(), QTreeView::selectionChanged(), QQuickTableViewPrivate::selectionChangedInSelectionModel(), MainWindow::updateSelection(), and QQuickTreeViewPrivate::updateSelection().

+ Here is the caller graph for this function:

◆ merge()

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.

See also
split()

Definition at line 455 of file qitemselectionmodel.cpp.

References QList< T >::append(), QList< T >::at(), at, QItemSelectionModel::Deselect, i, QList< QItemSelectionRange >::operator+=(), other(), QList< T >::push_back(), QList< QItemSelectionRange >::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(), QListView::setSelection(), QQuickTableViewPrivate::updateSelection(), and QQuickTreeViewPrivate::updateSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ select()

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.

Note
topLeft and bottomRight must have the same parent.

Definition at line 389 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(), QListViewPrivate::selection(), and QListView::setSelection().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ split()

void QItemSelection::split ( const QItemSelectionRange & range,
const QItemSelectionRange & other,
QItemSelection * result )
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.

See also
merge()

Definition at line 509 of file qitemselectionmodel.cpp.

References QAbstractTableModel::index(), model, other(), and Q_ASSERT.

Referenced by QItemSelectionModel::emitSelectionChanged(), merge(), and QItemSelectionModelPrivate::rowsAboutToBeRemoved().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: