com.trolltech.qt.gui
Class QItemSelectionModel

java.lang.Object
  extended by com.trolltech.qt.internal.QSignalEmitterInternal
      extended by com.trolltech.qt.QSignalEmitter
          extended by com.trolltech.qt.QtJambiObject
              extended by com.trolltech.qt.core.QObject
                  extended by com.trolltech.qt.gui.QItemSelectionModel
All Implemented Interfaces:
QtJambiInterface

public class QItemSelectionModel
extends QObject

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 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, and Chart Example.


Nested Class Summary
static class QItemSelectionModel.SelectionFlag
          This enum describes the way the selection model will be updated.
static class QItemSelectionModel.SelectionFlags
           
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.PrivateSignal0, QSignalEmitter.PrivateSignal1, QSignalEmitter.PrivateSignal2, QSignalEmitter.PrivateSignal3, QSignalEmitter.PrivateSignal4, QSignalEmitter.PrivateSignal5, QSignalEmitter.PrivateSignal6, QSignalEmitter.PrivateSignal7, QSignalEmitter.PrivateSignal8, QSignalEmitter.PrivateSignal9, QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9
 
Nested classes/interfaces inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
com.trolltech.qt.internal.QSignalEmitterInternal.AbstractSignalInternal
 
Field Summary
 QSignalEmitter.Signal2 currentChanged
          This signal takes 2 generic argument(s).
 QSignalEmitter.Signal2 currentColumnChanged
          This signal takes 2 generic argument(s).
 QSignalEmitter.Signal2 currentRowChanged
          This signal takes 2 generic argument(s).
 QSignalEmitter.Signal2 selectionChanged
          This signal takes 2 generic argument(s).
 
Fields inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
currentSender
 
Constructor Summary
QItemSelectionModel(QAbstractItemModel model)
          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.
 
Method Summary
 void clear()
          Clears the selection model.
 void clearSelection()
          Clears the selection in the selection model.
 boolean columnIntersectsSelection(int column, com.trolltech.qt.core.QModelIndex parent)
          Returns true if there are any items selected in the column with the given parent.
 com.trolltech.qt.core.QModelIndex currentIndex()
          Returns the model item index for the current item, or an invalid index if there is no current item.
protected  void emitSelectionChanged(QItemSelection newSelection, QItemSelection oldSelection)
          Compares the two selections newSelection and oldSelection and emits selectionChanged() with the deselected and selected items.
 boolean hasSelection()
          Returns true if the selection model contains any selection ranges; otherwise returns false.
 boolean isColumnSelected(int column, com.trolltech.qt.core.QModelIndex parent)
          Returns true if all items are selected in the column with the given parent.
 boolean isRowSelected(int row, com.trolltech.qt.core.QModelIndex parent)
          Returns true if all items are selected in the row with the given parent.
 boolean isSelected(com.trolltech.qt.core.QModelIndex index)
          Returns true if the given model item index is selected.
 QAbstractItemModel model()
          Returns the item model operated on by the selection model.
 void reset()
          Clears the selection model.
 boolean rowIntersectsSelection(int row, com.trolltech.qt.core.QModelIndex parent)
          Returns true if there are any items selected in the row with the given parent.
 void select(QItemSelection selection, QItemSelectionModel.SelectionFlag[] command)
          This is an overloaded method provided for convenience.
 void select(QItemSelection selection, QItemSelectionModel.SelectionFlags command)
          Selects the item selection using the specified command, and emits selectionChanged() .
 void select(com.trolltech.qt.core.QModelIndex index, QItemSelectionModel.SelectionFlag[] command)
          This is an overloaded method provided for convenience.
 void select(com.trolltech.qt.core.QModelIndex index, QItemSelectionModel.SelectionFlags command)
          Selects the model item index using the specified command, and emits selectionChanged() .
 java.util.List selectedColumns()
          Returns the indexes in row 0 for columns where all rows are selected.
 java.util.List selectedColumns(int row)
          Returns the indexes in the given row for columns where all rows are selected.
 java.util.List selectedIndexes()
          Returns a list of all selected model item indexes.
 java.util.List selectedRows()
          Returns the indexes in column 0 for the rows where all columns are selected.
 java.util.List selectedRows(int column)
          Returns the indexes in the given column for the rows where all columns are selected.
 QItemSelection selection()
          Returns the selection ranges stored in the selection model.
 void setCurrentIndex(com.trolltech.qt.core.QModelIndex index, QItemSelectionModel.SelectionFlag[] command)
          This is an overloaded method provided for convenience.
 void setCurrentIndex(com.trolltech.qt.core.QModelIndex index, QItemSelectionModel.SelectionFlags command)
          Sets the model item index to be the current item, and emits currentChanged() .
 
Methods inherited from class com.trolltech.qt.core.QObject
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread
 
Methods inherited from class com.trolltech.qt.internal.QSignalEmitterInternal
__qt_signalInitialization
 
Methods inherited from class java.lang.Object
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

