Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
|
[38] More...
#include <qitemselectionmodel.h>
Public Types | |
enum | SelectionFlag { NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select , NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select , NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select } |
This enum describes the way the selection model will be updated. More... | |
enum | SelectionFlag { NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select , NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select , NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select } |
enum | SelectionFlag { NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select , NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select , NoUpdate = 0x0000 , Clear = 0x0001 , Select = 0x0002 , Deselect = 0x0004 , Toggle = 0x0008 , Current = 0x0010 , Rows = 0x0020 , Columns = 0x0040 , SelectCurrent = Select | Current , ToggleCurrent = Toggle | Current , ClearAndSelect = Clear | Select } |
Public Slots | |
virtual void | setCurrentIndex (const QModelIndex &index, QItemSelectionModel::SelectionFlags command) |
Sets the model item index to be the current item, and emits currentChanged(). | |
virtual void | select (const QModelIndex &index, QItemSelectionModel::SelectionFlags command) |
Selects the model item index using the specified command, and emits selectionChanged(). | |
virtual void | select (const QItemSelection &selection, QItemSelectionModel::SelectionFlags command) |
Selects the item selection using the specified command, and emits selectionChanged(). | |
virtual void | clear () |
Clears the selection model. | |
virtual void | reset () |
Clears the selection model. | |
void | clearSelection () |
virtual void | clearCurrentIndex () |
Clears the current index. | |
Public Slots inherited from QObject | |
void | deleteLater () |
\threadsafe | |
Signals | |
void | selectionChanged (const QItemSelection &selected, const QItemSelection &deselected) |
This signal is emitted whenever the selection changes. | |
void | currentChanged (const QModelIndex ¤t, const QModelIndex &previous) |
This signal is emitted whenever the current item changes. | |
void | currentRowChanged (const QModelIndex ¤t, const QModelIndex &previous) |
This signal is emitted if the current item changes and its row is different to the row of the previous current item. | |
void | currentColumnChanged (const QModelIndex ¤t, const QModelIndex &previous) |
This signal is emitted if the current item changes and its column is different to the column of the previous current item. | |
void | modelChanged (QAbstractItemModel *model) |
Signals inherited from QObject | |
void | destroyed (QObject *=nullptr) |
This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked. | |
void | objectNameChanged (const QString &objectName, QPrivateSignal) |
This signal is emitted after the object's name has been changed. | |
Public Member Functions | |
QItemSelectionModel (QAbstractItemModel *model=nullptr) | |
Constructs a selection model that operates on the specified item model. | |
QItemSelectionModel (QAbstractItemModel *model, QObject *parent) | |
Constructs a selection model that operates on the specified item model with parent. | |
virtual | ~QItemSelectionModel () |
Destroys the selection model. | |
QModelIndex | currentIndex () const |
Returns the model item index for the current item, or an invalid index if there is no current item. | |
Q_INVOKABLE bool | isSelected (const QModelIndex &index) const |
Returns true if the given model item index is selected. | |
Q_INVOKABLE bool | isRowSelected (int row, const QModelIndex &parent=QModelIndex()) const |
Returns true if all items are selected in the row with the given parent. | |
Q_INVOKABLE bool | isColumnSelected (int column, const QModelIndex &parent=QModelIndex()) const |
Returns true if all items are selected in the column with the given parent. | |
Q_INVOKABLE bool | rowIntersectsSelection (int row, const QModelIndex &parent=QModelIndex()) const |
Returns true if there are any items selected in the row with the given parent. | |
Q_INVOKABLE bool | columnIntersectsSelection (int column, const QModelIndex &parent=QModelIndex()) const |
Returns true if there are any items selected in the column with the given parent. | |
bool | hasSelection () const |
QModelIndexList | selectedIndexes () const |
Returns a list of all selected model item indexes. | |
Q_INVOKABLE QModelIndexList | selectedRows (int column=0) const |
Q_INVOKABLE QModelIndexList | selectedColumns (int row=0) const |
const QItemSelection | selection () const |
Returns the selection ranges stored in the selection model. | |
const QAbstractItemModel * | model () const |
Returns the item model operated on by the selection model. | |
QAbstractItemModel * | model () |
QBindable< QAbstractItemModel * > | bindableModel () |
void | setModel (QAbstractItemModel *model) |
Public Member Functions inherited from QObject | |
Q_INVOKABLE | QObject (QObject *parent=nullptr) |
Constructs an object with parent object parent. | |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. | |
virtual bool | event (QEvent *event) |
This virtual function receives events to an object and should return true if the event e was recognized and processed. | |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
Filters events if this object has been installed as an event filter for the watched object. | |
QString | objectName () const |
Q_WEAK_OVERLOAD void | setObjectName (const QString &name) |
Sets the object's name to name. | |
void | setObjectName (QAnyStringView name) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
QBindable< QString > | bindableObjectName () |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false . | |
bool | isWindowType () const |
Returns true if the object is a window; otherwise returns false . | |
bool | isQuickItemType () const |
Returns true if the object is a QQuickItem; otherwise returns false . | |
bool | signalsBlocked () const noexcept |
Returns true if signals are blocked; otherwise returns false . | |
bool | blockSignals (bool b) noexcept |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). | |
QThread * | thread () const |
Returns the thread in which the object lives. | |
bool | moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL) |
Changes the thread affinity for this object and its children and returns true on success. | |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds. | |
int | startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer) |
void | killTimer (int id) |
Kills the timer with timer identifier, id. | |
void | killTimer (Qt::TimerId id) |
template<typename T > | |
T | findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object. | |
template<typename T > | |
QList< T > | findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. | |
template<typename T > | |
T | findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<typename T > | |
QList< T > | findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
const QObjectList & | children () const |
Returns a list of child objects. | |
void | setParent (QObject *parent) |
Makes the object a child of parent. | |
void | installEventFilter (QObject *filterObj) |
Installs an event filter filterObj on this object. | |
void | removeEventFilter (QObject *obj) |
Removes an event filter object obj from this object. | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const |
bool | disconnect (const QObject *receiver, const char *member=nullptr) const |
void | dumpObjectTree () const |
Dumps a tree of children to the debug output. | |
void | dumpObjectInfo () const |
Dumps information about signal connections, etc. | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. | |
bool | setProperty (const char *name, QVariant &&value) |
QVariant | property (const char *name) const |
Returns the value of the object's name property. | |
QList< QByteArray > | dynamicPropertyNames () const |
QBindingStorage * | bindingStorage () |
const QBindingStorage * | bindingStorage () const |
QObject * | parent () const |
Returns a pointer to the parent object. | |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false . | |
Protected Member Functions | |
QItemSelectionModel (QItemSelectionModelPrivate &dd, QAbstractItemModel *model) | |
void | emitSelectionChanged (const QItemSelection &newSelection, const QItemSelection &oldSelection) |
Compares the two selections newSelection and oldSelection and emits selectionChanged() with the deselected and selected items. | |
Protected Member Functions inherited from QObject | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr. | |
int | senderSignalIndex () const |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. | |
bool | isSignalConnected (const QMetaMethod &signal) const |
virtual void | timerEvent (QTimerEvent *event) |
This event handler can be reimplemented in a subclass to receive timer events for the object. | |
virtual void | childEvent (QChildEvent *event) |
This event handler can be reimplemented in a subclass to receive child events. | |
virtual void | customEvent (QEvent *event) |
This event handler can be reimplemented in a subclass to receive custom events. | |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
QObject (QObjectPrivate &dd, QObject *parent=nullptr) | |
Properties | |
QAbstractItemModel * | model |
bool | hasSelection |
QModelIndex | currentIndex |
QItemSelection | selection |
QModelIndexList | selectedIndexes |
Properties inherited from QObject | |
QString | objectName |
the name of this object | |
Additional Inherited Members | |
Static Public Member Functions inherited from QObject | |
static QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
\threadsafe | |
static QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection) |
template<typename Func1 , typename Func2 > | |
static QMetaObject::Connection | connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
\threadsafe | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static bool | disconnect (const QMetaObject::Connection &) |
Disconnect a connection. | |
template<typename Func1 , typename Func2 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot) |
template<typename Func1 > | |
static bool | disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero) |
Protected Attributes inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Related Symbols inherited from QObject | |
template< class T > T | qobject_cast (const QObject *object) |
Returns the given object cast to type T if the object is of type T (or of a subclass); otherwise returns \nullptr. | |
template< typename T > T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
template< typename T > QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QObjectList | |
\macro Q_CLASSINFO(Name, Value) | |
[38]
\inmodule QtCore
[39]
The QItemSelectionModel class keeps track of a view's selected items.
A QItemSelectionModel keeps track of the selected items in a view, or in several views onto the same model. It also keeps track of the currently selected item in a view.
The QItemSelectionModel class is one of the \l{Model/View Classes} and is part of Qt's \l{Model/View Programming}{model/view framework}.
The selected items are stored using ranges. Whenever you want to modify the selected items use select() and provide either a QItemSelection, or a QModelIndex and a QItemSelectionModel::SelectionFlag.
The QItemSelectionModel takes a two layer approach to selection management, dealing with both selected items that have been committed and items that are part of the current selection. The current selected items are part of the current interactive selection (for example with rubber-band selection or keyboard-shift selections).
To update the currently selected items, use the bitwise OR of QItemSelectionModel::Current and any of the other SelectionFlags. If you omit the QItemSelectionModel::Current command, a new current selection will be created, and the previous one added to the whole selection. All functions operate on both layers; for example, \l {QTableWidget::selectedItems()}{selecteditems()} will return items from both layers.
Definition at line 327 of file src_corelib_kernel_qobject.cpp.
This enum describes the way the selection model will be updated.
\value NoUpdate No selection will be made. \value Clear The complete selection will be cleared. \value Select All specified indexes will be selected. \value Deselect All specified indexes will be deselected. \value Toggle All specified indexes will be selected or deselected depending on their current state. \value Current The current selection will be updated. \value Rows All indexes will be expanded to span rows. \value Columns All indexes will be expanded to span columns. \value SelectCurrent A combination of Select and Current, provided for convenience. \value ToggleCurrent A combination of Toggle and Current, provided for convenience. \value ClearAndSelect A combination of Clear and Select, provided for convenience.
Definition at line 333 of file src_corelib_kernel_qobject.cpp.
Definition at line 333 of file src_corelib_kernel_qobject.cpp.
Definition at line 106 of file qitemselectionmodel.h.
|
explicit |
Constructs a selection model that operates on the specified item model.
Definition at line 1179 of file qitemselectionmodel.cpp.
|
explicit |
Constructs a selection model that operates on the specified item model with parent.
Definition at line 1188 of file qitemselectionmodel.cpp.
|
virtual |
Destroys the selection model.
Definition at line 1206 of file qitemselectionmodel.cpp.
|
protected |
Definition at line 1197 of file qitemselectionmodel.cpp.
QBindable< QAbstractItemModel * > QItemSelectionModel::bindableModel | ( | ) |
Definition at line 1937 of file qitemselectionmodel.cpp.
|
virtualslot |
Clears the selection model.
Emits selectionChanged() and currentChanged().
Definition at line 1378 of file qitemselectionmodel.cpp.
|
virtualslot |
Clears the current index.
Emits currentChanged().
Definition at line 1387 of file qitemselectionmodel.cpp.
|
slot |
Definition at line 1412 of file qitemselectionmodel.cpp.
bool QItemSelectionModel::columnIntersectsSelection | ( | int | column, |
const QModelIndex & | parent = QModelIndex() ) const |
Returns true
if there are any items selected in the column with the given parent.
Definition at line 1712 of file qitemselectionmodel.cpp.
|
signal |
This signal is emitted whenever the current item changes.
The previous model item index is replaced by the current index as the selection's current item.
Note that this signal will not be emitted when the item model is reset.
|
signal |
This signal is emitted if the current item changes and its column is different to the column of the previous current item.
Note that this signal will not be emitted when the item model is reset.
QModelIndex QItemSelectionModel::currentIndex | ( | ) | const |
Returns the model item index for the current item, or an invalid index if there is no current item.
Definition at line 1461 of file qitemselectionmodel.cpp.
|
signal |
This signal is emitted if the current item changes and its row is different to the row of the previous current item.
Note that this signal will not be emitted when the item model is reset.
|
protected |
Compares the two selections newSelection and oldSelection and emits selectionChanged() with the deselected and selected items.
Definition at line 1963 of file qitemselectionmodel.cpp.
bool QItemSelectionModel::hasSelection | ( | ) | const |
Returns true
if the selection model contains any selected item, otherwise returns false
.
Definition at line 1760 of file qitemselectionmodel.cpp.
bool QItemSelectionModel::isColumnSelected | ( | int | column, |
const QModelIndex & | parent = QModelIndex() ) const |
Returns true
if all items are selected in the column with the given parent.
Note that this function is usually faster than calling isSelected() on all items in the same column and that unselectable items are ignored.
Definition at line 1594 of file qitemselectionmodel.cpp.
bool QItemSelectionModel::isRowSelected | ( | int | row, |
const QModelIndex & | parent = QModelIndex() ) const |
Returns true
if all items are selected in the row with the given parent.
Note that this function is usually faster than calling isSelected() on all items in the same row and that unselectable items are ignored.
Definition at line 1508 of file qitemselectionmodel.cpp.
bool QItemSelectionModel::isSelected | ( | const QModelIndex & | index | ) | const |
Returns true
if the given model item index is selected.
Definition at line 1469 of file qitemselectionmodel.cpp.
QAbstractItemModel * QItemSelectionModel::model | ( | ) |
const QAbstractItemModel * QItemSelectionModel::model | ( | ) | const |
Returns the item model operated on by the selection model.
Definition at line 1932 of file qitemselectionmodel.cpp.
|
signal |
This signal is emitted when the model is successfully set with setModel().
|
virtualslot |
Clears the selection model.
Does not emit any signals.
Definition at line 1402 of file qitemselectionmodel.cpp.
bool QItemSelectionModel::rowIntersectsSelection | ( | int | row, |
const QModelIndex & | parent = QModelIndex() ) const |
Returns true
if there are any items selected in the row with the given parent.
Definition at line 1676 of file qitemselectionmodel.cpp.
|
virtualslot |
Selects the item selection using the specified command, and emits selectionChanged().
Definition at line 1327 of file qitemselectionmodel.cpp.
|
virtualslot |
Selects the model item index using the specified command, and emits selectionChanged().
Definition at line 1216 of file qitemselectionmodel.cpp.
QModelIndexList QItemSelectionModel::selectedColumns | ( | int | row = 0 | ) | const |
Definition at line 1853 of file qitemselectionmodel.cpp.
QModelIndexList QItemSelectionModel::selectedIndexes | ( | ) | const |
Returns a list of all selected model item indexes.
The list contains no duplicates, and is not sorted.
Definition at line 1790 of file qitemselectionmodel.cpp.
QModelIndexList QItemSelectionModel::selectedRows | ( | int | column = 0 | ) | const |
Definition at line 1824 of file qitemselectionmodel.cpp.
const QItemSelection QItemSelectionModel::selection | ( | ) | const |
Returns the selection ranges stored in the selection model.
Definition at line 1878 of file qitemselectionmodel.cpp.
|
signal |
This signal is emitted whenever the selection changes.
The change in the selection is represented as an item selection of deselected items and an item selection of selected items.
Note the that the current index changes independently from the selection. Also note that this signal will not be emitted when the item model is reset.
Items which stay selected but change their index are not included in selected and deselected. Thus, this signal might be emitted with both selected and deselected empty, if only the indices of selected items change.
|
virtualslot |
Sets the model item index to be the current item, and emits currentChanged().
The current item is used for keyboard navigation and focus indication; it is independent of any selected items, although a selected item can also be the current item.
Depending on the specified command, the index can also become part of the current selection.
Definition at line 1432 of file qitemselectionmodel.cpp.
void QItemSelectionModel::setModel | ( | QAbstractItemModel * | model | ) |
Sets the model to model. The modelChanged() signal will be emitted.
Definition at line 1949 of file qitemselectionmodel.cpp.
|
read |
Definition at line 95 of file qitemselectionmodel.h.
|
read |
Definition at line 93 of file qitemselectionmodel.h.
|
readwrite |
Returns the item model operated on by the selection model.
Definition at line 91 of file qitemselectionmodel.h.
|
read |
Definition at line 99 of file qitemselectionmodel.h.
|
read |
Definition at line 97 of file qitemselectionmodel.h.