QAbstractItemModel Class
The QAbstractItemModel class provides the abstract interface for item model classes. 更多...
头文件: | #include <QAbstractItemModel> |
qmake: | QT += core |
基类: | QObject |
派生类: | QAbstractListModel, QAbstractProxyModel, and QAbstractTableModel |
公有类型
enum | LayoutChangeHint { NoLayoutChangeHint, VerticalSortHint, HorizontalSortHint } |
公有函数
QAbstractItemModel(QObject *parent = Q_NULLPTR) | |
virtual | ~QAbstractItemModel() |
virtual QModelIndex | buddy(const QModelIndex &index) const |
virtual bool | canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const |
virtual bool | canFetchMore(const QModelIndex &parent) const |
virtual int | columnCount(const QModelIndex &parent = QModelIndex()) const = 0 |
virtual QVariant | data(const QModelIndex &index, int role = Qt::DisplayRole) const = 0 |
virtual bool | dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) |
virtual void | fetchMore(const QModelIndex &parent) |
virtual Qt::ItemFlags | flags(const QModelIndex &index) const |
virtual bool | hasChildren(const QModelIndex &parent = QModelIndex()) const |
bool | hasIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const |
virtual QVariant | headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const |
virtual QModelIndex | index(int row, int column, const QModelIndex &parent = QModelIndex()) const = 0 |
bool | insertColumn(int column, const QModelIndex &parent = QModelIndex()) |
virtual bool | insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) |
bool | insertRow(int row, const QModelIndex &parent = QModelIndex()) |
virtual bool | insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) |
virtual QMap<int, QVariant> | itemData(const QModelIndex &index) const |
virtual QModelIndexList | match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags( Qt::MatchStartsWith | Qt::MatchWrap )) const |
virtual QMimeData * | mimeData(const QModelIndexList &indexes) const |
virtual QStringList | mimeTypes() const |
bool | moveColumn(const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild) |
virtual bool | moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild) |
bool | moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild) |
virtual bool | moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) |
virtual QModelIndex | parent(const QModelIndex &index) const = 0 |
bool | removeColumn(int column, const QModelIndex &parent = QModelIndex()) |
virtual bool | removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) |
bool | removeRow(int row, const QModelIndex &parent = QModelIndex()) |
virtual bool | removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) |
virtual QHash<int, QByteArray> | roleNames() const |
virtual int | rowCount(const QModelIndex &parent = QModelIndex()) const = 0 |
virtual bool | setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) |
virtual bool | setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) |
virtual bool | setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) |
virtual QModelIndex | sibling(int row, int column, const QModelIndex &index) const |
virtual void | sort(int column, Qt::SortOrder order = Qt::AscendingOrder) |
virtual QSize | span(const QModelIndex &index) const |
virtual Qt::DropActions | supportedDragActions() const |
virtual Qt::DropActions | supportedDropActions() const |
- 32 个公有函数继承自 QObject
公有槽函数
- 1 个公有槽函数继承自 QObject
信号
void | columnsAboutToBeInserted(const QModelIndex &parent, int first, int last) |
void | columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn) |
void | columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last) |
void | columnsInserted(const QModelIndex &parent, int first, int last) |
void | columnsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column) |
void | columnsRemoved(const QModelIndex &parent, int first, int last) |
void | dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int> ()) |
void | headerDataChanged(Qt::Orientation orientation, int first, int last) |
void | layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex> (), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint) |
void | layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex> (), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint) |
void | modelAboutToBeReset() |
void | modelReset() |
void | rowsAboutToBeInserted(const QModelIndex &parent, int start, int end) |
void | rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) |
void | rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last) |
void | rowsInserted(const QModelIndex &parent, int first, int last) |
void | rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) |
void | rowsRemoved(const QModelIndex &parent, int first, int last) |
- 2 个信号继承自 QObject
受保护的函数
void | beginInsertColumns(const QModelIndex &parent, int first, int last) |
void | beginInsertRows(const QModelIndex &parent, int first, int last) |
bool | beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild) |
bool | beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild) |
void | beginRemoveColumns(const QModelIndex &parent, int first, int last) |
void | beginRemoveRows(const QModelIndex &parent, int first, int last) |
void | beginResetModel() |
void | changePersistentIndex(const QModelIndex &from, const QModelIndex &to) |
void | changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to) |
QModelIndex | createIndex(int row, int column, void *ptr = Q_NULLPTR) const |
QModelIndex | createIndex(int row, int column, quintptr id) const |
void | endInsertColumns() |
void | endInsertRows() |
void | endMoveColumns() |
void | endMoveRows() |
void | endRemoveColumns() |
void | endRemoveRows() |
void | endResetModel() |
QModelIndexList | persistentIndexList() const |
- 9 个受保护的函数继承自 QObject
Protected Slots
void | resetInternalData() |
其他继承的成员
详细描述
QAbstractItemModel 类为item模型类提供了抽象接口.
QAbstractItemModel 定义了item模型与模型/视图体系结构中的其他组件进行交互操作时必须使用的标准接口. 你应该子类化该类创建新的模型, 而不是直接实例化使用.
QAbstractItemModel 是 Model/View Classes 中的一个, 也是 Qt的 model/view framework的一部分. 它可以用作 QML 中的item视图元素或 Qt Widgets 模块中的item视图类的底层数据模型.
如果需要一个模型来使用item视图, 比如 QML 的 List View 元素或者 C++ widget 的 QListView, QTableView, 你应该考虑子类化 QAbstractListModel 或 QAbstractTableModel, 而不是使用该类.
底层数据模型作为表的层次结构暴露给视图和委托. 如果不使用层次结构, 那么模型就是一个简单的具有行和列的表. 每个item都有一个由 QModelIndex 指定的惟一索引.
每个数据item都可以通过包含一个关联的模型索引的模型进行访问. 该索引可以通过 index() 函数获得. 每个索引可能有一个 sibling() 索引; 子 item 有一个 parent() 索引.
每个 item 都有许多与之关联的数据元素, 可以通过为模型的 data() 函数指定一个角色 (参见 Qt::ItemDataRole) 检索它们. 可以使用 itemData() 函数同时获取所有可用角色的数据.
使用特定的 Qt::ItemDataRole 设置每个角色的数据. 可以使用 setData() 单独设置各个角色的数据, 也可以使用 setItemData() 设置所有角色的数据.
可以使用 flags() (参见 Qt::ItemFlag), 以查看是否可以通过其他方式选择, 拖动或操纵它们.
如果item具有子对象, 则 hasChildren() 为相应的索引返回 true
.
该模型在层次结构的每个级别都有一个 rowCount() 和 columnCount(). 可以使用 insertRows(), insertColumns(), removeRows(), removeColumns() 插入和删除行和列.
模型发出信号以指示变化. 例如, 只要模型可用的数据项发生更改, 就会发出dataChanged() 信号. 改变模型的标题会发出 headerDataChanged() 信号. 如果底层数据的结构发生了变化, 则模型可以发出 layoutChanged() 来向任何附加的视图指示它们应该重新显示所显示的任何项, 并需要考虑到新的结构.
可以使用 match() 函数在模型中搜索可用的项以查找特定数据.
要对模型进行排序, 可以使用 sort().
子类化
注意: 在 Model Subclassing Reference 中有一些关于模型子类化的通用指南.
子类化 QAbstractItemModel 时, 至少必须实现 index(), parent(), rowCount(), columnCount(), data(). 这些函数在所有的只读模型中使用, 同样也构成了可编辑模型的基础.
还可以为模型重新实现 hasChildren() 来提供特殊的行为, 而不是重新实现成本很高的 rowCount(). 这使得模型可以限制视图请求的数据量, 并且可以作为实现模型数据的惰性填充的一种方式.
要在模型中启用编辑, 还必须实现 setData() 和重新实现 flags(), 以确保返回 ItemIsEditable
. 你还可以重新实现 headerData() 和 setHeaderData() 来控制呈现模型标题的方式.
当分别重新实现setData() 和 setHeaderData()函数时, 必须显式发出 dataChanged() 和 headerDataChanged() 信号.
定制模型需要创建模型索引以供其他组件使用. 为此, 请使用适当的行号和列号以及相应的标识符调用 createIndex(), 并将其作为指针或整数值. 这些item的组合对于每个项都必须是唯一的. 定制模型通常在其他重新实现的函数中使用这些唯一标识符, 以检索项数据并访问有关该item的parent和child的信息. 有关唯一标识符的更多信息, 请参见 Simple Tree Model Example 示例.
不必支持 Qt::ItemDataRole 中定义的每个角色. 根据模型中包含的数据类型, 可能只有实现 data() 函数以返回一些更常见角色的有效信息才有用. 大多数模型至少为 Qt::DisplayRole 提供item数据的文本表示, 行为良好的模型也应为 Qt::ToolTipRole 和 Qt::WhatsThisRole 提供有效信息. 支持这些角色可使模型与标准 Qt 视图一起使用. 但是, 对于某些处理高度专业化数据的模型, 仅为用户定义的角色提供数据可能是合适的.
提供可调整数据结构大小的接口的模型可以提供 insertRows(), removeRows(), insertColumns(), removeColumns() 的实现. 在实现这些函数时, 重要的是要在模型尺寸大小发生 之前 和 之后 将有关模型尺寸的更改通知所有连接的视图:
- insertRows() 的实现必须在将新行插入数据结构 之前 调用 beginInsertRows(), 然后 立即 调用 endInsertRows().
- insertColumns() 的实现必须在将新列插入数据结构 之前 调用 beginInsertColumns(), 然后 立即 调用 endInsertColumns().
- removeRows() 的实现必须在从数据结构中删除行 之前 调用 beginRemoveRows(), 然后 立即 调用 endRemoveRows().
- removeColumns() 的实现必须在列从数据结构中删除 之前 调用 beginRemoveColumns(), 然后 立即 调用 endRemoveColumns().
这些函数发出的私有信号使附加组件有机会在任何数据变得不可用之前采取行动. 使用这些 begin 和 end 函数封装插入和删除操作还使模型能够正确地管理 persistent model indexes. 如果希望正确处理选择, 则必须确保调用了这些函数. 如果插入或移除带有child的itme, 则不需要为子item调用这些函数. 换句话说, 父item将管理其子item.
要创建增量填充的模型, 可以重新实现 fetchMore() 和 canFetchMore(). 如果 fetchMore() 的重新实现向模型中添加了行, 则必须调用 beginInsertRows() 和 endInsertRows().
参见 Model Classes, Model Subclassing Reference, QModelIndex, QAbstractItemView, Using drag and drop with item views, Simple DOM Model Example, Simple Tree Model Example, Editable Tree Model Example, Fetch More Example.
成员类型
enum QAbstractItemModel::LayoutChangeHint
这个枚举描述了模型更改布局的方式.
Constant | Value | Description |
---|---|---|
QAbstractItemModel::NoLayoutChangeHint | 0 | No hint is available. |
QAbstractItemModel::VerticalSortHint | 1 | Rows are being sorted. |
QAbstractItemModel::HorizontalSortHint | 2 | Columns are being sorted. |
注意: VerticalSortHint 和 HorizontalSortHint 的含义是item在同一父级中移动, 而不是移动到模型中的不同父级, 并且不会被过滤掉或过滤掉.
成员函数
QAbstractItemModel::QAbstractItemModel(QObject *parent = Q_NULLPTR)
构造函数, parent 是父对象.
[virtual]
QAbstractItemModel::~QAbstractItemModel()
析构函数.
[protected]
void QAbstractItemModel::beginInsertColumns(const QModelIndex &parent, int first, int last)
开始一个列插入操作.
在子类中重新实现 insertColumns() 时, 你必须在将数据插入模型的底层数据存储之前调用此函数.
parent 索引对应于插入新列的父索引; first 和 last 是新列插入后的列号.
![]() | Specify the first and last column numbers for the span of columns you want to insert into an item in a model. For example, as shown in the diagram, we insert three columns before column 4, so first is 4 and last is 6: beginInsertColumns(parent, 4, 6); 这将插入三个新列作为列4, 5和6. |
![]() | To append columns, insert them after the last column. For example, as shown in the diagram, we append three columns to a collection of six existing columns (ending in column 5), so first is 6 and last is 8: beginInsertColumns(parent, 6, 8); 这将追加两个新列作为列6, 7和8. |
注意: 此函数发出 columnsAboutToBeInserted() 信号, 在插入数据之前, 已连接的视图(或代理)必须处理该信号. 否则, 视图可能会以无效状态结束.
参见 endInsertColumns().
[protected]
void QAbstractItemModel::beginInsertRows(const QModelIndex &parent, int first, int last)
开始一个行插入操作.
在子类中重新实现 insertRows() 时, 必须在将数据插入模型的底层数据存储之前调用此函数.
Theparent 索引对应于插入新列的父索引; first 和 last 是新行插入后的行号.
![]() | Specify the first and last row numbers for the span of rows you want to insert into an item in a model. For example, as shown in the diagram, we insert three rows before row 2, so first is 2 and last is 4: beginInsertRows(parent, 2, 4); 这将插入三行新行, 即第2, 3和4行. |
![]() | To append rows, insert them after the last row. For example, as shown in the diagram, we append two rows to a collection of 4 existing rows (ending in row 3), so first is 4 and last is 5: beginInsertRows(parent, 4, 5); 这将追加两个新行作为第4行和第5行. |
注意: 此函数发出 rowsAboutToBeInserted() 信号, 在插入数据之前, 已连接的视图(或代理)必须处理该信号. 否则, 视图可能会以无效状态结束.
参见 endInsertRows().
[protected]
bool QAbstractItemModel::beginMoveColumns(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
开始一个列移动操作.
当重新实现子类时, 此方法简化了模型中实体的移动. 此方法负责在模型中移动持久索引, 否则您将需要自己执行此操作. 使用 beginMoveColumns 和 endMoveColumns 是直接发送与 changePersistentIndex 一起的 layoutAboutToBeChanged 和 layoutChanged 的另一种选择.
sourceParent 索引对应于从其移出列的父级; sourceFirst 和 sourceLast 是要移动的列的第一列和最后一列. destinationParent 索引对应于将这些列移入的父级. destinationChild 是要将列移动到的列. 也就是说, sourceParent 中 sourceFirst 列的索引将成为 destinationParent 中的 destinationChild 列, 然后是所有其他列, 直到 sourceLast.
但是, 当在同一父目录下移动列时 (sourceParent 和 destinationParent 是相等的), 这些列将被放置在 destinationChild 索引之前. 也就是说, 如果你希望移动列0和1, 使它们变成列 1 和列 2, destinationChild 应该是 3. 在本例中, 源列 i
(位于 sourceFirst 和 sourceLast之间) 的新索引等于 (destinationChild-sourceLast-1+i)
.
注意, 如果 sourceParent 和 destinationParent 是相同的, 你必须确保 destinationChild 不在 sourceFirst 和 sourceLast + 1 的范围内. 你还必须确保不会尝试将列移动到它自己的子列或祖先列中. 如果任一条件为真, 此方法将返回 false
, 在这种情况下, 应中止移动操作.
This function was introduced in Qt 4.6.
参见 endMoveColumns().
[protected]
bool QAbstractItemModel::beginMoveRows(const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationChild)
开始一个行移动操作.
When reimplementing a subclass, this method simplifies moving entities in your model. This method is responsible for moving persistent indexes in the model, which you would otherwise be required to do yourself. Using beginMoveRows and endMoveRows is an alternative to emitting layoutAboutToBeChanged and layoutChanged directly along with changePersistentIndex.
The sourceParent index corresponds to the parent from which the rows are moved; sourceFirst and sourceLast are the first and last row numbers of the rows to be moved. The destinationParent index corresponds to the parent into which those rows are moved. The destinationChild is the row to which the rows will be moved. That is, the index at row sourceFirst in sourceParent will become row destinationChild in destinationParent, followed by all other rows up to sourceLast.
However, when moving rows down in the same parent (sourceParent and destinationParent are equal), the rows will be placed before the destinationChild index. That is, if you wish to move rows 0 and 1 so they will become rows 1 and 2, destinationChild should be 3. In this case, the new index for the source row i
(which is between sourceFirst and sourceLast) is equal to (destinationChild-sourceLast-1+i)
.
Note that if sourceParent and destinationParent are the same, you must ensure that the destinationChild is not within the range of sourceFirst and sourceLast + 1. You must also ensure that you do not attempt to move a row to one of its own children or ancestors. This method returns false
if either condition is true, in which case you should abort your move operation.
![]() | Specify the first and last row numbers for the span of rows in the source parent you want to move in the model. Also specify the row in the destination parent to move the span to. For example, as shown in the diagram, we move three rows from row 2 to 4 in the source, so sourceFirst is 2 and sourceLast is 4. We move those items to above row 2 in the destination, so destinationChild is 2. beginMoveRows(sourceParent, 2, 4, destinationParent, 2); This moves the three rows rows 2, 3, and 4 in the source to become 2, 3 and 4 in the destination. Other affected siblings are displaced accordingly. |
![]() | To append rows to another parent, move them to after the last row. For example, as shown in the diagram, we move three rows to a collection of 6 existing rows (ending in row 5), so destinationChild is 6: beginMoveRows(sourceParent, 2, 4, destinationParent, 6); This moves the target rows to the end of the target parent as 6, 7 and 8. |
![]() | To move rows within the same parent, specify the row to move them to. For example, as shown in the diagram, we move one item from row 2 to row 0, so sourceFirst and sourceLast are 2 and destinationChild is 0. beginMoveRows(parent, 2, 2, parent, 0); Note that other rows may be displaced accordingly. Note also that when moving items within the same parent you should not attempt invalid or no-op moves. In the above example, item 2 is at row 2 before the move, so it can not be moved to row 2 (where it is already) or row 3 (no-op as row 3 means above row 3, where it is already) |
![]() | To move rows within the same parent, specify the row to move them to. For example, as shown in the diagram, we move one item from row 2 to row 4, so sourceFirst and sourceLast are 2 and destinationChild is 4. beginMoveRows(parent, 2, 2, parent, 4); Note that other rows may be displaced accordingly. |
This function was introduced in Qt 4.6.
参见 endMoveRows().
[protected]
void QAbstractItemModel::beginRemoveColumns(const QModelIndex &parent, int first, int last)
开始一个列移除操作.
When reimplementing removeColumns() in a subclass, you must call this function before removing data from the model's underlying data store.
The parent index corresponds to the parent from which the new columns are removed; first and last are the column numbers of the first and last columns to be removed.
![]() | Specify the first and last column numbers for the span of columns you want to remove from an item in a model. For example, as shown in the diagram, we remove the three columns from column 4 to column 6, so first is 4 and last is 6: beginRemoveColumns(parent, 4, 6); |
注意: This function emits the columnsAboutToBeRemoved() signal which connected views (or proxies) must handle before the data is removed. Otherwise, the views may end up in an invalid state.
参见 endRemoveColumns().
[protected]
void QAbstractItemModel::beginRemoveRows(const QModelIndex &parent, int first, int last)
开始一个行移除操作.
When reimplementing removeRows() in a subclass, you must call this function before removing data from the model's underlying data store.
The parent index corresponds to the parent from which the new rows are removed; first and last are the row numbers of the rows to be removed.
![]() | Specify the first and last row numbers for the span of rows you want to remove from an item in a model. For example, as shown in the diagram, we remove the two rows from row 2 to row 3, so first is 2 and last is 3: beginRemoveRows(parent, 2, 3); |
注意: This function emits the rowsAboutToBeRemoved() signal which connected views (or proxies) must handle before the data is removed. Otherwise, the views may end up in an invalid state.
参见 endRemoveRows().
[protected]
void QAbstractItemModel::beginResetModel()
开始模型重置操作.
A reset operation resets the model to its current state in any attached views.
注意: Any views attached to this model will be reset as well.
When a model is reset it means that any previous data reported from the model is now invalid and has to be queried for again. This also means that the current item and any selected items will become invalid.
When a model radically changes its data it can sometimes be easier to just call this function rather than emit dataChanged() to inform other components when the underlying data source, or its structure, has changed.
You must call this function before resetting any internal data structures in your model or proxy model.
This function emits the signal modelAboutToBeReset().
This function was introduced in Qt 4.6.
参见 modelAboutToBeReset(), modelReset(), and endResetModel().
[virtual]
QModelIndex QAbstractItemModel::buddy(const QModelIndex &index) const
Returns a model index for the buddy of the item represented by index. When the user wants to edit an item, the view will call this function to check whether another item in the model should be edited instead. Then, the view will construct a delegate using the model index returned by the buddy item.
The default implementation of this function has each item as its own buddy.
[virtual]
bool QAbstractItemModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
Returns true
if a model can accept a drop of the data. This default implementation only checks if data has at least one format in the list of mimeTypes() and if action is among the model's supportedDropActions().
Reimplement this function in your custom model, if you want to test whether the data can be dropped at row, column, parent with action. If you don't need that test, it is not necessary to reimplement this function.
参见 dropMimeData() and Using drag and drop with item views.
[virtual]
bool QAbstractItemModel::canFetchMore(const QModelIndex &parent) const
Returns true
if there is more data available for parent; otherwise returns false
.
The default implementation always returns false
.
If canFetchMore() returns true
, the fetchMore() function should be called. This is the behavior of QAbstractItemView, for example.
参见 fetchMore().
[protected]
void QAbstractItemModel::changePersistentIndex(const QModelIndex &from, const QModelIndex &to)
Changes the QPersistentModelIndex that is equal to the given from model index to the given to model index.
If no persistent model index equal to the given from model index was found, nothing is changed.
参见 persistentIndexList() and changePersistentIndexList().
[protected]
void QAbstractItemModel::changePersistentIndexList(const QModelIndexList &from, const QModelIndexList &to)
Changes the {QPersistentModelIndex}es that are equal to the indexes in the given from model index list to the given to model index list.
If no persistent model indexes equal to the indexes in the given from model index list are found, nothing is changed.
This function was introduced in Qt 4.1.
参见 persistentIndexList() and changePersistentIndex().
[pure virtual]
int QAbstractItemModel::columnCount(const QModelIndex &parent = QModelIndex()) const
Returns the number of columns for the children of the given parent.
In most subclasses, the number of columns is independent of the parent.
For example:
int DomModel::columnCount(const QModelIndex &/*parent*/) const { return 3; }
注意: When implementing a table based model, columnCount() should return 0 when the parent is valid.
参见 rowCount().
[signal]
void QAbstractItemModel::columnsAboutToBeInserted(const QModelIndex &parent, int first, int last)
在将列插入模型之前就发出此信号. 新item将位于给定父item下的首尾之间.
注意: 连接到这个信号的组件使用它来适应模型尺寸的变化. 它只能由 QAbstractItemModel 的实现发出, 不能在子类代码中显式发出.
注意: 这是一个私有信号. 它可以用于信号连接, 但不能由用户发出.
参见 insertColumns() 和 beginInsertColumns().
[signal]
void QAbstractItemModel::columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
模型中的列被移动之前发出该信号. 将要移动的item是在给定sourceParent下在 sourceStart 和 sourceEnd 之间(包括首尾)的item. 它们将从 destinationParent 列开始移动到 destinationColumn.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化. 它只能由 QAbstractItemModel 实现发出, 不能在子类代码中显式发出.
This function was introduced in Qt 4.6.
注意: 这是一个私有信号. 它可以用于信号连接, 但不能由用户发出.
参见 beginMoveRows().
[signal]
void QAbstractItemModel::columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
模型中的列被移除之前发出该信号. 将要移除的item是在给定 parent 下在 first and last 之间(包括首尾)的item.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化. 它只能由 QAbstractItemModel 实现发出, 不能在子类代码中显式发出.
注意: 这是一个私有信号. 它可以用于信号连接, 但不能由用户发出.
参见 removeColumns() 和 beginRemoveColumns().
[signal]
void QAbstractItemModel::columnsInserted(const QModelIndex &parent, int first, int last)
将列插入到模型之后发出该信号. 新的item是在给定 parent 下在 first 和 last 之间(包括首尾)的item.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化. 它只能由 QAbstractItemModel 实现发出, 不能在子类代码中显式发出.
注意: 这是一个私有信号. 它可以用于信号连接, 但不能由用户发出.
参见 insertColumns() 和 beginInsertColumns().
[signal]
void QAbstractItemModel::columnsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int column)
模型中的列被移动之后发出这个信号. 新的item是在给定 parent 下, 在 start 和 end 之间(包括首尾)的item. 它们将从 column 列开始移动到 destination.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化. 它只能由 QAbstractItemModel 实现发出, 不能在子类代码中显式发出.
This function was introduced in Qt 4.6.
注意: 这是一个私有信号. 它可以用于信号连接, 但不能由用户发出.
参见 beginMoveRows().
[signal]
void QAbstractItemModel::columnsRemoved(const QModelIndex &parent, int first, int last)
模型中的列被移除之后发出这个信号. 移除的item是在给定 parent 下在 first 和 last 之间(包括首尾)的item.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化. 它只能由 QAbstractItemModel 实现发出, 不能在子类代码中显式发出.
注意: 这是一个私有信号. 它可以用于信号连接, 但不能由用户发出.
参见 removeColumns() 和 beginRemoveColumns().
[protected]
QModelIndex QAbstractItemModel::createIndex(int row, int column, void *ptr = Q_NULLPTR) const
Creates a model index for the given row and column with the internal pointer ptr.
When using a QSortFilterProxyModel, its indexes have their own internal pointer. It is not advisable to access this internal pointer outside of the model. Use the data() function instead.
This function provides a consistent interface that model subclasses must use to create model indexes.
[protected]
QModelIndex QAbstractItemModel::createIndex(int row, int column, quintptr id) const
Creates a model index for the given row and column with the internal identifier, id.
This function provides a consistent interface that model subclasses must use to create model indexes.
参见 QModelIndex::internalId().
[pure virtual]
QVariant QAbstractItemModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const
Returns the data stored under the given role for the item referred to by the index.
注意: If you do not have a value to return, return an invalid QVariant instead of returning 0.
参见 Qt::ItemDataRole, setData(), and headerData().
[signal]
void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int> ())
现有 item 的数据发生改变时发出这个信号.
如果 item 是同一父, 则受影响的item是在 topLeft 和 bottomRight(包含)之间的item. 如果 item 没有相同的父, 则行为是不确定的.
重新实现 setData() 函数时, 必须显示地发出该信号.
可选的 roles 参数可用于指定实际修改了哪些数据角色. Roles 参数中的向量为空, 表示应将所有角色视为已修改. 角色参数中元素的顺序没有任何关联.
参见 headerDataChanged(), setData(), and layoutChanged().
[virtual]
bool QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Handles the data supplied by a drag and drop operation that ended with the given action.
Returns true
if the data and action were handled by the model; otherwise returns false
.
The specified row, column and parent indicate the location of an item in the model where the operation ended. It is the responsibility of the model to complete the action at the correct location.
For instance, a drop action on an item in a QTreeView can result in new items either being inserted as children of the item specified by row, column, and parent, or as siblings of the item.
When row and column are -1 it means that the dropped data should be considered as dropped directly on parent. Usually this will mean appending the data as child items of parent. If row and column are greater than or equal zero, it means that the drop occurred just before the specified row and column in the specified parent.
The mimeTypes() member is called to get the list of acceptable MIME types. This default implementation assumes the default implementation of mimeTypes(), which returns a single default MIME type. If you reimplement mimeTypes() in your custom model to return multiple MIME types, you must reimplement this function to make use of them.
参见 supportedDropActions(), canDropMimeData(), and Using drag and drop with item views.
[protected]
void QAbstractItemModel::endInsertColumns()
Ends a column insertion operation.
When reimplementing insertColumns() in a subclass, you must call this function after inserting data into the model's underlying data store.
参见 beginInsertColumns().
[protected]
void QAbstractItemModel::endInsertRows()
Ends a row insertion operation.
When reimplementing insertRows() in a subclass, you must call this function after inserting data into the model's underlying data store.
参见 beginInsertRows().
[protected]
void QAbstractItemModel::endMoveColumns()
Ends a column move operation.
When implementing a subclass, you must call this function after moving data within the model's underlying data store.
This function was introduced in Qt 4.6.
参见 beginMoveColumns().
[protected]
void QAbstractItemModel::endMoveRows()
Ends a row move operation.
When implementing a subclass, you must call this function after moving data within the model's underlying data store.
This function was introduced in Qt 4.6.
参见 beginMoveRows().
[protected]
void QAbstractItemModel::endRemoveColumns()
Ends a column removal operation.
When reimplementing removeColumns() in a subclass, you must call this function after removing data from the model's underlying data store.
参见 beginRemoveColumns().
[protected]
void QAbstractItemModel::endRemoveRows()
Ends a row removal operation.
When reimplementing removeRows() in a subclass, you must call this function after removing data from the model's underlying data store.
参见 beginRemoveRows().
[protected]
void QAbstractItemModel::endResetModel()
Completes a model reset operation.
You must call this function after resetting any internal data structure in your model or proxy model.
This function emits the signal modelReset().
This function was introduced in Qt 4.6.
参见 beginResetModel().
[virtual]
void QAbstractItemModel::fetchMore(const QModelIndex &parent)
Fetches any available data for the items with the parent specified by the parent index.
Reimplement this if you are populating your model incrementally.
The default implementation does nothing.
参见 canFetchMore().
[virtual]
Qt::ItemFlags QAbstractItemModel::flags(const QModelIndex &index) const
Returns the item flags for the given index.
The base class implementation returns a combination of flags that enables the item (ItemIsEnabled
) and allows it to be selected (ItemIsSelectable
).
参见 Qt::ItemFlags.
[virtual]
bool QAbstractItemModel::hasChildren(const QModelIndex &parent = QModelIndex()) const
Returns true
if parent has any children; otherwise returns false
.
Use rowCount() on the parent to find out the number of children.
Note that it is undefined behavior to report that a particular index hasChildren with this method if the same index has the flag Qt::ItemNeverHasChildren set.
bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent = QModelIndex()) const
Returns true
if the model returns a valid QModelIndex for row and column with parent, otherwise returns false
.
[virtual]
QVariant QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
Returns the data for the given role and section in the header with the specified orientation.
For horizontal headers, the section number corresponds to the column number. Similarly, for vertical headers, the section number corresponds to the row number.
参见 Qt::ItemDataRole, setHeaderData(), and QHeaderView.
[signal]
void QAbstractItemModel::headerDataChanged(Qt::Orientation orientation, int first, int last)
当标题改变时发出该信号. orientation 表示是横向标题还是竖向标题发生了改变. 标题中从 first 到 last 的部分需要更新.
重新实现 setHeaderData() 函数时, 必须显示地发出该信号.
如果要更改列数或行数, 则不需要发出此信号, 而可以使用 begin/end 函数 (有关子类化部分, 详见 QAbstractItemModel).
参见 headerData(), setHeaderData(), dataChanged().
[pure virtual]
QModelIndex QAbstractItemModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const
Returns the index of the item in the model specified by the given row, column and parent index.
When reimplementing this function in a subclass, call createIndex() to generate model indexes that other components can use to refer to items in your model.
参见 createIndex().
bool QAbstractItemModel::insertColumn(int column, const QModelIndex &parent = QModelIndex())
Inserts a single column before the given column in the child items of the parent specified.
Returns true
if the column is inserted; otherwise returns false
.
参见 insertColumns(), insertRow(), and removeColumn().
[virtual]
bool QAbstractItemModel::insertColumns(int column, int count, const QModelIndex &parent = QModelIndex())
On models that support this, inserts count new columns into the model before the given column. The items in each new column will be children of the item represented by the parent model index.
If column is 0, the columns are prepended to any existing columns.
If column is columnCount(), the columns are appended to any existing columns.
If parent has no children, a single row with count columns is inserted.
Returns true
if the columns were successfully inserted; otherwise returns false
.
The base class implementation does nothing and returns false
.
If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide your own API for altering the data.
参见 insertRows(), removeColumns(), beginInsertColumns(), and endInsertColumns().
bool QAbstractItemModel::insertRow(int row, const QModelIndex &parent = QModelIndex())
Inserts a single row before the given row in the child items of the parent specified.
注意: This function calls the virtual method insertRows.
Returns true
if the row is inserted; otherwise returns false
.
参见 insertRows(), insertColumn(), and removeRow().
[virtual]
bool QAbstractItemModel::insertRows(int row, int count, const QModelIndex &parent = QModelIndex())
注意: The base class implementation of this function does nothing and returns false
.
On models that support this, inserts count rows into the model before the given row. Items in the new row will be children of the item represented by the parent model index.
If row is 0, the rows are prepended to any existing rows in the parent.
If row is rowCount(), the rows are appended to any existing rows in the parent.
If parent has no children, a single column with count rows is inserted.
Returns true
if the rows were successfully inserted; otherwise returns false
.
If you implement your own model, you can reimplement this function if you want to support insertions. Alternatively, you can provide your own API for altering the data. In either case, you will need to call beginInsertRows() and endInsertRows() to notify other components that the model has changed.
参见 insertColumns(), removeRows(), beginInsertRows(), and endInsertRows().
[virtual]
QMap<int, QVariant> QAbstractItemModel::itemData(const QModelIndex &index) const
Returns a map with values for all predefined roles in the model for the item at the given index.
Reimplement this function if you want to extend the default behavior of this function to include custom roles in the map.
参见 setItemData(), Qt::ItemDataRole, and data().
[signal]
void QAbstractItemModel::layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex> (), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint)
这个信号会在模型的布局改变之前发出. 连接到这个信号的组件使用它来适应模型布局的变化.
在发出 layoutAboutToBeChanged() 之后, 子类应该更新所有的持久化模型索引.
可选的 parents 参数用于提供更具体的通知关于模型布局的哪些部分正在被改变. 空列表表示对整个模型的布局进行了更改. parents 列表中元素的顺序不重要. 可选的 hint 参数用于提示模型重新布局时都发生了什么.
This function was introduced in Qt 5.0.
参见 layoutChanged() and changePersistentIndex().
[signal]
void QAbstractItemModel::layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex> (), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint)
每当模型公开的item的布局发生变化时, 就会发出这个信号, 例如, 对模型进行排序时. 当视图接收到该信号时, 应更新item的布局来反映此更改.
对 QAbstractItemModel 或 QAbstractProxyModel 子类化时, 请确保在更改项顺序或更改要公开给视图的数据的结构之前发出 layoutAboutToBeChanged() 信号,并在更改布局后发出 layoutChanged() 信号.
可选的 parents 参数用于给出有关模型布局的哪些部分正在更改的具体的通知. 空列表表示更改了整个模型的布局. parents 列表中元素的顺序并不重要. 可选的 hint 参数用于提示模型重新布局时发生的情况.
子类应在发出 layoutChanged() 信号之前更新所有持久模型索引. 换句话说, 当结构改变时:
- 发出 layoutAboutToBeChanged
- 记住将会改变的 QModelIndex
- 更新内部数据
- 调用 changePersistentIndex()
- 发出 layoutChanged
This function was introduced in Qt 5.0.
参见 layoutAboutToBeChanged(), dataChanged(), headerDataChanged(), modelReset(), changePersistentIndex().
[virtual]
QModelIndexList QAbstractItemModel::match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags( Qt::MatchStartsWith | Qt::MatchWrap )) const
Returns a list of indexes for the items in the column of the start index where data stored under the given role matches the specified value. The way the search is performed is defined by the flags given. The list that is returned may be empty. Note also that the order of results in the list may not correspond to the order in the model, if for example a proxy model is used. The order of the results can not be relied upon.
The search begins from the start index, and continues until the number of matching data items equals hits, the search reaches the last row, or the search reaches start again - depending on whether MatchWrap
is specified in flags. If you want to search for all matching items, use hits = -1.
By default, this function will perform a wrapping, string-based comparison on all items, searching for items that begin with the search term specified by value.
注意: The default implementation of this function only searches columns. Reimplement this function to include a different search behavior.
[virtual]
QMimeData *QAbstractItemModel::mimeData(const QModelIndexList &indexes) const
Returns an object that contains serialized items of data corresponding to the list of indexes specified. The format used to describe the encoded data is obtained from the mimeTypes() function. This default implementation uses the default MIME type returned by the default implementation of mimeTypes(). If you reimplement mimeTypes() in your custom model to return more MIME types, reimplement this function to make use of them.
If the list of indexes is empty, or there are no supported MIME types, 0 is returned rather than a serialized empty list.
参见 mimeTypes() and dropMimeData().
[virtual]
QStringList QAbstractItemModel::mimeTypes() const
Returns the list of allowed MIME types. By default, the built-in models and views use an internal MIME type: application/x-qabstractitemmodeldatalist
.
When implementing drag and drop support in a custom model, if you will return data in formats other than the default internal MIME type, reimplement this function to return your list of MIME types.
If you reimplement this function in your custom model, you must also reimplement the member functions that call it: mimeData() and dropMimeData().
参见 mimeData() and dropMimeData().
[signal]
void QAbstractItemModel::modelAboutToBeReset()
调用 beginResetModel() 时, 在模型的内部状态(例如持久模型索引)失效之前发出这个信号.
This function was introduced in Qt 4.2.
注意: 这是一个私有信号. 仅用于信号连接, 而不能由用户发出.
参见 beginResetModel() and modelReset().
[signal]
void QAbstractItemModel::modelReset()
调用 endResetModel() 时, 在模型的内部状态(例如. 持久模型索引)失效之后发出这个信号 .
注意, 如果模型被重置, 则应该认为之前从模型中检索的所有信息都是无效的. 这包括但不限于 rowCount() and columnCount(), flags(), 通过 data()检索的数据, roleNames().
This function was introduced in Qt 4.1.
注意: 这是一个私有信号. 仅用于信号连接, 而不能由用户发出.
参见 endResetModel() and modelAboutToBeReset().
bool QAbstractItemModel::moveColumn(const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild)
On models that support this, moves sourceColumn from sourceParent to destinationChild under destinationParent.
Returns true
if the columns were successfully moved; otherwise returns false
.
参见 moveColumns() and moveRow().
[virtual]
bool QAbstractItemModel::moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild)
On models that support this, moves count columns starting with the given sourceColumn under parent sourceParent to column destinationChild under parent destinationParent.
Returns true
if the columns were successfully moved; otherwise returns false
.
The base class implementation does nothing and returns false
.
If you implement your own model, you can reimplement this function if you want to support moving. Alternatively, you can provide your own API for altering the data.
参见 beginMoveColumns() and endMoveColumns().
bool QAbstractItemModel::moveRow(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild)
On models that support this, moves sourceRow from sourceParent to destinationChild under destinationParent.
Returns true
if the rows were successfully moved; otherwise returns false
.
参见 moveRows() and moveColumn().
[virtual]
bool QAbstractItemModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
On models that support this, moves count rows starting with the given sourceRow under parent sourceParent to row destinationChild under parent destinationParent.
Returns true
if the rows were successfully moved; otherwise returns false
.
The base class implementation does nothing and returns false
.
If you implement your own model, you can reimplement this function if you want to support moving. Alternatively, you can provide your own API for altering the data.
参见 beginMoveRows() and endMoveRows().
[pure virtual]
QModelIndex QAbstractItemModel::parent(const QModelIndex &index) const
Returns the parent of the model item with the given index. If the item has no parent, an invalid QModelIndex is returned.
A common convention used in models that expose tree data structures is that only items in the first column have children. For that case, when reimplementing this function in a subclass the column of the returned QModelIndex would be 0.
When reimplementing this function in a subclass, be careful to avoid calling QModelIndex member functions, such as QModelIndex::parent(), since indexes belonging to your model will simply call your implementation, leading to infinite recursion.
参见 createIndex().
[protected]
QModelIndexList QAbstractItemModel::persistentIndexList() const
Returns the list of indexes stored as persistent indexes in the model.
This function was introduced in Qt 4.2.
bool QAbstractItemModel::removeColumn(int column, const QModelIndex &parent = QModelIndex())
Removes the given column from the child items of the parent specified.
Returns true
if the column is removed; otherwise returns false
.
参见 removeColumns(), removeRow(), and insertColumn().
[virtual]
bool QAbstractItemModel::removeColumns(int column, int count, const QModelIndex &parent = QModelIndex())
On models that support this, removes count columns starting with the given column under parent parent from the model.
Returns true
if the columns were successfully removed; otherwise returns false
.
The base class implementation does nothing and returns false
.
If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide your own API for altering the data.
参见 removeColumn(), removeRows(), insertColumns(), beginRemoveColumns(), and endRemoveColumns().
bool QAbstractItemModel::removeRow(int row, const QModelIndex &parent = QModelIndex())
Removes the given row from the child items of the parent specified.
Returns true
if the row is removed; otherwise returns false
.
This is a convenience function that calls removeRows(). The QAbstractItemModel implementation of removeRows() does nothing.
参见 removeRows(), removeColumn(), and insertRow().
[virtual]
bool QAbstractItemModel::removeRows(int row, int count, const QModelIndex &parent = QModelIndex())
On models that support this, removes count rows starting with the given row under parent parent from the model.
Returns true
if the rows were successfully removed; otherwise returns false
.
The base class implementation does nothing and returns false
.
If you implement your own model, you can reimplement this function if you want to support removing. Alternatively, you can provide your own API for altering the data.
参见 removeRow(), removeColumns(), insertColumns(), beginRemoveRows(), and endRemoveRows().
[protected slot]
void QAbstractItemModel::resetInternalData()
这个槽函数在模型的内部数据被清除并被重置之后被调用.
这个槽函数为具体代理模型的子类提供了便利,例如维护了额外的数据的 QSortFilterProxyModel 的子类.
class CustomDataProxy : public QSortFilterProxyModel { Q_OBJECT public: CustomDataProxy(QObject *parent) : QSortFilterProxyModel(parent) { } ... QVariant data(const QModelIndex &index, int role) { if (role != Qt::BackgroundRole) return QSortFilterProxyModel::data(index, role); if (m_customData.contains(index.row())) return m_customData.value(index.row()); return QSortFilterProxyModel::data(index, role); } private slots: void resetInternalData() { m_customData.clear(); } private: QHash<int, QVariant> m_customData; };
注意: 由于错误, 这个槽函数没有出现在 Qt 5.0. 中.
This function was introduced in Qt 4.8.
参见 modelAboutToBeReset() and modelReset().
[virtual slot]
void QAbstractItemModel::revert()
让模型知道它应该丢弃缓存的信息. 这个函数通常用于行编辑.
参见 submit().
[virtual]
QHash<int, QByteArray> QAbstractItemModel::roleNames() const
Returns the model's role names.
The default role names set by Qt are:
Qt Role | QML Role Name |
---|---|
Qt::DisplayRole | display |
Qt::DecorationRole | decoration |
Qt::EditRole | edit |
Qt::ToolTipRole | toolTip |
Qt::StatusTipRole | statusTip |
Qt::WhatsThisRole | whatsThis |
This function was introduced in Qt 4.6.
参见 setRoleNames().
[pure virtual]
int QAbstractItemModel::rowCount(const QModelIndex &parent = QModelIndex()) const
Returns the number of rows under the given parent. When the parent is valid it means that rowCount is returning the number of children of parent.
注意: When implementing a table based model, rowCount() should return 0 when the parent is valid.
参见 columnCount().
[signal]
void QAbstractItemModel::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
在将行插入模型之前就发出该信号. 新 item 将位于给定 parent item 下的包含 start 和 end 之间.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化。它只能由 QAbstractItemModel 实现发出, 而不能在子类代码中显式发出.
注意: 这是一个私有信号. 仅用于信号连接, 而不能由用户发出.
参见 insertRows() 和 beginInsertRows().
[signal]
void QAbstractItemModel::rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
模型中的行被移动之前发出该信号. 将要移动的item是在给定 sourceParent 下在 sourceStart 和 sourceEnd 之间(包括首尾)的item. 它们将从 destinationRow 列开始移动到 destinationParent.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化。它只能由 QAbstractItemModel 实现发出, 而不能在子类代码中显式发出.
This function was introduced in Qt 4.6.
注意: 这是一个私有信号. 仅用于信号连接, 而不能由用户发出.
参见 beginMoveRows().
[signal]
void QAbstractItemModel::rowsAboutToBeRemoved(const QModelIndex &parent, int first, int last)
模型中的行被移除之前发出该信号. 将要移除的 item 是在给定 parent 下在 first 和 last 之间(包括首尾)的item.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化。它只能由 QAbstractItemModel 实现发出, 而不能在子类代码中显式发出.
注意: 这是一个私有信号. 仅用于信号连接, 而不能由用户发出.
参见 removeRows() and beginRemoveRows().
[signal]
void QAbstractItemModel::rowsInserted(const QModelIndex &parent, int first, int last)
将行插入到模型之后发出这个信号. 新的item是在给定 parent 下在 first 和 last 之间(包括首尾)的item.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化。它只能由 QAbstractItemModel 实现发出, 而不能在子类代码中显式发出.
注意: 这是一个私有信号. 仅用于信号连接, 而不能由用户发出.
参见 insertRows() and beginInsertRows().
[signal]
void QAbstractItemModel::rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
模型中的行被移动之后发出该信号. 新的itme是在给定 parent 下在 start 和 end 之间(包括首尾)的item. 它们将从 column 列开始移动到 destination.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化。它只能由 QAbstractItemModel 实现发出, 而不能在子类代码中显式发出.
This function was introduced in Qt 4.6.
注意: 这是一个私有信号. 仅用于信号连接, 而不能由用户发出.
参见 beginMoveRows().
[signal]
void QAbstractItemModel::rowsRemoved(const QModelIndex &parent, int first, int last)
模型中的行被移除之后发出该信号. 移除的item是在给定 parent 下在 first 和 last 之间(包括首尾)的item.
注意: 连接到该信号的组件使用它来适应模型尺寸的变化。它只能由 QAbstractItemModel 实现发出, 而不能在子类代码中显式发出.
注意: 这是一个私有信号. 仅用于信号连接, 而不能由用户发出.
参见 removeRows() and beginRemoveRows().
[virtual]
bool QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
Sets the role data for the item at index to value.
Returns true
if successful; otherwise returns false
.
The dataChanged() signal should be emitted if the data was successfully set.
The base class implementation returns false
. This function and data() must be reimplemented for editable models.
参见 Qt::ItemDataRole, data(), and itemData().
[virtual]
bool QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole)
Sets the data for the given role and section in the header with the specified orientation to the value supplied.
Returns true
if the header's data was updated; otherwise returns false
.
When reimplementing this function, the headerDataChanged() signal must be emitted explicitly.
参见 Qt::ItemDataRole and headerData().
[virtual]
bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)
Sets the role data for the item at index to the associated value in roles, for every Qt::ItemDataRole.
Returns true
if successful; otherwise returns false
.
Roles that are not in roles will not be modified.
参见 setData(), data(), and itemData().
[virtual]
QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const
Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location.
sibling() is just a convenience function that finds the item's parent, and uses it to retrieve the index of the child item in the specified row and column.
This method can optionally be overridden for implementation-specific optimization.
参见 index(), QModelIndex::row(), and QModelIndex::column().
[virtual]
void QAbstractItemModel::sort(int column, Qt::SortOrder order = Qt::AscendingOrder)
Sorts the model by column in the given order.
The base class implementation does nothing.
[virtual]
QSize QAbstractItemModel::span(const QModelIndex &index) const
Returns the row and column span of the item represented by index.
注意: Currently, span is not used.
[virtual slot]
bool QAbstractItemModel::submit()
让模型知道它应该将缓存的信息提交到永久存储. 这个函数通常用于行编辑.
如果没有错误,返回 true
; 否则返回 false
.
参见 revert().
[virtual]
Qt::DropActions QAbstractItemModel::supportedDragActions() const
Returns the actions supported by the data in this model.
The default implementation returns supportedDropActions(). Reimplement this function if you wish to support additional actions.
supportedDragActions() is used by QAbstractItemView::startDrag() as the default values when a drag occurs.
参见 setSupportedDragActions(), Qt::DropActions, and Using drag and drop with item views.
[virtual]
Qt::DropActions QAbstractItemModel::supportedDropActions() const
Returns the drop actions supported by this model.
The default implementation returns Qt::CopyAction. Reimplement this function if you wish to support additional actions. You must also reimplement the dropMimeData() function to handle the additional operations.
This function was introduced in Qt 4.2.
参见 dropMimeData(), Qt::DropActions, and Using drag and drop with item views.