QItemSelectionModel 类

QItemSelectionModel 类保持视图选中项的跟踪。 更多...

头: #include <QItemSelectionModel>
qmake: QT += core
实例化: ItemSelectionModel
继承: QObject

公共类型

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

特性

公共函数

QItemSelectionModel (QAbstractItemModel * model = Q_NULLPTR)
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
QAbstractItemModel * model ()
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
void setModel (QAbstractItemModel * model )

公共槽

virtual void clear ()
virtual void clearCurrentIndex ()
void clearSelection ()
virtual void reset ()
virtual void select (const QModelIndex & index , QItemSelectionModel::SelectionFlags command )
virtual void select (const QItemSelection & selection , QItemSelectionModel::SelectionFlags command )
virtual 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 modelChanged (QAbstractItemModel * model )
void selectionChanged (const QItemSelection & selected , const QItemSelection & deselected )

保护函数

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

额外继承成员

详细描述

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.

QItemSelectionModel 类是一种 模型/视图类 且属于 Qt 的 模型/视图框架 .

选中项使用范围存储。每当想要修改选中项时,使用 select () 和提供 QItemSelection ,或 QModelIndex QItemSelectionModel::SelectionFlag .

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 命令,将创建新的当前选定,并将之前的一个添加到整个选定。所有函数都在 2 层上运转;例如, selecteditems() 将从 2 层返回项。

注意: 从 5.5 起, model , hasSelection ,和 currentIndex 是元对象特性。

另请参阅 模型/视图编程 , 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 组合。

特性文档编制

selectedIndexes : const QModelIndexList

该特性在 Qt 5.5 引入。

访问函数:

QModelIndexList selectedIndexes () const

通知程序信号:

void selectionChanged (const QItemSelection & selected , const QItemSelection & deselected )

成员函数文档编制

QItemSelectionModel:: QItemSelectionModel ( QAbstractItemModel * model = Q_NULLPTR)

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 .

[virtual] QItemSelectionModel:: ~QItemSelectionModel ()

销毁选定模型。

[virtual slot] void QItemSelectionModel:: clear ()

清零选定模型。发射 selectionChanged () 和 currentChanged ().

[virtual slot] void QItemSelectionModel:: clearCurrentIndex ()

清零当前索引。发射 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

返回 true 若有选中任何项在 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

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

该函数在 Qt 4.2 引入。

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

返回 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

返回 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

返回 true 若给定模型项 index 被选中。

const QAbstractItemModel *QItemSelectionModel:: model () const

返回由选定模型操作的项模型。

另请参阅 setModel ().

QAbstractItemModel *QItemSelectionModel:: model ()

返回由选定模型操作的项模型。

该函数在 Qt 5.5 引入。

[signal] void QItemSelectionModel:: modelChanged ( QAbstractItemModel * model )

此信号被发射当 model is successfully set with setModel ().

该函数在 Qt 5.5 引入。

另请参阅 model () 和 setModel ().

[virtual slot] void QItemSelectionModel:: reset ()

Clears the selection model. Does not emit any signals.

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

返回 true 若有选中任何项在 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

返回所有选中模型项索引的列表。列表包含的不重复,且未排序。

注意: Getter 函数对于特性 selectedIndexes .

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.

注意: 通知程序信号对于特性 selectedIndexes .

另请参阅 select () 和 currentChanged ().

[virtual 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 ().

void QItemSelectionModel:: setModel ( QAbstractItemModel * model )

将模型设为 model modelChanged () 信号会被发射。

该函数在 Qt 5.5 引入。

另请参阅 model () 和 modelChanged ().