CopperSpice API  1.9.1
QItemSelectionModel Class Reference

Keeps track of a view's selected items. More...

Inheritance diagram for QItemSelectionModel:
QObject

Public Typedefs

using SelectionFlags = QFlags< SelectionFlag >
 

Public Types

enum  SelectionFlag : uint
 

Public Signals

void currentChanged (const QModelIndex &current, const QModelIndex &previous)
 
void currentColumnChanged (const QModelIndex &current, const QModelIndex &previous)
 
void currentRowChanged (const QModelIndex &current, const QModelIndex &previous)
 
void modelChanged (QAbstractItemModel *model)
 
void selectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

virtual void clear ()
 
void clearCurrentIndex ()
 
void clearSelection ()
 
virtual void reset ()
 
virtual void select (const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
 
virtual void select (const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
 
void setCurrentIndex (const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QItemSelectionModel (QAbstractItemModel *model, QObject *parent)
 
 QItemSelectionModel (QAbstractItemModel *model=nullptr)
 
virtual ~QItemSelectionModel ()
 
bool columnIntersectsSelection (int column, const QModelIndex &parent) const
 
QModelIndex currentIndex () const
 
bool hasSelection () const
 
bool isColumnSelected (int column, const QModelIndex &parent) const
 
bool isRowSelected (int row, const QModelIndex &parent) const
 
bool isSelected (const QModelIndex &index) const
 
const QAbstractItemModelmodel () const
 
bool rowIntersectsSelection (int row, const QModelIndex &parent) const
 
QModelIndexList selectedColumns (int row=0) const
 
QModelIndexList selectedIndexes () const
 
QModelIndexList selectedRows (int column=0) const
 
QItemSelection selection () const
 
void setModel (QAbstractItemModel *model)
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Protected Methods

void emitSelectionChanged (const QItemSelection &newSelection, const QItemSelection &oldSelection)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Properties

 selectedIndexes
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 

Detailed Description

The QItemSelectionModel class keeps track of a view's selected items or in several views onto the same model. It also keeps track of the currently selected item in a view.

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, selectedItems() will return items from both layers.

See also
QAbstractItemModel, Model/View Architecture

Member Typedef Documentation

Member Enumeration Documentation

This enum describes the way the selection model will be updated.

ConstantValueDescription
QItemSelectionModel::NoUpdate0x0000No selection will be made.
QItemSelectionModel::Clear0x0001The complete selection will be cleared.
QItemSelectionModel::Select0x0002All specified indexes will be selected.
QItemSelectionModel::Deselect0x0004All specified indexes will be deselected.
QItemSelectionModel::Toggle0x0008 All specified indexes will be selected or deselected depending on their current state.
QItemSelectionModel::Current0x0010The current selection will be updated.
QItemSelectionModel::Rows0x0020All indexes will be expanded to span rows.
QItemSelectionModel::Columns0x0040All indexes will be expanded to span columns.
QItemSelectionModel::SelectCurrentSelect | Current A combination of Select and Current, provided for convenience.
QItemSelectionModel::ToggleCurrentToggle | Current A combination of Toggle and Current, provided for convenience.
QItemSelectionModel::ClearAndSelectClear | Select A combination of Clear and Select, provided for convenience.

Constructor & Destructor Documentation

QItemSelectionModel::QItemSelectionModel ( QAbstractItemModel model = nullptr)
explicit

Constructs a selection model that operates on the specified item model.

QItemSelectionModel::QItemSelectionModel ( QAbstractItemModel model,
QObject parent 
)
explicit

Constructs a selection model that operates on the specified item model with parent.

QItemSelectionModel::~QItemSelectionModel ( )
virtual

Destroys the selection model.

Method Documentation

void QItemSelectionModel::clear ( )
slot

Clears the selection model. Emits selectionChanged() and currentChanged().

void QItemSelectionModel::clearCurrentIndex ( )
slot

Clears the current index. Emits currentChanged().

void QItemSelectionModel::clearSelection ( )
slot

Clears the selection in the selection model. Emits selectionChanged().

bool QItemSelectionModel::columnIntersectsSelection ( int  column,
const QModelIndex parent 
) const

Returns true if there are any items selected in the column with the given parent.

void QItemSelectionModel::currentChanged ( const QModelIndex current,
const QModelIndex previous 
)
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. This signal will not be emitted when the item model is reset.

See also
currentIndex(), setCurrentIndex(), selectionChanged()
void QItemSelectionModel::currentColumnChanged ( const QModelIndex current,
const QModelIndex previous 
)
signal

This signal is emitted if the current item changes and its column is different to the column of the previous current item. This signal will not be emitted when the item model is reset.

See also
currentChanged(), currentRowChanged(), currentIndex(), setCurrentIndex()
QModelIndex QItemSelectionModel::currentIndex ( ) const

Returns the model item index for the current item or an invalid index if there is no current item.

See also
setCurrentIndex()
void QItemSelectionModel::currentRowChanged ( const QModelIndex current,
const QModelIndex previous 
)
signal

This signal is emitted if the current item changes and its row is different to the row of the previous current item. It will not be emitted when the item model is reset.

See also
currentChanged(), currentColumnChanged(), currentIndex(), setCurrentIndex()
void QItemSelectionModel::emitSelectionChanged ( const QItemSelection newSelection,
const QItemSelection oldSelection 
)
protected

Compares the two selections newSelection and oldSelection and emits selectionChanged() with the deselected and selected items.

bool QItemSelectionModel::hasSelection ( ) const

Returns true if the selection model contains any selection ranges, otherwise returns false.

bool QItemSelectionModel::isColumnSelected ( int  column,
const QModelIndex parent 
) const

Returns true if all items are selected in the column with the given parent. This method is usually faster than calling isSelected() on all items in the same column and that unselectable items are ignored.

bool QItemSelectionModel::isRowSelected ( int  row,
const QModelIndex parent 
) const

Returns true if all items are selected in the row with the given parent. This method is usually faster than calling isSelected() on all items in the same row and that unselectable items are ignored.

bool QItemSelectionModel::isSelected ( const QModelIndex index) const

Returns true if the given model item index is selected.

const QAbstractItemModel * QItemSelectionModel::model ( ) const

Returns the item model operated on by the selection model.

void QItemSelectionModel::modelChanged ( QAbstractItemModel model)
signal

This signal is emitted when the model is successfully set with setModel().

See also
model(), setModel()
void QItemSelectionModel::reset ( )
slot

Clears the selection model. Does not emit any signals.

bool QItemSelectionModel::rowIntersectsSelection ( int  row,
const QModelIndex parent 
) const

Returns true if there are any items selected in the row with the given parent.

void QItemSelectionModel::select ( const QItemSelection selection,
QItemSelectionModel::SelectionFlags  command 
)
slot

Selects the item selection using the specified command and emits selectionChanged().

See also
QItemSelectionModel::SelectionFlag
void QItemSelectionModel::select ( const QModelIndex index,
QItemSelectionModel::SelectionFlags  command 
)
slot

Selects the model item index using the specified command and emits selectionChanged().

See also
QItemSelectionModel::SelectionFlags
QModelIndexList QItemSelectionModel::selectedColumns ( int  row = 0) const

Returns the indexes in the given row for columns where all rows are selected.

See also
selectedIndexes(), selectedRows()
QModelIndexList QItemSelectionModel::selectedIndexes ( ) const

Returns a list of all selected model item indexes. The list contains no duplicates and is not sorted.

QModelIndexList QItemSelectionModel::selectedRows ( int  column = 0) const

Returns the indexes in the given column for the rows where all columns are selected.

See also
selectedIndexes(), selectedColumns()
QItemSelection QItemSelectionModel::selection ( ) const

Returns the selection ranges stored in the selection model.

void QItemSelectionModel::selectionChanged ( const QItemSelection selected,
const QItemSelection deselected 
)
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.

The current index changes independently from the selection and this signal will not be emitted when the item model is reset.

See also
select(), currentChanged()
void QItemSelectionModel::setCurrentIndex ( const QModelIndex index,
QItemSelectionModel::SelectionFlags  command 
)
slot

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.

See also
currentIndex(), select()
void QItemSelectionModel::setModel ( QAbstractItemModel model)

Sets the current QItemSelectionMode to model and emits the modelChanged() signal.

See also
model(), modelChanged()

Property Documentation

QItemSelectionModel::selectedIndexes

This property contains a list of all the currently selected indexes.

PropertiesClass Methods
read selectedIndexes
notify selectionChanged
designable true
stored true