currentChanged

public final QSignalEmitter.Signal2 currentChanged

This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.core.QModelIndex(named: current), com.trolltech.qt.core.QModelIndex(named: previous)>:

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(), and selectionChanged() .


currentColumnChanged

public final QSignalEmitter.Signal2 currentColumnChanged

This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.core.QModelIndex(named: current), com.trolltech.qt.core.QModelIndex(named: previous)>:

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(), and setCurrentIndex().


currentRowChanged

public final QSignalEmitter.Signal2 currentRowChanged

This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.core.QModelIndex(named: current), com.trolltech.qt.core.QModelIndex(named: previous)>:

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(), and setCurrentIndex().


selectionChanged

public final QSignalEmitter.Signal2 selectionChanged

This signal takes 2 generic argument(s). We list their type and the name they go by in the description of this signal. <com.trolltech.qt.gui.QItemSelection(named: selected), com.trolltech.qt.gui.QItemSelection(named: deselected)>:

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(), and currentChanged() .

Constructor Detail

QItemSelectionModel

public QItemSelectionModel(QAbstractItemModel model)
Constructs a selection model that operates on the specified item model.


QItemSelectionModel

public QItemSelectionModel(QAbstractItemModel model,
                           QObject parent)
Constructs a selection model that operates on the specified item model with parent.

Method Detail

clearSelection

public final void clearSelection()
Clears the selection in the selection model. Emits selectionChanged() .


columnIntersectsSelection

public final boolean columnIntersectsSelection(int column,
                                               com.trolltech.qt.core.QModelIndex parent)
Returns true if there are any items selected in the column with the given parent.


currentIndex

public final com.trolltech.qt.core.QModelIndex currentIndex()
Returns the model item index for the current item, or an invalid index if there is no current item.

See also:
setCurrentIndex().


emitSelectionChanged

protected final void emitSelectionChanged(QItemSelection newSelection,
                                          QItemSelection oldSelection)
Compares the two selections newSelection and oldSelection and emits selectionChanged() with the deselected and selected items.


hasSelection

public final boolean hasSelection()
Returns true if the selection model contains any selection ranges; otherwise returns false.


isColumnSelected

public final boolean isColumnSelected(int column,
                                      com.trolltech.qt.core.QModelIndex parent)
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.


isRowSelected

public final boolean isRowSelected(int row,
                                   com.trolltech.qt.core.QModelIndex parent)
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.


isSelected

public final boolean isSelected(com.trolltech.qt.core.QModelIndex index)
Returns true if the given model item index is selected.


model

public final QAbstractItemModel model()
Returns the item model operated on by the selection model.


rowIntersectsSelection

public final boolean rowIntersectsSelection(int row,
                                            com.trolltech.qt.core.QModelIndex parent)
Returns true if there are any items selected in the row with the given parent.


selectedColumns

public final java.util.List selectedColumns()
Returns the indexes in row 0 for columns where all rows are selected.


selectedColumns

public final java.util.List selectedColumns(int row)
Returns the indexes in the given row for columns where all rows are selected.

See also:
selectedIndexes(), and selectedRows().


selectedIndexes

public final java.util.List selectedIndexes()
Returns a list of all selected model item indexes. The list contains no duplicates, and is not sorted.


selectedRows

public final java.util.List selectedRows()
Returns the indexes in column 0 for the rows where all columns are selected.


selectedRows

public final java.util.List selectedRows(int column)
Returns the indexes in the given column for the rows where all columns are selected.

See also:
selectedIndexes(), and selectedColumns().


selection

public final QItemSelection selection()
Returns the selection ranges stored in the selection model.


setCurrentIndex

public final void setCurrentIndex(com.trolltech.qt.core.QModelIndex index,
                                  QItemSelectionModel.SelectionFlag[] command)
This is an overloaded method provided for convenience.


setCurrentIndex

public final void setCurrentIndex(com.trolltech.qt.core.QModelIndex index,
                                  QItemSelectionModel.SelectionFlags command)
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(), and select().


clear

public void clear()
Clears the selection model. Emits selectionChanged() and currentChanged() .


reset

public void reset()
Clears the selection model. Does not emit any signals.


select

public final void select(QItemSelection selection,
                         QItemSelectionModel.SelectionFlag[] command)
This is an overloaded method provided for convenience.


select

public void select(QItemSelection selection,
                   QItemSelectionModel.SelectionFlags command)
Selects the item selection using the specified command, and emits selectionChanged() .

See also:
QItemSelectionModel::SelectionFlag .


select

public final void select(com.trolltech.qt.core.QModelIndex index,
                         QItemSelectionModel.SelectionFlag[] command)
This is an overloaded method provided for convenience.


select

public void select(com.trolltech.qt.core.QModelIndex index,
                   QItemSelectionModel.SelectionFlags command)
Selects the model item index using the specified command, and emits selectionChanged() .

See also:
QItemSelectionModel::SelectionFlags.