Qt 4.8
Public Types | Public Slots | Signals | Public Functions | Protected Functions | List of all members
QItemSelectionModel Class Reference

The QItemSelectionModel class keeps track of a view's selected items. More...

#include <qitemselectionmodel.h>

Inheritance diagram for QItemSelectionModel:
QObject

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
}
 This enum describes the way the selection model will be updated. More...
 

Public Slots

virtual void clear ()
 Clears the selection model. More...
 
void clearSelection ()
 Clears the selection in the selection model. More...
 
virtual void reset ()
 Clears the selection model. More...
 
virtual void select (const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
 Selects the model item index using the specified command, and emits selectionChanged(). More...
 
virtual void select (const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
 Selects the item selection using the specified command, and emits selectionChanged(). More...
 
void setCurrentIndex (const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
 Sets the model item index to be the current item, and emits currentChanged(). More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void currentChanged (const QModelIndex &current, const QModelIndex &previous)
 This signal is emitted whenever the current item changes. More...
 
void currentColumnChanged (const QModelIndex &current, 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. More...
 
void currentRowChanged (const QModelIndex &current, 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. More...
 
void selectionChanged (const QItemSelection &selected, const QItemSelection &deselected)
 This signal is emitted whenever the selection changes. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

bool columnIntersectsSelection (int column, const QModelIndex &parent) const
 Returns true if there are any items selected in the column with the given parent. More...
 
QModelIndex currentIndex () const
 Returns the model item index for the current item, or an invalid index if there is no current item. More...
 
bool hasSelection () const
 Returns true if the selection model contains any selection ranges; otherwise returns false. More...
 
bool isColumnSelected (int column, const QModelIndex &parent) const
 Returns true if all items are selected in the column with the given parent. More...
 
bool isRowSelected (int row, const QModelIndex &parent) const
 Returns true if all items are selected in the row with the given parent. More...
 
bool isSelected (const QModelIndex &index) const
 Returns true if the given model item index is selected. More...
 
const QAbstractItemModelmodel () const
 Returns the item model operated on by the selection model. More...
 
 QItemSelectionModel (QAbstractItemModel *model)
 Constructs a selection model that operates on the specified item model. More...
 
 QItemSelectionModel (QAbstractItemModel *model, QObject *parent)
 Constructs a selection model that operates on the specified item model with parent. More...
 
bool rowIntersectsSelection (int row, const QModelIndex &parent) const
 Returns true if there are any items selected in the row with the given parent. More...
 
QModelIndexList selectedColumns (int row=0) const
 Returns the indexes in the given row for columns where all rows are selected. More...
 
QModelIndexList selectedIndexes () const
 Returns a list of all selected model item indexes. More...
 
QModelIndexList selectedRows (int column=0) const
 Returns the indexes in the given column for the rows where all columns are selected. More...
 
const QItemSelection selection () const
 Returns the selection ranges stored in the selection model. More...
 
virtual ~QItemSelectionModel ()
 Destroys the selection model. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) 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. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
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. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

void emitSelectionChanged (const QItemSelection &newSelection, const QItemSelection &oldSelection)
 Compares the two selections newSelection and oldSelection and emits selectionChanged() with the deselected and selected items. More...
 
 QItemSelectionModel (QItemSelectionModelPrivate &dd, QAbstractItemModel *model)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Additional Inherited Members

- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

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 Model/View Classes and is part of Qt's 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, selectedItems() will return items from both layers.

See also
{Model/View Programming}, QAbstractItemModel, {Chart Example}

Definition at line 151 of file qitemselectionmodel.h.

Enumerations

◆ SelectionFlag

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

  • NoUpdate No selection will be made.
  • Clear The complete selection will be cleared.
  • Select All specified indexes will be selected.
  • Deselect All specified indexes will be deselected.
  • Toggle All specified indexes will be selected or deselected depending on their current state.
  • Current The current selection will be updated.
  • Rows All indexes will be expanded to span rows.
  • Columns All indexes will be expanded to span columns.
  • SelectCurrent A combination of Select and Current, provided for convenience.
  • ToggleCurrent A combination of Toggle and Current, provided for convenience.
  • ClearAndSelect A combination of Clear and Select, provided for convenience.
Enumerator
NoUpdate 
Clear 
Select 
Deselect 
Toggle 
Current 
Rows 
Columns 
SelectCurrent 
ToggleCurrent 
ClearAndSelect 

Definition at line 159 of file qitemselectionmodel.h.

Constructors and Destructors

◆ QItemSelectionModel() [1/3]

QItemSelectionModel::QItemSelectionModel ( QAbstractItemModel model)
explicit

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

Definition at line 1035 of file qitemselectionmodel.cpp.

1036  : QObject(*new QItemSelectionModelPrivate, model)
1037 {
1038  d_func()->initModel(model);
1039 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ QItemSelectionModel() [2/3]

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

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

Definition at line 1044 of file qitemselectionmodel.cpp.

1045  : QObject(*new QItemSelectionModelPrivate, parent)
1046 {
1047  d_func()->initModel(model);
1048 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753

◆ ~QItemSelectionModel()

QItemSelectionModel::~QItemSelectionModel ( )
virtual

Destroys the selection model.

Definition at line 1062 of file qitemselectionmodel.cpp.

1063 {
1064 }

◆ QItemSelectionModel() [3/3]

QItemSelectionModel::QItemSelectionModel ( QItemSelectionModelPrivate dd,
QAbstractItemModel model 
)
protected
Warning
This function is not part of the public interface.

Definition at line 1053 of file qitemselectionmodel.cpp.

1054  : QObject(dd, model)
1055 {
1056  dd.initModel(model);
1057 }
Q_INVOKABLE QObject(QObject *parent=0)
Constructs an object with parent object parent.
Definition: qobject.cpp:753
void initModel(QAbstractItemModel *model)

Functions

◆ clear

void QItemSelectionModel::clear ( )
virtualslot

Clears the selection model.

Emits selectionChanged() and currentChanged().

Definition at line 1221 of file qitemselectionmodel.cpp.

Referenced by QListWidget::clear(), QTableWidget::clear(), QTreeWidget::clear(), QTableWidget::clearContents(), reset(), QSidebar::selectUrl(), QCompleterPrivate::setCurrentIndex(), QTreeView::setSelection(), and QCalendarWidgetPrivate::update().

1222 {
1224  clearSelection();
1225  QModelIndex previous = d->currentIndex;
1226  d->currentIndex = QModelIndex();
1227  if (previous.isValid()) {
1228  emit currentChanged(d->currentIndex, previous);
1229  emit currentRowChanged(d->currentIndex, previous);
1230  emit currentColumnChanged(d->currentIndex, previous);
1231  }
1232 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
void clearSelection()
Clears the selection in the selection model.
#define Q_D(Class)
Definition: qglobal.h:2482
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted if the current item changes and its row is different to the row of the previou...
#define emit
Definition: qobjectdefs.h:76
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QModelIndex class is used to locate data in a data model.
void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted whenever the current item changes.
void currentColumnChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted if the current item changes and its column is different to the column of the p...

◆ clearSelection

void QItemSelectionModel::clearSelection ( )
slot

Clears the selection in the selection model.

Since
4.2 Emits selectionChanged().

Definition at line 1251 of file qitemselectionmodel.cpp.

Referenced by clear().

1252 {
1254  if (d->ranges.count() == 0 && d->currentSelection.count() == 0)
1255  return;
1256 
1258 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
#define Q_D(Class)
Definition: qglobal.h:2482
The QItemSelection class manages information about selected items in a model.
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().

◆ columnIntersectsSelection()

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

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

Definition at line 1491 of file qitemselectionmodel.cpp.

Referenced by QHeaderViewPrivate::columnIntersectsSelection().

1492 {
1493  Q_D(const QItemSelectionModel);
1494  if (parent.isValid() && d->model != parent.model())
1495  return false;
1496 
1497  QItemSelection sel = d->ranges;
1498  sel.merge(d->currentSelection, d->currentCommand);
1499  for (int i = 0; i < sel.count(); ++i) {
1500  int left = sel.at(i).left();
1501  int right = sel.at(i).right();
1502  int top = sel.at(i).top();
1503  int bottom = sel.at(i).bottom();
1504  if (left <= column && right >= column) {
1505  for (int j = top; j <= bottom; j++) {
1506  const Qt::ItemFlags flags = d->model->index(j, column, parent).flags();
1507  if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled))
1508  return true;
1509  }
1510  }
1511  }
1512 
1513  return false;
1514 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
Merges the other selection with this QItemSelection using the command given.
int left() const
Returns the column index corresponding to the leftmost selected column in the selection range...
int bottom() const
Returns the row index corresponding to the lowermost selected row in the selection range...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int right() const
Returns the column index corresponding to the rightmost selected column in the selection range...
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QItemSelection class manages information about selected items in a model.
int top() const
Returns the row index corresponding to the uppermost selected row in the selection range...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ currentChanged

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.

Note that this signal will not be emitted when the item model is reset.

See also
currentIndex() setCurrentIndex() selectionChanged()

Referenced by clear(), and setCurrentIndex().

◆ currentColumnChanged

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.

Note that this signal will not be emitted when the item model is reset.

See also
currentChanged() currentRowChanged() currentIndex() setCurrentIndex()

Referenced by clear(), and setCurrentIndex().

◆ currentIndex()

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

Referenced by QAbstractItemViewPrivate::checkPersistentEditorFocus(), QAbstractItemView::closePersistentEditor(), QCompleterPrivate::setCurrentIndex(), QAccessibleItemRow::state(), and QAccessibleTable2Cell::state().

1297 {
1298  return static_cast<QModelIndex>(d_func()->currentIndex);
1299 }
The QModelIndex class is used to locate data in a data model.

◆ currentRowChanged

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.

Note that this signal will not be emitted when the item model is reset.

See also
currentChanged() currentColumnChanged() currentIndex() setCurrentIndex()

Referenced by clear(), and setCurrentIndex().

◆ emitSelectionChanged()

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.

Definition at line 1651 of file qitemselectionmodel.cpp.

Referenced by select().

1653 {
1654  // if both selections are empty or equal we return
1655  if ((oldSelection.isEmpty() && newSelection.isEmpty()) ||
1656  oldSelection == newSelection)
1657  return;
1658 
1659  // if either selection is empty we do not need to compare
1660  if (oldSelection.isEmpty() || newSelection.isEmpty()) {
1661  emit selectionChanged(newSelection, oldSelection);
1662  return;
1663  }
1664 
1665  QItemSelection deselected = oldSelection;
1666  QItemSelection selected = newSelection;
1667 
1668  // remove equal ranges
1669  bool advance;
1670  for (int o = 0; o < deselected.count(); ++o) {
1671  advance = true;
1672  for (int s = 0; s < selected.count() && o < deselected.count();) {
1673  if (deselected.at(o) == selected.at(s)) {
1674  deselected.removeAt(o);
1675  selected.removeAt(s);
1676  advance = false;
1677  } else {
1678  ++s;
1679  }
1680  }
1681  if (advance)
1682  ++o;
1683  }
1684 
1685  // find intersections
1686  QItemSelection intersections;
1687  for (int o = 0; o < deselected.count(); ++o) {
1688  for (int s = 0; s < selected.count(); ++s) {
1689  if (deselected.at(o).intersects(selected.at(s)))
1690  intersections.append(deselected.at(o).intersected(selected.at(s)));
1691  }
1692  }
1693 
1694  // compare remaining ranges with intersections and split them to find deselected and selected
1695  for (int i = 0; i < intersections.count(); ++i) {
1696  // split deselected
1697  for (int o = 0; o < deselected.count();) {
1698  if (deselected.at(o).intersects(intersections.at(i))) {
1699  QItemSelection::split(deselected.at(o), intersections.at(i), &deselected);
1700  deselected.removeAt(o);
1701  } else {
1702  ++o;
1703  }
1704  }
1705  // split selected
1706  for (int s = 0; s < selected.count();) {
1707  if (selected.at(s).intersects(intersections.at(i))) {
1708  QItemSelection::split(selected.at(s), intersections.at(i), &selected);
1709  selected.removeAt(s);
1710  } else {
1711  ++s;
1712  }
1713  }
1714  }
1715 
1716  if (!selected.isEmpty() || !deselected.isEmpty())
1717  emit selectionChanged(selected, deselected);
1718 }
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
This signal is emitted whenever the selection changes.
The QItemSelection class manages information about selected items in a model.
QItemSelectionRange intersected(const QItemSelectionRange &other) const
Returns a new selection range containing only the items that are found in both the selection range an...
bool intersects(const QItemSelectionRange &other) const
Returns true if this selection range intersects (overlaps with) the other range given; otherwise retu...
static void split(const QItemSelectionRange &range, const QItemSelectionRange &other, QItemSelection *result)
Splits the selection range using the selection other range.
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ hasSelection()

bool QItemSelectionModel::hasSelection ( ) const

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

Since
4.2

Definition at line 1525 of file qitemselectionmodel.cpp.

Referenced by QComboBox::hidePopup(), QInputDialogPrivate::listViewText(), QHeaderViewPrivate::prepareSectionSelected(), and QInputDialogPrivate::setInputWidget().

1526 {
1527  Q_D(const QItemSelectionModel);
1528  if (d->currentCommand & (Toggle | Deselect)) {
1529  QItemSelection sel = d->ranges;
1530  sel.merge(d->currentSelection, d->currentCommand);
1531  return !sel.isEmpty();
1532  } else {
1533  return !(d->ranges.isEmpty() && d->currentSelection.isEmpty());
1534  }
1535 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
Merges the other selection with this QItemSelection using the command given.
#define Q_D(Class)
Definition: qglobal.h:2482
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
The QItemSelection class manages information about selected items in a model.

◆ isColumnSelected()

bool QItemSelectionModel::isColumnSelected ( int  column,
const QModelIndex parent 
) 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 1406 of file qitemselectionmodel.cpp.

Referenced by QAccessibleTable2::isColumnSelected(), QHeaderViewPrivate::isColumnSelected(), QAccessibleItemView::isColumnSelected(), and selectedColumns().

1407 {
1408  Q_D(const QItemSelectionModel);
1409  if (parent.isValid() && d->model != parent.model())
1410  return false;
1411 
1412  // return false if column exist in currentSelection (Deselect)
1413  if (d->currentCommand & Deselect && d->currentSelection.count()) {
1414  for (int i = 0; i < d->currentSelection.count(); ++i) {
1415  if (d->currentSelection.at(i).parent() == parent &&
1416  column >= d->currentSelection.at(i).left() &&
1417  column <= d->currentSelection.at(i).right())
1418  return false;
1419  }
1420  }
1421  // return false if ranges in both currentSelection and the selection model
1422  // intersect and have the same column contained
1423  if (d->currentCommand & Toggle && d->currentSelection.count()) {
1424  for (int i = 0; i < d->currentSelection.count(); ++i) {
1425  if (d->currentSelection.at(i).left() <= column &&
1426  d->currentSelection.at(i).right() >= column) {
1427  for (int j = 0; j < d->ranges.count(); ++j) {
1428  if (d->ranges.at(j).left() <= column && d->ranges.at(j).right() >= column
1429  && d->currentSelection.at(i).intersected(d->ranges.at(j)).isValid()) {
1430  return false;
1431  }
1432  }
1433  }
1434  }
1435  }
1436  // add ranges and currentSelection and check through them all
1438  QList<QItemSelectionRange> joined = d->ranges;
1439  if (d->currentSelection.count())
1440  joined += d->currentSelection;
1441  int rowCount = d->model->rowCount(parent);
1442  for (int row = 0; row < rowCount; ++row) {
1443  for (it = joined.constBegin(); it != joined.constEnd(); ++it) {
1444  if ((*it).contains(row, column, parent)) {
1445  Qt::ItemFlags flags = d->model->index(row, column, parent).flags();
1446  if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled)) {
1447  row = qMax(row, (*it).bottom());
1448  break;
1449  }
1450  }
1451  }
1452  if (it == joined.constEnd())
1453  return false;
1454  }
1455  return rowCount > 0; // no rows means no selected items
1456 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ isRowSelected()

bool QItemSelectionModel::isRowSelected ( int  row,
const QModelIndex parent 
) 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 1346 of file qitemselectionmodel.cpp.

Referenced by QAccessibleTable2::isRowSelected(), QHeaderViewPrivate::isRowSelected(), QAccessibleTree::isRowSelected(), QAccessibleItemView::isRowSelected(), selectedRows(), and QAccessibleItemRow::state().

1347 {
1348  Q_D(const QItemSelectionModel);
1349  if (parent.isValid() && d->model != parent.model())
1350  return false;
1351 
1352  // return false if row exist in currentSelection (Deselect)
1353  if (d->currentCommand & Deselect && d->currentSelection.count()) {
1354  for (int i=0; i<d->currentSelection.count(); ++i) {
1355  if (d->currentSelection.at(i).parent() == parent &&
1356  row >= d->currentSelection.at(i).top() &&
1357  row <= d->currentSelection.at(i).bottom())
1358  return false;
1359  }
1360  }
1361  // return false if ranges in both currentSelection and ranges
1362  // intersect and have the same row contained
1363  if (d->currentCommand & Toggle && d->currentSelection.count()) {
1364  for (int i=0; i<d->currentSelection.count(); ++i)
1365  if (d->currentSelection.at(i).top() <= row &&
1366  d->currentSelection.at(i).bottom() >= row)
1367  for (int j=0; j<d->ranges.count(); ++j)
1368  if (d->ranges.at(j).top() <= row && d->ranges.at(j).bottom() >= row
1369  && d->currentSelection.at(i).intersected(d->ranges.at(j)).isValid())
1370  return false;
1371  }
1372  // add ranges and currentSelection and check through them all
1374  QList<QItemSelectionRange> joined = d->ranges;
1375  if (d->currentSelection.count())
1376  joined += d->currentSelection;
1377  int colCount = d->model->columnCount(parent);
1378  for (int column = 0; column < colCount; ++column) {
1379  for (it = joined.constBegin(); it != joined.constEnd(); ++it) {
1380  if ((*it).contains(row, column, parent)) {
1381  bool selectable = false;
1382  for (int i = column; !selectable && i <= (*it).right(); ++i) {
1383  Qt::ItemFlags flags = d->model->index(row, i, parent).flags();
1384  selectable = flags & Qt::ItemIsSelectable;
1385  }
1386  if (selectable){
1387  column = qMax(column, (*it).right());
1388  break;
1389  }
1390  }
1391  }
1392  if (it == joined.constEnd())
1393  return false;
1394  }
1395  return colCount > 0; // no columns means no selected items
1396 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
#define it(className, varName)
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
#define Q_D(Class)
Definition: qglobal.h:2482
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ isSelected()

bool QItemSelectionModel::isSelected ( const QModelIndex index) const

Returns true if the given model item index is selected.

Definition at line 1304 of file qitemselectionmodel.cpp.

Referenced by QColumnViewPrivate::_q_clicked(), QAbstractItemViewPrivate::extendedSelectionCommand(), QListWidget::isItemSelected(), QTableWidget::isItemSelected(), QAccessibleItemView::isSelected(), QAccessibleTable2Cell::isSelected(), QListView::paintEvent(), QAbstractItemViewPrivate::shouldEdit(), QAccessibleItemRow::state(), and QAccessibleTable2Cell::state().

1305 {
1306  Q_D(const QItemSelectionModel);
1307  if (d->model != index.model() || !index.isValid())
1308  return false;
1309 
1310  bool selected = false;
1311  // search model ranges
1313  for (; it != d->ranges.end(); ++it) {
1314  if ((*it).isValid() && (*it).contains(index)) {
1315  selected = true;
1316  break;
1317  }
1318  }
1319 
1320  // check currentSelection
1321  if (d->currentSelection.count()) {
1322  if ((d->currentCommand & Deselect) && selected)
1323  selected = !d->currentSelection.contains(index);
1324  else if (d->currentCommand & Toggle)
1325  selected ^= d->currentSelection.contains(index);
1326  else if ((d->currentCommand & Select) && !selected)
1327  selected = d->currentSelection.contains(index);
1328  }
1329 
1330  if (selected) {
1331  Qt::ItemFlags flags = d->model->flags(index);
1332  return (flags & Qt::ItemIsSelectable);
1333  }
1334 
1335  return false;
1336 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
#define it(className, varName)
#define Q_D(Class)
Definition: qglobal.h:2482
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QList class is a template class that provides lists.
Definition: qdatastream.h:62

◆ model()

const QAbstractItemModel * QItemSelectionModel::model ( ) const

Returns the item model operated on by the selection model.

Definition at line 1642 of file qitemselectionmodel.cpp.

Referenced by selectedColumns(), selectedRows(), and QAbstractItemView::setSelectionModel().

1643 {
1644  return d_func()->model;
1645 }

◆ reset

void QItemSelectionModel::reset ( )
virtualslot

Clears the selection model.

Does not emit any signals.

Definition at line 1237 of file qitemselectionmodel.cpp.

1238 {
1239  bool block = blockSignals(true);
1240  clear();
1241  blockSignals(block);
1242 }
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
virtual void clear()
Clears the selection model.

◆ rowIntersectsSelection()

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

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

Definition at line 1462 of file qitemselectionmodel.cpp.

Referenced by QHeaderViewPrivate::rowIntersectsSelection().

1463 {
1464  Q_D(const QItemSelectionModel);
1465  if (parent.isValid() && d->model != parent.model())
1466  return false;
1467 
1468  QItemSelection sel = d->ranges;
1469  sel.merge(d->currentSelection, d->currentCommand);
1470  for (int i = 0; i < sel.count(); ++i) {
1471  int top = sel.at(i).top();
1472  int bottom = sel.at(i).bottom();
1473  int left = sel.at(i).left();
1474  int right = sel.at(i).right();
1475  if (top <= row && bottom >= row) {
1476  for (int j = left; j <= right; j++) {
1477  const Qt::ItemFlags flags = d->model->index(row, j, parent).flags();
1478  if ((flags & Qt::ItemIsSelectable) && (flags & Qt::ItemIsEnabled))
1479  return true;
1480  }
1481  }
1482  }
1483 
1484  return false;
1485 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
Merges the other selection with this QItemSelection using the command given.
int left() const
Returns the column index corresponding to the leftmost selected column in the selection range...
int bottom() const
Returns the row index corresponding to the lowermost selected row in the selection range...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int right() const
Returns the column index corresponding to the rightmost selected column in the selection range...
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
const QAbstractItemModel * model() const
Returns a pointer to the model containing the item that this index refers to.
bool isValid() const
Returns true if this model index is valid; otherwise returns false.
The QItemSelection class manages information about selected items in a model.
int top() const
Returns the row index corresponding to the uppermost selected row in the selection range...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ select [1/2]

void QItemSelectionModel::select ( const QModelIndex index,
QItemSelectionModel::SelectionFlags  command 
)
virtualslot

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

See also
QItemSelectionModel::SelectionFlags

Definition at line 1072 of file qitemselectionmodel.cpp.

Referenced by QColumnViewPrivate::_q_changeCurrentColumn(), clearSelection(), QAccessibleItemRow::doAction(), QComboBox::hidePopup(), QAccessibleItemRow::navigate(), QColumnView::selectAll(), QAbstractItemViewPrivate::selectAll(), QListViewPrivate::selectAll(), QAccessibleTable2::selectColumn(), QAccessibleItemView::selectColumn(), QTableViewPrivate::selectColumn(), QAccessibleTable2::selectRow(), QAccessibleTree::selectRow(), QAccessibleItemView::selectRow(), QTableViewPrivate::selectRow(), QSidebar::selectUrl(), setCurrentIndex(), QListWidget::setItemSelected(), QTableWidget::setItemSelected(), QTreeWidget::setItemSelected(), QTableWidget::setRangeSelected(), QAccessibleTable2::unselectColumn(), QAccessibleItemView::unselectColumn(), QAccessibleTable2::unselectRow(), and QAccessibleItemView::unselectRow().

1073 {
1074  QItemSelection selection(index, index);
1075  select(selection, command);
1076 }
const QItemSelection selection() const
Returns the selection ranges stored in the selection model.
The QItemSelection class manages information about selected items in a model.
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().

◆ select [2/2]

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

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

See also
QItemSelectionModel::SelectionFlag

Definition at line 1168 of file qitemselectionmodel.cpp.

1169 {
1171  if (command == NoUpdate)
1172  return;
1173 
1174  // store old selection
1175  QItemSelection sel = selection;
1176  // If d->ranges is non-empty when the source model is reset the persistent indexes
1177  // it contains will be invalid. We can't clear them in a modelReset slot because that might already
1178  // be too late if another model observer is connected to the same modelReset slot and is invoked first
1179  // it might call select() on this selection model before any such QItemSelectionModelPrivate::_q_modelReset() slot
1180  // is invoked, so it would not be cleared yet. We clear it invalid ranges in it here.
1181  QItemSelection::iterator it = d->ranges.begin();
1182  while (it != d->ranges.end()) {
1183  if (!it->isValid())
1184  it = d->ranges.erase(it);
1185  else
1186  ++it;
1187  }
1188 
1189  QItemSelection old = d->ranges;
1190  old.merge(d->currentSelection, d->currentCommand);
1191 
1192  // expand selection according to SelectionBehavior
1193  if (command & Rows || command & Columns)
1194  sel = d->expandSelection(sel, command);
1195 
1196  // clear ranges and currentSelection
1197  if (command & Clear) {
1198  d->ranges.clear();
1199  d->currentSelection.clear();
1200  }
1201 
1202  // merge and clear currentSelection if Current was not set (ie. start new currentSelection)
1203  if (!(command & Current))
1204  d->finalize();
1205 
1206  // update currentSelection
1207  if (command & Toggle || command & Select || command & Deselect) {
1208  d->currentCommand = command;
1209  d->currentSelection = sel;
1210  }
1211 
1212  // generate new selection, compare with old and emit selectionChanged()
1213  QItemSelection newSelection = d->ranges;
1214  newSelection.merge(d->currentSelection, d->currentCommand);
1215  emitSelectionChanged(newSelection, old);
1216 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
Merges the other selection with this QItemSelection using the command given.
#define it(className, varName)
const QItemSelection selection() const
Returns the selection ranges stored in the selection model.
void emitSelectionChanged(const QItemSelection &newSelection, const QItemSelection &oldSelection)
Compares the two selections newSelection and oldSelection and emits selectionChanged() with the desel...
#define Q_D(Class)
Definition: qglobal.h:2482
friend class iterator
Definition: qlist.h:226
The QItemSelection class manages information about selected items in a model.

◆ selectedColumns()

QModelIndexList QItemSelectionModel::selectedColumns ( int  row = 0) const

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

Since
4.2
See also
selectedIndexes(), selectedRows()

Definition at line 1594 of file qitemselectionmodel.cpp.

Referenced by QTableViewPrivate::selectColumn(), QAccessibleTable2::selectedColumnCount(), QAccessibleItemView::selectedColumnCount(), and QAccessibleItemView::selectedColumns().

1595 {
1596  QModelIndexList indexes;
1597  //the QSet contains pairs of parent modelIndex
1598  //and column number
1599  QSet< QPair<QModelIndex, int> > columnsSeen;
1600 
1601  const QItemSelection ranges = selection();
1602  for (int i = 0; i < ranges.count(); ++i) {
1603  const QItemSelectionRange &range = ranges.at(i);
1604  QModelIndex parent = range.parent();
1605  for (int column = range.left(); column <= range.right(); column++) {
1606  QPair<QModelIndex, int> columnDef = qMakePair(parent, column);
1607  if (!columnsSeen.contains(columnDef)) {
1608  columnsSeen << columnDef;
1609  if (isColumnSelected(column, parent)) {
1610  indexes.append(model()->index(row, column, parent));
1611  }
1612  }
1613  }
1614  }
1615 
1616  return indexes;
1617 }
int left() const
Returns the column index corresponding to the leftmost selected column in the selection range...
bool isColumnSelected(int column, const QModelIndex &parent) const
Returns true if all items are selected in the column with the given parent.
The QItemSelectionRange class manages information about a range of selected items in a model...
const QItemSelection selection() const
Returns the selection ranges stored in the selection model.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
int right() const
Returns the column index corresponding to the rightmost selected column in the selection range...
QModelIndex parent() const
Returns the parent model item index of the items in the selection range.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool contains(const T &value) const
Definition: qset.h:91
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QItemSelection class manages information about selected items in a model.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
The QModelIndex class is used to locate data in a data model.
const QAbstractItemModel * model() const
Returns the item model operated on by the selection model.
quint16 index

◆ selectedIndexes()

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

Referenced by QSidebar::removeEntry(), QColumnView::selectAll(), QAccessibleTable2::selectedCellCount(), QTreeView::selectedIndexes(), QListWidget::selectedItems(), QTableWidget::selectedItems(), and QTreeWidget::selectedItems().

1542 {
1543  Q_D(const QItemSelectionModel);
1544  QItemSelection selected = d->ranges;
1545  selected.merge(d->currentSelection, d->currentCommand);
1546  return selected.indexes();
1547 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
Merges the other selection with this QItemSelection using the command given.
#define Q_D(Class)
Definition: qglobal.h:2482
The QItemSelection class manages information about selected items in a model.
QModelIndexList indexes() const
Returns a list of model indexes that correspond to the selected items.

◆ selectedRows()

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

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

Since
4.2
See also
selectedIndexes(), selectedColumns()

Definition at line 1559 of file qitemselectionmodel.cpp.

Referenced by QInputDialogPrivate::listViewText(), QAccessibleTable2::selectedRowCount(), QAccessibleItemView::selectedRowCount(), QAccessibleItemView::selectedRows(), and QTableViewPrivate::selectRow().

1560 {
1561  QModelIndexList indexes;
1562  //the QSet contains pairs of parent modelIndex
1563  //and row number
1564  QSet< QPair<QModelIndex, int> > rowsSeen;
1565 
1566  const QItemSelection ranges = selection();
1567  for (int i = 0; i < ranges.count(); ++i) {
1568  const QItemSelectionRange &range = ranges.at(i);
1569  QModelIndex parent = range.parent();
1570  for (int row = range.top(); row <= range.bottom(); row++) {
1571  QPair<QModelIndex, int> rowDef = qMakePair(parent, row);
1572  if (!rowsSeen.contains(rowDef)) {
1573  rowsSeen << rowDef;
1574  if (isRowSelected(row, parent)) {
1575  indexes.append(model()->index(row, column, parent));
1576  }
1577  }
1578  }
1579  }
1580 
1581  return indexes;
1582 }
The QItemSelectionRange class manages information about a range of selected items in a model...
const QItemSelection selection() const
Returns the selection ranges stored in the selection model.
int bottom() const
Returns the row index corresponding to the lowermost selected row in the selection range...
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QModelIndex parent() const
Returns the parent model item index of the items in the selection range.
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool contains(const T &value) const
Definition: qset.h:91
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QItemSelection class manages information about selected items in a model.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
Q_OUTOFLINE_TEMPLATE QPair< T1, T2 > qMakePair(const T1 &x, const T2 &y)
Definition: qpair.h:102
The QModelIndex class is used to locate data in a data model.
const QAbstractItemModel * model() const
Returns the item model operated on by the selection model.
quint16 index
int top() const
Returns the row index corresponding to the uppermost selected row in the selection range...
bool isRowSelected(int row, const QModelIndex &parent) const
Returns true if all items are selected in the row with the given parent.

◆ selection()

const QItemSelection QItemSelectionModel::selection ( ) const

Returns the selection ranges stored in the selection model.

Definition at line 1622 of file qitemselectionmodel.cpp.

Referenced by QAbstractItemViewPrivate::clearOrRemove(), QComboBox::hidePopup(), QAccessibleItemRow::navigate(), select(), selectedColumns(), QTableWidget::selectedRanges(), selectedRows(), and QTreeWidget::setSelectionModel().

1623 {
1624  Q_D(const QItemSelectionModel);
1625  QItemSelection selected = d->ranges;
1626  selected.merge(d->currentSelection, d->currentCommand);
1627  int i = 0;
1628  // make sure we have no invalid ranges
1629  // ### should probably be handled more generic somewhere else
1630  while (i<selected.count()) {
1631  if (selected.at(i).isValid())
1632  ++i;
1633  else
1634  (selected.removeAt(i));
1635  }
1636  return selected;
1637 }
double d
Definition: qnumeric_p.h:62
The QItemSelectionModel class keeps track of a view&#39;s selected items.
void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
Merges the other selection with this QItemSelection using the command given.
bool isValid() const
Returns true if the selection range is valid; otherwise returns false.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
#define Q_D(Class)
Definition: qglobal.h:2482
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QItemSelection class manages information about selected items in a model.
void removeAt(int i)
Removes the item at index position i.
Definition: qlist.h:480

◆ selectionChanged

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.

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.

See also
select() currentChanged()

Referenced by emitSelectionChanged().

◆ setCurrentIndex

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
select()

Definition at line 1271 of file qitemselectionmodel.cpp.

Referenced by QColumnViewPrivate::_q_changeCurrentColumn(), QAbstractItemView::focusInEvent(), QTreeView::keyboardSearch(), QCalendarView::mouseMoveEvent(), QCalendarView::mousePressEvent(), QTableViewPrivate::selectColumn(), QTableViewPrivate::selectRow(), QCompleterPrivate::setCurrentIndex(), QListWidget::setCurrentRow(), QInputDialogPrivate::setListViewText(), QComboBox::showPopup(), QUndoModel::stackChanged(), QCalendarWidgetPrivate::update(), and QCalendarWidgetPrivate::updateCurrentPage().

1272 {
1274  if (index == d->currentIndex) {
1275  if (command != NoUpdate)
1276  select(index, command); // select item
1277  return;
1278  }
1279  QPersistentModelIndex previous = d->currentIndex;
1280  d->currentIndex = index; // set current before emitting selection changed below
1281  if (command != NoUpdate)
1282  select(d->currentIndex, command); // select item
1283  emit currentChanged(d->currentIndex, previous);
1284  if (d->currentIndex.row() != previous.row() ||
1285  d->currentIndex.parent() != previous.parent())
1286  emit currentRowChanged(d->currentIndex, previous);
1287  if (d->currentIndex.column() != previous.column() ||
1288  d->currentIndex.parent() != previous.parent())
1289  emit currentColumnChanged(d->currentIndex, previous);
1290 }
double d
Definition: qnumeric_p.h:62
int row() const
Returns the row this persistent model index refers to.
The QItemSelectionModel class keeps track of a view&#39;s selected items.
int column() const
Returns the column this persistent model index refers to.
#define Q_D(Class)
Definition: qglobal.h:2482
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted if the current item changes and its row is different to the row of the previou...
#define emit
Definition: qobjectdefs.h:76
QModelIndex parent() const
Returns the parent QModelIndex for this persistent index, or an invalid QModelIndex if it has no pare...
The QPersistentModelIndex class is used to locate data in a data model.
virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged().
void currentChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted whenever the current item changes.
void currentColumnChanged(const QModelIndex &current, const QModelIndex &previous)
This signal is emitted if the current item changes and its column is different to the column of the p...
quint16 index

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