QItemSelectionModel 類

The QItemSelectionModel 類保持視圖選中項的跟蹤。 更多...

頭: #include <QItemSelectionModel>
繼承: QObject

公共類型

enum SelectionFlag { NoUpdate, Clear, Select, Deselect, ..., ClearAndSelect }
flags SelectionFlags

公共函數

QItemSelectionModel (QAbstractItemModel * model )
QItemSelectionModel (QAbstractItemModel * model , QObject * parent )
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 QAbstractItemModel * model () const
bool rowIntersectsSelection (int row , const QModelIndex & parent ) const
QModelIndexList selectedColumns (int row = 0) const
QModelIndexList selectedIndexes () const
QModelIndexList selectedRows (int column = 0) const
const QItemSelection selection () const

公共槽

virtual void clear ()
void clearSelection ()
virtual void reset ()
virtual void select (const QModelIndex & index , QItemSelectionModel::SelectionFlags command )
virtual void select (const QItemSelection & selection , QItemSelectionModel::SelectionFlags command )
void setCurrentIndex (const QModelIndex & index , QItemSelectionModel::SelectionFlags command )

信號

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 selectionChanged (const QItemSelection & selected , const QItemSelection & deselected )

保護函數

void emitSelectionChanged (const QItemSelection & newSelection , const QItemSelection & oldSelection )

額外繼承成員

詳細描述

The QItemSelectionModel 類保持視圖選中項的跟蹤。

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 類是一種 模型/視圖類 且屬於 Qt 的 模型/視圖框架 .

選中項使用範圍存儲。每當想要修改選中項時,使用 select () 和提供 QItemSelection ,或 QModelIndex 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).

要更新目前的選中項,使用按位 OR 的 QItemSelectionModel::Current 和任何其它 SelectionFlags 。若省略 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.

另請參閱 模型/視圖編程 , QAbstractItemModel ,和 圖錶範例 .

成員類型文檔編製

enum QItemSelectionModel:: SelectionFlag
flags QItemSelectionModel:: SelectionFlags

此枚舉描述將更新選定模型的方式。

常量 描述
QItemSelectionModel::NoUpdate 0x0000 不會做齣選擇。
QItemSelectionModel::Clear 0x0001 完整選定將被清零。
QItemSelectionModel::Select 0x0002 所有指定索引將被選中。
QItemSelectionModel::Deselect 0x0004 所有指定索引將被取消選擇。
QItemSelectionModel::Toggle 0x0008 所有指定索引將根據它們的當前狀態被選中或取消選擇。
QItemSelectionModel::Current 0x0010 當前選定將被更新。
QItemSelectionModel::Rows 0x0020 將擴展所有索引以跨行。
QItemSelectionModel::Columns 0x0040 將擴展所有索引以跨列。
QItemSelectionModel::SelectCurrent Select | Current Select 和 Current 的組閤,為方便起見提供。
QItemSelectionModel::ToggleCurrent Toggle | Current Toggle 和 Current 的組閤,為方便起見提供。
QItemSelectionModel::ClearAndSelect Clear | Select Clear 和 Select 的組閤,為方便起見提供。

SelectionFlags 類型是 typedef 對於 QFlags <SelectionFlag>。它存儲 SelectionFlag 值的 OR 組閤。

成員函數文檔編製

QItemSelectionModel:: QItemSelectionModel ( QAbstractItemModel * model )

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

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

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

[虛擬] QItemSelectionModel:: ~QItemSelectionModel ()

銷毀選定模型。

[virtual slot] void QItemSelectionModel:: clear ()

清零選定模型。發射 selectionChanged () 和 currentChanged ().

[slot] void QItemSelectionModel:: clearSelection ()

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

該函數在 Qt 4.2 引入。

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

Returns true if there are any items selected in the column 采用給定 parent .

[signal] void QItemSelectionModel:: currentChanged (const QModelIndex & current , const QModelIndex & previous )

此信號被發射每當當前項改變。 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.

另請參閱 currentIndex (), setCurrentIndex (),和 selectionChanged ().

[signal] void QItemSelectionModel:: currentColumnChanged (const QModelIndex & current , const QModelIndex & previous )

此信號發射,若 current item changes and its column is different to the column of the previous 當前項。

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

另請參閱 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.

另請參閱 setCurrentIndex ().

[signal] void QItemSelectionModel:: currentRowChanged (const QModelIndex & current , const QModelIndex & previous )

此信號發射,若 current item changes and its row is different to the row of the previous 當前項。

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

另請參閱 currentChanged (), currentColumnChanged (), currentIndex (),和 setCurrentIndex ().

[protected] void QItemSelectionModel:: emitSelectionChanged (const QItemSelection & newSelection , const QItemSelection & oldSelection )

比較 2 選定 newSelection and oldSelection 並發射 selectionChanged () with the deselected and selected items.

bool QItemSelectionModel:: hasSelection () const

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

該函數在 Qt 4.2 引入。

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

Returns true if all items are selected in the column 采用給定 parent .

Note that this function 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 采用給定 parent .

Note that this function 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 被選中。

const QAbstractItemModel * QItemSelectionModel:: model () const

返迴由選定模型操作的項模型。

[virtual slot] void QItemSelectionModel:: reset ()

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 采用給定 parent .

[virtual slot] void QItemSelectionModel:: select (const QModelIndex & index , QItemSelectionModel::SelectionFlags command )

選擇模型項 index 使用指定 command ,和發射 selectionChanged ().

另請參閱 QItemSelectionModel::SelectionFlags .

[virtual slot] void QItemSelectionModel:: select (const QItemSelection & selection , QItemSelectionModel::SelectionFlags command )

選擇項 selection 使用指定 command ,和發射 selectionChanged ().

另請參閱 QItemSelectionModel::SelectionFlag .

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

返迴的索引在給定 row 對於選中所有行的列而言。

該函數在 Qt 4.2 引入。

另請參閱 selectedIndexes () 和 selectedRows ().

QModelIndexList QItemSelectionModel:: selectedIndexes () const

返迴所有選中模型項索引的列錶。列錶包含的不重復,且未排序。

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

返迴的索引在給定 column 對於選中所有列的行而言。

該函數在 Qt 4.2 引入。

另請參閱 selectedIndexes () 和 selectedColumns ().

const QItemSelection QItemSelectionModel:: selection () const

返迴存儲在選定模型中的選定範圍。

[signal] void QItemSelectionModel:: selectionChanged (const QItemSelection & selected , const QItemSelection & 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 項。

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.

另請參閱 select () 和 currentChanged ().

[slot] void QItemSelectionModel:: setCurrentIndex (const 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.

從屬指定 command index 也可以變為當前選定的一部分。

另請參閱 currentIndex () 和 select ().