The QAbstractItemModel 类为项模型类提供抽象接口。 更多...
| 头: | #include <QAbstractItemModel> |
| 继承: | QObject |
| 继承者: | QAbstractListModel , QAbstractProxyModel , QAbstractTableModel , QDirModel , QFileSystemModel , QHelpContentModel , QProxyModel ,和 QStandardItemModel |
| QAbstractItemModel (QObject * parent = 0) | |
| virtual | ~QAbstractItemModel () |
| virtual QModelIndex | buddy (const QModelIndex & index ) 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 |
| 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()) |
| const 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 ) |
| void | setSupportedDragActions (Qt::DropActions actions ) |
| 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 |
| Qt::DropActions | supportedDragActions () const |
| virtual Qt::DropActions | supportedDropActions () const |
| virtual void | revert () |
| virtual bool | submit () |
| void | columnsAboutToBeInserted (const QModelIndex & parent , int start , int end ) |
| void | columnsAboutToBeMoved (const QModelIndex & sourceParent , int sourceStart , int sourceEnd , const QModelIndex & destinationParent , int destinationColumn ) |
| void | columnsAboutToBeRemoved (const QModelIndex & parent , int start , int end ) |
| void | columnsInserted (const QModelIndex & parent , int start , int end ) |
| void | columnsMoved (const QModelIndex & sourceParent , int sourceStart , int sourceEnd , const QModelIndex & destinationParent , int destinationColumn ) |
| void | columnsRemoved (const QModelIndex & parent , int start , int end ) |
| void | dataChanged (const QModelIndex & topLeft , const QModelIndex & bottomRight ) |
| void | headerDataChanged (Qt::Orientation orientation , int first , int last ) |
| void | layoutAboutToBeChanged () |
| void | layoutChanged () |
| 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 start , int end ) |
| void | rowsInserted (const QModelIndex & parent , int start , int end ) |
| void | rowsMoved (const QModelIndex & sourceParent , int sourceStart , int sourceEnd , const QModelIndex & destinationParent , int destinationRow ) |
| void | rowsRemoved (const QModelIndex & parent , int start , int end ) |
| 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 = 0) const |
| QModelIndex | createIndex (int row , int column , quint32 id ) const |
| void | endInsertColumns () |
| void | endInsertRows () |
| void | endMoveColumns () |
| void | endMoveRows () |
| void | endRemoveColumns () |
| void | endRemoveRows () |
| void | endResetModel () |
| QModelIndexList | persistentIndexList () const |
| void | reset () |
| void | setRoleNames (const QHash<int, QByteArray> & roleNames ) |
| void | resetInternalData () |
The QAbstractItemModel 类为项模型类提供抽象接口。
The QAbstractItemModel 类定义项模型必须使用的标准接口,为能与模型/视图体系结构中的其它组件互操作。假设无法直接实例化它。相反,应子类它以创建新模型。
The QAbstractItemModel 类是一种 模型/视图类 且属于 Qt 的 模型/视图框架 .
If you need a model to use with a QListView 或 QTableView ,应考虑子类化 QAbstractListModel or QAbstractTableModel 而不是此类。
底层数据模型以表格层次结构形式被暴露给视图和委托。若不使用层次结构,那么模型是简单行列表。每项拥有唯一索引指定通过 QModelIndex .
可以凭借模型访问的各数据项,都拥有关联模型索引。可以获取此模型索引使用 index () 函数。每个索引可以拥有 sibling () 索引;子级项拥有 parent () 索引。
各项有许多与之关联的数据元素,且可以检索它们通过指定角色 (见 Qt::ItemDataRole ) 到模型的 data () 函数。可以同时获得所有可用角色的数据使用 itemData () 函数。
各角色数据的设置是使用特定 Qt::ItemDataRole 。单个角色数据的设置是单独采用 setData (),或者可以设置所有角色采用 setItemData ().
可以查询项采用 flags () (见 Qt::ItemFlag ) 以查看是否可以选中、拖拽或以其它方式操纵它们。
若项拥有子级对象, hasChildren () returns true for the corresponding index.
模型有 rowCount () 和 columnCount () 对于层次结构各级别。插入/移除行和列可以采用 insertRows (), insertColumns (), removeRows (),和 removeColumns ().
模型通过发射信号,来指示改变。例如, dataChanged () 被发射,每当模型可用数据项改变时。改变由模型提供的 Header (头) 会导致 headerDataChanged () 被发射。若底层数据的结构改变,模型会发射 layoutChanged () 以指示任何附加视图,它们应考虑新结构,重新显示任何展示项。
透过模型中的可用项搜索特定数据,可以使用 match () 函数。
要排序模型,可以使用 sort ().
注意: 用于子类化模型的一些一般可用指导方针,在 模型子类化参考 .
当子类化 QAbstractItemModel , at the very least you must implement index (), parent (), rowCount (), columnCount (),和 data ()。在所有只读模型使用这些函数,并形成可编辑模型的基础。
还可以重实现 hasChildren () 为模型提供特殊行为,其中实现的 rowCount () 很昂贵。这使模型限定由视图请求的数据量成为可能,且可以用作实现模型数据惰性填充的方式。
要启用模型编辑,还必须实现
setData
(),并重实现
flags
() 以确保
ItemIsEditable
被返回。还可以重实现
headerData
() 和
setHeaderData
() 以控制模型呈现标题的方式。
The dataChanged () 和 headerDataChanged () 信号必须被明确发射,当重实现 setData () 和 setHeaderData () 函数,分别。
自定义模型需要创建模型索引,以供其它组件使用。要做到这,调用 createIndex () 采用针对项的合适行号和列号,及其标识符 (要么以指针方式,要么以整数值方式)。这些值的组合必须唯一,对于各项。通常,自定义模型会在其它重实现函数中使用这些唯一标识符,以检索项数据并访问项父级和子级的有关信息。见 简单树模型范例 了解唯一标识符的更多有关信息。
没有必要支持的各角色,其定义在 Qt::ItemDataRole 。从属模型包含的数据类型,它可能才有用为实现 data () 函数,以返回用于一些更常见角色的有效信息。大多数模型至少提供项数据的正文表示为 Qt::DisplayRole ,且行为良好模型还应提供有效信息为 Qt::ToolTipRole and Qt::WhatsThisRole 。支持这些角色,使模型能够用于标准 Qt 视图。不管怎样,对于处理高度专用数据的某些模型,仅为用户定义角色提供数据可能是合适的。
为可重置大小的数据结构提供接口的模型,可以提供实现 insertRows (), removeRows (), insertColumns (),and removeColumns ()。当实现这些函数时,重要的是通知任何已连接视图,即将改变模型维度 before and after 它们出现:
The private 信号这些函数发射给定附加组件改变,以在任何数据变为不可用前采取行动。采用这些 begin 和 end 函数封装地插入和移除操作,还使模型能够管理 持久模型索引 正确。 若想要正确处理选择,必须确保调用这些函数。 若插入 (或移除) 具有子级的项,不需要为子级项调用这些函数。换句话说,父级项会关心其子级项。
要创建增量填充模型,可以重实现 fetchMore () 和 canFetchMore ()。若重实现 fetchMore () 把行添加到模型, beginInsertRows() and endInsertRows() 必须被调用。
另请参阅 模型类 , 模型子类化参考 , QModelIndex , QAbstractItemView , 将拖放用于项视图 , 简单 DOM 模型范例 , 简单树模型范例 , 可编辑树模型范例 ,和 抓取更多范例 .
构造抽象项模型采用给定 parent .
[虚拟]
QAbstractItemModel::
~QAbstractItemModel
()
销毁抽象项模型。
[protected]
void
QAbstractItemModel::
beginInsertColumns
(const
QModelIndex
&
parent
,
int
first
,
int
last
)
开始列插入操作。
当重实现 insertColumns () 在子类,必须调用此函数 before inserting data into the model's underlying data store.
The parent index corresponds to the parent into which the new columns are inserted; first and last are the column numbers of the new columns will have after they have been inserted.
|
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); This inserts the three new columns as columns 4, 5, and 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); This appends the two new columns as columns 6, 7, and 8. |
注意: 此函数发射 columnsAboutToBeInserted () signal which connected views (or proxies) must handle before the data is inserted. Otherwise, the views may end up in an invalid state.
另请参阅 endInsertColumns ().
[protected]
void
QAbstractItemModel::
beginInsertRows
(const
QModelIndex
&
parent
,
int
first
,
int
last
)
开始行插入操作。
当重实现 insertRows () 在子类,必须调用此函数 before inserting data into the model's underlying data store.
The parent index corresponds to the parent into which the new rows are inserted; first and last are the row numbers that the new rows will have after they have been inserted.
|
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); This inserts the three new rows as rows 2, 3, and 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); This appends the two new rows as rows 4 and 5. |
注意: 此函数发射 rowsAboutToBeInserted () signal which connected views (or proxies) must handle before the data is inserted. Otherwise, the views may end up in an invalid state.
另请参阅 endInsertRows ().
[protected]
bool
QAbstractItemModel::
beginMoveColumns
(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 changePersistentIndexes. layoutAboutToBeChanged is emitted by this method for compatibility reasons.
The sourceParent index corresponds to the parent from which the columns are moved; sourceFirst and sourceLast are the first and last column numbers of the columns to be moved. The destinationParent index corresponds to the parent into which those columns are moved. The destinationChild is the column to which the columns will be moved. That is, the index at column sourceFirst in sourceParent will become column destinationChild in destinationParent , followed by all other columns up to sourceLast .
However, when moving columns down in the same parent (
sourceParent
and
destinationParent
are equal), the columnss will be placed before the
destinationChild
index. That is, if you wish to move columns 0 and 1 so they will become columns 1 and 2,
destinationChild
should be 3. In this case, the new index for the source column
i
(which is between
sourceFirst
and
sourceLast
) is equal to
(destinationChild-sourceLast-1+i)
.
注意,若 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 column 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.
该函数在 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 changePersistentIndexes. layoutAboutToBeChanged is emitted by this method for compatibility reasons.
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)
.
注意,若 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 为 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. |
该函数在 Qt 4.6 引入。
另请参阅 endMoveRows ().
[protected]
void
QAbstractItemModel::
beginRemoveColumns
(const
QModelIndex
&
parent
,
int
first
,
int
last
)
开始列移除操作。
当重实现 removeColumns () 在子类,必须调用此函数 before 移除数据从模型的底层数据存储。
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); |
注意: 此函数发射 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
)
开始行移除操作。
当重实现 removeRows () 在子类,必须调用此函数 before 移除数据从模型的底层数据存储。
The parent 索引相当于从其中移除新行的父级; first and last 是要移除行的行号。
|
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); |
注意: 此函数发射 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.
该函数在 Qt 4.6 引入。
另请参阅 modelAboutToBeReset (), modelReset (),和 endResetModel ().
[虚拟]
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.
[虚拟]
bool
QAbstractItemModel::
canFetchMore
(const
QModelIndex
&
parent
) const
Returns true if there is more data available for parent ;否则返回 false。
The default implementation always returns false.
If canFetchMore() returns true, QAbstractItemView 将调用 fetchMore (). However, the fetchMore () function is only called when the model is being populated incrementally.
另请参阅 fetchMore ().
[protected]
void
QAbstractItemModel::
changePersistentIndex
(const
QModelIndex
&
from
, const
QModelIndex
&
to
)
改变 QPersistentModelIndex that is equal to the given from model index to the given to 模型索引。
If no persistent model index equal to the given from model index was found, nothing is changed.
另请参阅 persistentIndexList () 和 changePersistentIndexList ().
[protected]
void
QAbstractItemModel::
changePersistentIndexList
(const
QModelIndexList
&
from
, const
QModelIndexList
&
to
)
Changes the QPersistentModelIndexes that is equal to the indexes in the given from model index list to the given to 模型索引列表。
If no persistent model indexes equal to the indexes in the given from model index list was found, nothing is changed.
该函数在 Qt 4.1 引入。
另请参阅 persistentIndexList () 和 changePersistentIndex ().
[pure virtual]
int
QAbstractItemModel::
columnCount
(const
QModelIndex
&
parent
= QModelIndex()) const
Returns the number of columns for the children of the given parent .
对于大多数子类,列数独立于 parent .
例如:
int DomModel::columnCount(const QModelIndex &/*parent*/) const { return 3; }
注意: 当实现基于表格的模型时,columnCount() 应返回 0,当父级有效时。
另请参阅 rowCount ().
[signal]
void
QAbstractItemModel::
columnsAboutToBeInserted
(const
QModelIndex
&
parent
,
int
start
,
int
end
)
This signal is emitted just before columns are inserted into the model. The new items will be positioned between start and end inclusive, under the given parent 项。
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
另请参阅 insertColumns () 和 beginInsertColumns ().
[signal]
void
QAbstractItemModel::
columnsAboutToBeMoved
(const
QModelIndex
&
sourceParent
,
int
sourceStart
,
int
sourceEnd
, const
QModelIndex
&
destinationParent
,
int
destinationColumn
)
This signal is emitted just before columns are moved within the model. The items that will be moved are those between sourceStart and sourceEnd inclusive, under the given sourceParent item. They will be moved to destinationParent starting at the column destinationColumn .
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
该函数在 Qt 4.6 引入。
另请参阅 beginMoveRows ().
[signal]
void
QAbstractItemModel::
columnsAboutToBeRemoved
(const
QModelIndex
&
parent
,
int
start
,
int
end
)
This signal is emitted just before columns are removed from the model. The items to be removed are those between start and end inclusive, under the given parent 项。
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
另请参阅 removeColumns () 和 beginRemoveColumns ().
[signal]
void
QAbstractItemModel::
columnsInserted
(const
QModelIndex
&
parent
,
int
start
,
int
end
)
This signal is emitted after columns have been inserted into the model. The new items are those between start and end inclusive, under the given parent 项。
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
另请参阅 insertColumns () 和 beginInsertColumns ().
[signal]
void
QAbstractItemModel::
columnsMoved
(const
QModelIndex
&
sourceParent
,
int
sourceStart
,
int
sourceEnd
, const
QModelIndex
&
destinationParent
,
int
destinationColumn
)
This signal is emitted after columns have been moved within the model. The items between sourceStart and sourceEnd inclusive, under the given sourceParent item have been moved to destinationParent starting at the column destinationColumn .
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
该函数在 Qt 4.6 引入。
另请参阅 beginMoveRows ().
[signal]
void
QAbstractItemModel::
columnsRemoved
(const
QModelIndex
&
parent
,
int
start
,
int
end
)
This signal is emitted after columns have been removed from the model. The removed items are those between start and end inclusive, under the given parent 项。
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
另请参阅 removeColumns () 和 beginRemoveColumns ().
[protected]
QModelIndex
QAbstractItemModel::
createIndex
(
int
row
,
int
column
,
void
*
ptr
= 0) const
创建模型索引为给定 row and column 采用内部指针 ptr .
当使用 QSortFilterProxyModel ,索引拥有自己的内部指针。在模型外访问此内部指针,不可能。使用 data () 函数代替。
此函数提供必须使用模型子类,创建模型索引的一致接口。
[protected]
QModelIndex
QAbstractItemModel::
createIndex
(
int
row
,
int
column
,
quint32
id
) const
创建模型索引为给定 row and column 采用内部标识符 id .
此函数提供必须使用模型子类,创建模型索引的一致接口。
另请参阅 QModelIndex::internalId ().
[pure virtual]
QVariant
QAbstractItemModel::
data
(const
QModelIndex
&
index
,
int
role
= Qt::DisplayRole) const
返回数据存储在给定 role for the item referred to by the index .
注意: 若没有值要返回,返回 无效 QVariant 而不是返回 0。
另请参阅 Qt::ItemDataRole , setData (),和 headerData ().
[signal]
void
QAbstractItemModel::
dataChanged
(const
QModelIndex
&
topLeft
, const
QModelIndex
&
bottomRight
)
此信号发射,每当现有项数据改变时。
If the items are of the same parent, the affected ones are those between topLeft and bottomRight inclusive. If the items do not have the same parent, the behavior is undefined.
当重实现 setData () 函数,必须明确发射此信号。
另请参阅 headerDataChanged (), setData (),和 layoutChanged ().
[虚拟]
bool
QAbstractItemModel::
dropMimeData
(const
QMimeData
*
data
,
Qt::DropAction
action
,
int
row
,
int
column
, const
QModelIndex
&
parent
)
处理 data 的提供是通过结束拖放操作,按给定 action .
Returns true if the data and action can be handled by the model; otherwise returns false.
指定 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 ,和 parent , or as siblings of the item.
当 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 。若 row and column are greater than or equal zero, it means that the drop occurred just before the specified row and column 以指定 parent .
另请参阅 supportedDropActions () 和 将拖放用于项视图 .
[protected]
void
QAbstractItemModel::
endInsertColumns
()
结束列插入操作。
当重实现 insertColumns () 在子类,必须调用此函数 after inserting data into the model's underlying data store.
另请参阅 beginInsertColumns ().
[protected]
void
QAbstractItemModel::
endInsertRows
()
结束行插入操作。
当重实现 insertRows () 在子类,必须调用此函数 after inserting data into the model's underlying data store.
另请参阅 beginInsertRows ().
[protected]
void
QAbstractItemModel::
endMoveColumns
()
结束列移动操作。
当实现子类时,必须调用此函数 after 于模型的底层数据存储中移动数据。
layoutChanged is emitted by this method for compatibility reasons.
该函数在 Qt 4.6 引入。
另请参阅 beginMoveColumns ().
[protected]
void
QAbstractItemModel::
endMoveRows
()
结束行移动操作。
当实现子类时,必须调用此函数 after 于模型的底层数据存储中移动数据。
layoutChanged is emitted by this method for compatibility reasons.
该函数在 Qt 4.6 引入。
另请参阅 beginMoveRows ().
[protected]
void
QAbstractItemModel::
endRemoveColumns
()
结束列移除操作。
当重实现 removeColumns () 在子类,必须调用此函数 after 移除数据从模型的底层数据存储。
另请参阅 beginRemoveColumns ().
[protected]
void
QAbstractItemModel::
endRemoveRows
()
结束行移除操作。
当重实现 removeRows () 在子类,必须调用此函数 after 移除数据从模型的底层数据存储。
另请参阅 beginRemoveRows ().
[protected]
void
QAbstractItemModel::
endResetModel
()
完成模型重置操作。
You must call this function after resetting any internal data structure in your model or proxy model.
该函数在 Qt 4.6 引入。
另请参阅 beginResetModel ().
[虚拟]
void
QAbstractItemModel::
fetchMore
(const
QModelIndex
&
parent
)
抓取针对项的任何可用数据,采用父级指定通过 parent 索引。
重实现此,若正增量填充模型。
默认实现什么都不做。
另请参阅 canFetchMore ().
[虚拟]
Qt::ItemFlags
QAbstractItemModel::
flags
(const
QModelIndex
&
index
) const
返回项标志为给定 index .
The base class implementation returns a combination of flags that enables the item (
ItemIsEnabled
) and allows it to be selected (
ItemIsSelectable
).
另请参阅 Qt::ItemFlags .
[虚拟]
bool
QAbstractItemModel::
hasChildren
(const
QModelIndex
&
parent
= QModelIndex()) const
返回 true 若 parent has any children; otherwise returns false.
使用 rowCount () on the parent to find out the number of children.
Returns true if the model returns a valid QModelIndex for row and column with parent ,否则返回 false。
[虚拟]
QVariant
QAbstractItemModel::
headerData
(
int
section
,
Qt::Orientation
orientation
,
int
role
= Qt::DisplayRole) const
返回数据为给定 role and section 在 Header (头) 采用指定 orientation .
对于水平 Header (头),区间号相当于列号。同样,对于垂直 Header (头),区间号相当于行号。
另请参阅 Qt::ItemDataRole , setHeaderData (),和 QHeaderView .
[signal]
void
QAbstractItemModel::
headerDataChanged
(
Qt::Orientation
orientation
,
int
first
,
int
last
)
This signal is emitted whenever a header is changed. The orientation indicates whether the horizontal or vertical header has changed. The sections in the header from the first 到 last need to be updated.
当重实现 setHeaderData () 函数,必须明确发射此信号。
If you are changing the number of columns or rows you do not need to emit this signal, but use the begin/end functions (refer to the section on subclassing in the QAbstractItemModel 类描述了解细节)。
另请参阅 headerData (), setHeaderData (),和 dataChanged ().
[pure virtual]
QModelIndex
QAbstractItemModel::
index
(
int
row
,
int
column
, const
QModelIndex
&
parent
= QModelIndex()) const
返回模型中的项索引,指定通过给定 row , column and parent 索引。
当在子类中重实现此函数时,调用 createIndex () 去生成模型索引,其它组件可以使用以引用模型中的项。
另请参阅 createIndex ().
插入单列先于给定 column in the child items of the parent 指定。
Returns true if the column is inserted; otherwise returns false.
另请参阅 insertColumns (), insertRow (),和 removeColumn ().
[虚拟]
bool
QAbstractItemModel::
insertColumns
(
int
column
,
int
count
, const
QModelIndex
&
parent
= QModelIndex())
对于支持这的模型,插入 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 模型索引。
若 column is 0, the columns are prepended to any existing columns.
若 column is columnCount (), the columns are appended to any existing columns.
若 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 (),和 endInsertColumns ().
注意: The base class implementation of this function does nothing and returns false.
插入单行先于给定 row in the child items of the parent 指定。
Returns true if the row is inserted; otherwise returns false.
另请参阅 insertRows (), insertColumn (),和 removeRow ().
[虚拟]
bool
QAbstractItemModel::
insertRows
(
int
row
,
int
count
, const
QModelIndex
&
parent
= QModelIndex())
注意: The base class implementation of this function does nothing and returns false.
对于支持这的模型,插入 count rows into the model before the given row . Items in the new row will be children of the item represented by the parent 模型索引。
若 row is 0, the rows are prepended to any existing rows in the parent.
若 row is rowCount (), the rows are appended to any existing rows in the parent.
若 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 () 和 endInsertRows () to notify other components that the model has changed.
另请参阅 insertColumns (), removeRows (), beginInsertRows (),和 endInsertRows ().
[虚拟]
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 ,和 data ().
[signal]
void
QAbstractItemModel::
layoutAboutToBeChanged
()
This signal is emitted just before the layout of a model is changed. Components connected to this signal use it to adapt to changes in the model's layout.
Subclasses should update any persistent model indexes after emitting layoutAboutToBeChanged().
该函数在 Qt 4.2 引入。
另请参阅 layoutChanged () 和 changePersistentIndex ().
[signal]
void
QAbstractItemModel::
layoutChanged
()
This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted. When this signal is received by a view, it should update the layout of items to reflect this change.
当子类化 QAbstractItemModel or QAbstractProxyModel ,确保发射 layoutAboutToBeChanged () before changing the order of items or altering the structure of the data you expose to views, and emit layoutChanged() after changing the layout.
Subclasses should update any persistent model indexes before emitting layoutChanged(). In other words, when the structure changes:
另请参阅 layoutAboutToBeChanged (), dataChanged (), headerDataChanged (), modelReset (),和 changePersistentIndex ().
[虚拟]
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.
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
指定在
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.
[虚拟]
QMimeData
* QAbstractItemModel::
mimeData
(const
QModelIndexList
&
indexes
) const
Returns an object that contains serialized items of data corresponding to the list of indexes specified. The formats used to describe the encoded data is obtained from the mimeTypes () 函数。
If the list of indexes is empty, or there are no supported MIME types, 0 is returned rather than a serialized empty list.
另请参阅 mimeTypes () 和 dropMimeData ().
[虚拟]
QStringList
QAbstractItemModel::
mimeTypes
() const
Returns a list of MIME types that can be used to describe a list of model indexes.
另请参阅 mimeData ().
[signal]
void
QAbstractItemModel::
modelAboutToBeReset
()
此信号发射,当 reset () is called, before the model's internal state (e.g. persistent model indexes) has been invalidated.
该函数在 Qt 4.2 引入。
另请参阅 beginResetModel () 和 modelReset ().
[signal]
void
QAbstractItemModel::
modelReset
()
此信号发射,当 reset () is called, after the model's internal state (e.g. persistent model indexes) has been invalidated.
该函数在 Qt 4.1 引入。
另请参阅 endResetModel () 和 modelAboutToBeReset ().
[pure virtual]
QModelIndex
QAbstractItemModel::
parent
(const
QModelIndex
&
index
) const
返回模型项的父级采用给定 index 。若项没有父级,无效 QModelIndex 被返回。
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.
在子类重实现此函数时,小心避免调用 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
返回以持久索引方式,存储在模型中的索引列表。
该函数在 Qt 4.2 引入。
移除给定 column 从子级项对于 parent 指定。
Returns true if the column is removed; otherwise returns false.
另请参阅 removeColumns (), removeRow (),和 insertColumn ().
[虚拟]
bool
QAbstractItemModel::
removeColumns
(
int
column
,
int
count
, const
QModelIndex
&
parent
= QModelIndex())
对于支持这的模型,移除 count 列始于给定 column 在父级 parent 来自模型。
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 (),和 endRemoveColumns ().
移除给定 row 从子级项对于 parent 指定。
Returns true if the row is removed; otherwise returns false.
这是方便函数当调用 removeRows ()。 QAbstractItemModel 实现的 removeRows () 什么都不做。
另请参阅 removeRows (), removeColumn (),和 insertRow ().
[虚拟]
bool
QAbstractItemModel::
removeRows
(
int
row
,
int
count
, const
QModelIndex
&
parent
= QModelIndex())
对于支持这的模型,移除 count 行始于给定 row 在父级 parent 来自模型。
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 (),和 endRemoveRows ().
[protected]
void
QAbstractItemModel::
reset
()
Resets the model to its original state in any attached views.
注意: 使用 beginResetModel () 和 endResetModel () instead whenever possible. Use this method only if there is no way to call beginResetModel () before invalidating the model. Otherwise it could lead to unexpected behaviour, especially when used with proxy models.
[protected slot]
void
QAbstractItemModel::
resetInternalData
()
This slot is called just after the internal data of a model is cleared while it is being reset.
This slot is provided the convenience of subclasses of concrete proxy models, such as subclasses of 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 4.8 引入。
另请参阅 modelAboutToBeReset () 和 modelReset ().
[virtual slot]
void
QAbstractItemModel::
revert
()
Lets the model know that it should discard cached information. This function is typically used for row editing.
另请参阅 submit ().
返回模型的角色名称。
该函数在 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
)
This signal is emitted just before rows are inserted into the model. The new items will be positioned between start and end inclusive, under the given parent 项。
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
另请参阅 insertRows () 和 beginInsertRows ().
[signal]
void
QAbstractItemModel::
rowsAboutToBeMoved
(const
QModelIndex
&
sourceParent
,
int
sourceStart
,
int
sourceEnd
, const
QModelIndex
&
destinationParent
,
int
destinationRow
)
This signal is emitted just before rows are moved within the model. The items that will be moved are those between sourceStart and sourceEnd inclusive, under the given sourceParent item. They will be moved to destinationParent starting at the row destinationRow .
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
该函数在 Qt 4.6 引入。
另请参阅 beginMoveRows ().
[signal]
void
QAbstractItemModel::
rowsAboutToBeRemoved
(const
QModelIndex
&
parent
,
int
start
,
int
end
)
This signal is emitted just before rows are removed from the model. The items that will be removed are those between start and end inclusive, under the given parent 项。
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
另请参阅 removeRows () 和 beginRemoveRows ().
[signal]
void
QAbstractItemModel::
rowsInserted
(const
QModelIndex
&
parent
,
int
start
,
int
end
)
This signal is emitted after rows have been inserted into the model. The new items are those between start and end inclusive, under the given parent 项。
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
另请参阅 insertRows () 和 beginInsertRows ().
[signal]
void
QAbstractItemModel::
rowsMoved
(const
QModelIndex
&
sourceParent
,
int
sourceStart
,
int
sourceEnd
, const
QModelIndex
&
destinationParent
,
int
destinationRow
)
This signal is emitted after rows have been moved within the model. The items between sourceStart and sourceEnd inclusive, under the given sourceParent item have been moved to destinationParent starting at the row destinationRow .
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
该函数在 Qt 4.6 引入。
另请参阅 beginMoveRows ().
[signal]
void
QAbstractItemModel::
rowsRemoved
(const
QModelIndex
&
parent
,
int
start
,
int
end
)
This signal is emitted after rows have been removed from the model. The removed items are those between start and end inclusive, under the given parent 项。
注意: Components connected to this signal use it to adapt to changes in the model's dimensions. It can only be emitted by the QAbstractItemModel implementation, and cannot be explicitly emitted in subclass code.
另请参阅 removeRows () 和 beginRemoveRows ().
[虚拟]
bool
QAbstractItemModel::
setData
(const
QModelIndex
&
index
, const
QVariant
&
value
,
int
role
= Qt::EditRole)
设置 role 数据为项在 index to value .
Returns true if successful; otherwise returns false.
The dataChanged () 信号应被发射,若数据设置成功。
The base class implementation returns false. This function and data () 必须被重实现为可编辑模型。
另请参阅 Qt::ItemDataRole , data (),和 itemData ().
[虚拟]
bool
QAbstractItemModel::
setHeaderData
(
int
section
,
Qt::Orientation
orientation
, const
QVariant
&
value
,
int
role
= Qt::EditRole)
设置数据为给定 role and section 在 Header (头) 采用指定 orientation 到 value 供给。
Returns true if the header's data was updated; otherwise returns false.
当重实现此函数时, headerDataChanged () 信号必须明确被发射。
另请参阅 Qt::ItemDataRole and headerData ().
[虚拟]
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 (),和 itemData ().
[protected]
void
QAbstractItemModel::
setRoleNames
(const
QHash
<
int
,
QByteArray
> &
roleNames
)
Sets the model's role names to roleNames .
This function allows mapping of role identifiers to role property names in Declarative UI. This function must be called before the model is used. Modifying the role names after the model has been set may result in undefined behaviour.
该函数在 Qt 4.6 引入。
另请参阅 roleNames ().
Sets the supported drag actions for the items in the model.
该函数在 Qt 4.2 引入。
另请参阅 supportedDragActions () 和 将拖放用于项视图 .
返回同级在 row and column for the item at index ,或无效 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 .
另请参阅 index (), QModelIndex::row (),和 QModelIndex::column ().
[虚拟]
void
QAbstractItemModel::
sort
(
int
column
,
Qt::SortOrder
order
= Qt::AscendingOrder)
排序模型按 column 以给定 order .
基类实现什么都不做。
[虚拟]
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
()
Lets the model know that it should submit cached information to permanent storage. This function is typically used for row editing.
Returns true if there is no error; otherwise returns false.
另请参阅 revert ().
Returns the actions supported by the data in this model.
默认实现返回 supportedDropActions () unless specific values have been set with setSupportedDragActions ().
supportedDragActions() is used by QAbstractItemView::startDrag () as the default values when a drag occurs.
另请参阅 setSupportedDragActions (), Qt::DropActions ,和 将拖放用于项视图 .
[虚拟]
Qt::DropActions
QAbstractItemModel::
supportedDropActions
() const
返回由此模型支持的掉落动作。
默认实现返回 Qt::CopyAction . Reimplement this function if you wish to support additional actions. You must also reimplement the dropMimeData () function to handle the additional operations.
该函数在 Qt 4.2 引入。
另请参阅 dropMimeData (), Qt::DropActions ,和 将拖放用于项视图 .