QItemSelection 类管理模型选中项的有关信息。 更多...
头: | #include <QItemSelection> |
qmake: | QT += core |
继承: | QList |
QItemSelection (const QModelIndex & topLeft , const QModelIndex & bottomRight ) | |
QItemSelection () | |
bool | contains (const QModelIndex & index ) const |
QModelIndexList | indexes () const |
void | merge (const QItemSelection & other , QItemSelectionModel::SelectionFlags 命令 ) |
void | select (const QModelIndex & topLeft , const QModelIndex & bottomRight ) |
void | split (const QItemSelectionRange & range , const QItemSelectionRange & other , QItemSelection * result ) |
A QItemSelection describes the items in a model that have been selected by the user. A QItemSelection is basically a list of selection ranges, see QItemSelectionRange . It provides functions for creating and manipulating selections, and selecting a range of items from a model.
The QItemSelection class is one of the 模型/视图类 且属于 Qt 的 模型/视图框架 .
An item selection can be constructed and initialized to contain a range of items from an existing model. The following example constructs a selection that contains a range of items from the given
model
, beginning at the
topLeft
, and ending at the
bottomRight
.
QItemSelection *selection = new QItemSelection(topLeft, bottomRight);
An empty item selection can be constructed, and later populated as required. So, if the model is going to be unavailable when we construct the item selection, we can rewrite the above code in the following way:
QItemSelection *selection = new QItemSelection(); ... selection->select(topLeft, bottomRight);
QItemSelection saves memory, and avoids unnecessary work, by working with selection ranges rather than recording the model item index for each item in the selection. Generally, an instance of this class will contain a list of non-overlapping selection ranges.
使用 merge () to merge one item selection into another without making overlapping ranges. Use split () to split one selection range into smaller ranges based on a another selection range.
另请参阅 模型/视图编程 and QItemSelectionModel .
Constructs an item selection that extends from the top-left model item, specified by the topLeft index, to the bottom-right item, specified by bottomRight .
Constructs an empty selection.
返回
true
if the selection contains the given
index
;否则返回
false
.
Returns a list of model indexes that correspond to the selected items.
Merges the other selection with this QItemSelection 使用 命令 given. This method guarantees that no ranges are overlapping.
Note that only QItemSelectionModel::Select , QItemSelectionModel::Deselect ,和 QItemSelectionModel::Toggle are supported.
另请参阅 split ().
Adds the items in the range that extends from the top-left model item, specified by the topLeft index, to the bottom-right item, specified by bottomRight to the list.
注意: topLeft and bottomRight must have the same parent.
[static]
void
QItemSelection::
split
(const
QItemSelectionRange
&
range
, const
QItemSelectionRange
&
other
,
QItemSelection
*
result
)
Splits the selection range using the selection other range. Removes all items in other from range and puts the result in result . This can be compared with the semantics of the subtract operation of a set.
另请参阅 merge ().