QtBase
v6.3.1
|
The QAbstractItemModel class provides the abstract interface for item model classes. More...
#include <qabstractitemmodel.h>
Public Types | |
enum | LayoutChangeHint { NoLayoutChangeHint , VerticalSortHint , HorizontalSortHint } |
enum class | CheckIndexOption { NoOption = 0x0000 , IndexIsValid = 0x0001 , DoNotUseParent = 0x0002 , ParentIsInvalid = 0x0004 } |
Public Slots | |
virtual bool | submit () |
virtual void | revert () |
Public Slots inherited from QObject | |
void | deleteLater () |
Protected Slots | |
virtual void | resetInternalData () |
Friends | |
class | QPersistentModelIndexData |
class | QAbstractItemViewPrivate |
class | QAbstractProxyModel |
The QAbstractItemModel class provides the abstract interface for item model classes.
\inmodule QtCore
The QAbstractItemModel class defines the standard interface that item models must use to be able to interoperate with other components in the model/view architecture. It is not supposed to be instantiated directly. Instead, you should subclass it to create new models.
The QAbstractItemModel class is one of the \l{Model/View Classes} and is part of Qt's \l{Model/View Programming}{model/view framework}. It can be used as the underlying data model for the item view elements in QML or the item view classes in the Qt Widgets module.
If you need a model to use with an item view such as QML's List View element or the C++ widgets QListView or QTableView, you should consider subclassing QAbstractListModel or QAbstractTableModel instead of this class.
The underlying data model is exposed to views and delegates as a hierarchy of tables. If you do not make use of the hierarchy, then the model is a simple table of rows and columns. Each item has a unique index specified by a QModelIndex.
Every item of data that can be accessed via a model has an associated model index. You can obtain this model index using the index() function. Each index may have a sibling() index; child items have a parent() index.
Each item has a number of data elements associated with it and they can be retrieved by specifying a role (see \l Qt::ItemDataRole) to the model's data() function. Data for all available roles can be obtained at the same time using the itemData() function.
Data for each role is set using a particular \l Qt::ItemDataRole. Data for individual roles are set individually with setData(), or they can be set for all roles with setItemData().
Items can be queried with flags() (see \l Qt::ItemFlag) to see if they can be selected, dragged, or manipulated in other ways.
If an item has child objects, hasChildren() returns {true} for the corresponding index.
The model has a rowCount() and a columnCount() for each level of the hierarchy. Rows and columns can be inserted and removed with insertRows(), insertColumns(), removeRows(), and removeColumns().
The model emits signals to indicate changes. For example, dataChanged() is emitted whenever items of data made available by the model are changed. Changes to the headers supplied by the model cause headerDataChanged() to be emitted. If the structure of the underlying data changes, the model can emit layoutChanged() to indicate to any attached views that they should redisplay any items shown, taking the new structure into account.
The items available through the model can be searched for particular data using the match() function.
To sort the model, you can use sort().
Definition at line 269 of file qabstractitemmodel.h.
|
strong |
This enum can be used to control the checks performed by QAbstractItemModel::checkIndex().
\value NoOption No check options are specified.
\value IndexIsValid The model index passed to QAbstractItemModel::checkIndex() is checked to be a valid model index.
\value DoNotUseParent Does not perform any check involving the usage of the parent of the index passed to QAbstractItemModel::checkIndex().
\value ParentIsInvalid The parent of the model index passed to QAbstractItemModel::checkIndex() is checked to be an invalid model index. If both this option and DoNotUseParent are specified, then this option is ignored.
Enumerator | |
---|---|
NoOption | |
IndexIsValid | |
DoNotUseParent | |
ParentIsInvalid |
Definition at line 353 of file qabstractitemmodel.h.
This enum describes the way the model changes layout.
\value NoLayoutChangeHint No hint is available. \value VerticalSortHint Rows are being sorted. \value HorizontalSortHint Columns are being sorted.
Note that VerticalSortHint and HorizontalSortHint carry the meaning that items are being moved within the same parent, not moved to a different parent in the model, and not filtered out or in.
Enumerator | |
---|---|
NoLayoutChangeHint | |
VerticalSortHint | |
HorizontalSortHint |
Definition at line 345 of file qabstractitemmodel.h.
Constructs an abstract item model with the given parent.
Definition at line 1734 of file qabstractitemmodel.cpp.
|
virtual |
Destroys the abstract item model.
Definition at line 1750 of file qabstractitemmodel.cpp.
|
protected |
Definition at line 1742 of file qabstractitemmodel.cpp.
|
protected |
Begins a column insertion operation.
When reimplementing insertColumns() in a subclass, you must call this function 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.
\table 80% \row
For example, as shown in the diagram, we insert three columns before column 4, so first is 4 and last is 6:
This inserts the three new columns as columns 4, 5, and 6. \row
For example, as shown in the diagram, we append three columns to a collection of six existing columns (ending in column 5), so \a first is 6 and \a last is 8: \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 4 This appends the two new columns as columns 6, 7, and 8.\endtable
Definition at line 3217 of file qabstractitemmodel.cpp.
|
protected |
Begins a row insertion operation.
When reimplementing insertRows() in a subclass, you must call this function 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.
\table 80% \row
For example, as shown in the diagram, we insert three rows before row 2, so first is 2 and last is 4:
This inserts the three new rows as rows 2, 3, and 4. \row
For example, as shown in the diagram, we append two rows to a collection of 4 existing rows (ending in row 3), so \a first is 4 and \a last is 5: \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 1 This appends the two new rows as rows 4 and 5.\endtable
Definition at line 2907 of file qabstractitemmodel.cpp.
|
protected |
Begins a column move operation.
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 beginMoveColumns and endMoveColumns is an alternative to emitting layoutAboutToBeChanged and layoutChanged directly along with changePersistentIndex.
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 columns 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)}.
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 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.
Definition at line 3338 of file qabstractitemmodel.cpp.
|
protected |
Begins a row move operation.
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.
\table 80% \row
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.
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. \row
For example, as shown in the diagram, we move three rows to a collection of 6 existing rows (ending in row 5), so \a destinationChild is 6: \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 7 This moves the target rows to the end of the target parent as 6, 7 and 8.\row
For example, as shown in the diagram, we move one item from row 2 to row 0, so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 0. \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 8 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 cannot 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)\row
For example, as shown in the diagram, we move one item from row 2 to row 4, so \a sourceFirst and \a sourceLast are 2 and \a destinationChild is 4. \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 9 Note that other rows may be displaced accordingly.\endtable
Definition at line 3119 of file qabstractitemmodel.cpp.
|
protected |
Begins a column removal operation.
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.
\table 80% \row
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:
\endtable
Definition at line 3273 of file qabstractitemmodel.cpp.
|
protected |
Begins a row removal operation.
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.
\table 80% \row
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:
\endtable
Definition at line 2962 of file qabstractitemmodel.cpp.
|
protected |
Begins a model reset operation.
A reset operation resets the model to its current state in any attached views.
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().
Definition at line 3417 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in QSortFilterProxyModel, and QAbstractProxyModel.
Definition at line 2507 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in QtTestModel, DragDropListModel, QConcatenateTablesProxyModel, QAbstractProxyModel, DropTestModel, and DropOnOddRows.
Definition at line 2185 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in QSqlQueryModel, FetchMoreModel, QFileSystemModel, QSortFilterProxyModel, QAbstractProxyModel, FileListModel, QtTestModel, QtTestModel, and QtTestTableModel.
Definition at line 2463 of file qabstractitemmodel.cpp.
|
protected |
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.
Definition at line 3450 of file qabstractitemmodel.cpp.
|
protected |
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.
Definition at line 3477 of file qabstractitemmodel.cpp.
bool QAbstractItemModel::checkIndex | ( | const QModelIndex & | index, |
CheckIndexOptions | options = CheckIndexOption::NoOption |
||
) | const |
This function checks whether index is a legal model index for this model. A legal model index is either an invalid model index, or a valid model index for which all the following holds:
\list
{this}; \endlist
The options argument may change some of these checks. If options contains {IndexIsValid}, then index must be a valid index; this is useful when reimplementing functions such as \l{data()} or \l{setData()}, which expect valid indexes.
If options contains {DoNotUseParent}, then the checks that would call \l{parent()} are omitted; this allows calling this function from a \l{parent()} reimplementation (otherwise, this would result in endless recursion and a crash).
If options does not contain {DoNotUseParent}, and it contains
{ParentIsInvalid}, then an additional check is performed: the parent index is checked for not being valid. This is useful when implementing flat models such as lists or tables, where no model index should have a valid parent index.
This function returns true if all the checks succeeded, and false otherwise. This allows to use the function in \l{Q_ASSERT} and similar other debugging mechanisms. If some check failed, a warning message will be printed in the {qt.core.qabstractitemmodel.checkindex} logging category, containing some information that may be useful for debugging the failure.
Definition at line 3591 of file qabstractitemmodel.cpp.
|
virtual |
{true} if successful; otherwise returns
{false}. The dataChanged() signal should be emitted if the data was successfully removed. The base class implementation returns
{false} Reimplemented in QTreeModel, QTableModel, QListModel, QSqlTableModel, QStandardItemModel, QStringListModel, and QAbstractProxyModel.
Definition at line 2078 of file qabstractitemmodel.cpp.
|
pure virtual |
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:
Implemented in SwappingProxy, EvilModel, QtTestModel, BigModel, CheckFilteredIndexes::TableModel, QtTestModel, QUndoModel, QTreeModel, QTableModel, TableModel, QSqlQueryModel, QStandardItemModel, QFileSystemModel, QTransposeProxyModel, QSortFilterProxyModel, QIdentityProxyModel, QConcatenateTablesProxyModel, MyModel, MyModel, MyModel, MyModel, MyModel, TreeModel, DomModel, ImageModel, TreeModel, LocaleModel, Dmodel, TestItemModel, QtTestModel, StorageModel, Model, TableModel, DynamicTreeModel, QCompletionModel, TstMoveModel, SpanModel, QtTestTableModel, QtTestTableModel, SimpleModel, StepTreeModel, QtTestTableModel, QStreamHelper, MyAbstractItemModel, Model_11466, Model, QtTestModel, QTBUG53221_Model, QtTestModel, SelectionProxyModel, TestModel, SubQAbstractProxyModel, and QEmptyItemModel.
|
signal |
This signal is emitted just before columns are inserted into the model. The new items will be positioned between first and last inclusive, under the given parent item.
|
signal |
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.
{Note:} 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.
|
signal |
This signal is emitted just before columns are removed from the model. The items to be removed are those between first and last inclusive, under the given parent item.
|
signal |
This signal is emitted after columns have been inserted into the model. The new items are those between first and last inclusive, under the given parent item.
|
signal |
This signal is emitted after columns have been moved within the model. The items between start and end inclusive, under the given parent item have been moved to destination starting at the column column.
{Note:} 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.
|
signal |
This signal is emitted after columns have been removed from the model. The removed items are those between first and last inclusive, under the given parent item.
|
inlineprotected |
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.
Definition at line 456 of file qabstractitemmodel.h.
|
inlineprotected |
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.
Definition at line 458 of file qabstractitemmodel.h.
|
pure virtual |
Returns the data stored under the given role for the item referred to by the index.
Implemented in QAbstractProxyModel, QSqlRelationalTableModel, QSqlQueryModel, MyModel, MyModel, CustomSqlModel, RecordReimplModel, QTBUG_56693_Model, BigModel, TstMoveModel, CheckerModel, DynamicTreeModel, CheckFilteredIndexes::TableModel, CustomStringListModel, StepTreeModel, DropOnOddRows, QUndoModel, QCompletionModel, QTreeModel, QTableModel, QListModel, QStandardItemModel, QFileSystemModel, QStringListModel, QSortFilterProxyModel, QConcatenateTablesProxyModel, MyModel, MyModel, MyModel, MyModel, MyModel, FileSystemModel, PiecesModel, ImageModel, FileListModel, LocaleModel, ColorProxyModel, ListModel, Model_11466, TestItemModel, QTBUG53221_Model, SimpleModel, CustomRoleNameModel, CustomDataProxy, TestModel, AppendStringProxy, NonMultiDataRoleModel, StringListModel, TableModel, StorageModel, TreeModel, DomModel, Model, TreeModel, TableModel, MimetypeModel, QtTestModel, SpanModel, QtTestTableModel, QtTestModel, QSqlTableModel, QtTestTableModel, EvilModel, QtTestModel, QtTestModel, QtTestModel, QtTestTableModel, CustomModel, QStreamHelper, MyAbstractItemModel, Model, DataChangedModel, QEmptyItemModel, and RandomListModel.
|
signal |
This signal is emitted whenever the data in an existing item changes.
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.
When reimplementing the setData() function, this signal must be emitted explicitly.
The optional roles argument can be used to specify which data roles have actually been modified. An empty vector in the roles argument means that all roles should be considered modified. The order of elements in the roles argument does not have any relevance.
|
protected |
Definition at line 2783 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in QTreeModel, QTableModel, DragDropListModel, QStandardItemModel, QFileSystemModel, QSortFilterProxyModel, QIdentityProxyModel, QConcatenateTablesProxyModel, QAbstractProxyModel, QAbstractListModel, QAbstractTableModel, PiecesModel, and DropTestModel.
Definition at line 2233 of file qabstractitemmodel.cpp.
|
protected |
Definition at line 2774 of file qabstractitemmodel.cpp.
|
protected |
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.
Definition at line 3237 of file qabstractitemmodel.cpp.
|
protected |
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.
Definition at line 2926 of file qabstractitemmodel.cpp.
|
protected |
Ends a column move operation.
When implementing a subclass, you must call this function after moving data within the model's underlying data store.
Definition at line 3373 of file qabstractitemmodel.cpp.
|
protected |
Ends a row move operation.
When implementing a subclass, you must call this function after moving data within the model's underlying data store.
Definition at line 3154 of file qabstractitemmodel.cpp.
|
protected |
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.
Definition at line 3292 of file qabstractitemmodel.cpp.
|
protected |
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.
Definition at line 2981 of file qabstractitemmodel.cpp.
|
protected |
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().
Definition at line 3433 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in QSqlQueryModel, FetchMoreModel, QFileSystemModel, QSortFilterProxyModel, QAbstractProxyModel, FileListModel, QtTestModel, QtTestModel, and QtTestTableModel.
Definition at line 2447 of file qabstractitemmodel.cpp.
|
virtual |
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
).
Reimplemented in QtTestTableModel, TstMoveModel, CheckerModel, QTreeModel, QTableModel, QListModel, StringListModel, DragDropListModel, TableModel, QUrlModel, QSqlTableModel, QStandardItemModel, QFileSystemModel, QStringListModel, QSortFilterProxyModel, QConcatenateTablesProxyModel, QAbstractProxyModel, QAbstractListModel, QAbstractTableModel, MyModel, StorageModel, TreeModel, DomModel, PiecesModel, Model, TreeModel, TableModel, EditableSqlModel, and LocaleModel.
Definition at line 2477 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in QtTestModel, TstMoveModel, QtTestModel, QCompletionModel, QStandardItemModel, QFileSystemModel, QSortFilterProxyModel, QAbstractProxyModel, QTreeModel, Model, MyAbstractItemModel, QStreamHelper, QtTestModel, and QEmptyItemModel.
Definition at line 2003 of file qabstractitemmodel.cpp.
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}.
Definition at line 1985 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in QtTestModel, CheckerModel, QtTestModel, StringListModel, TableModel, QSqlTableModel, QSqlQueryModel, QStandardItemModel, QFileSystemModel, QTransposeProxyModel, QSortFilterProxyModel, QIdentityProxyModel, QConcatenateTablesProxyModel, QAbstractProxyModel, TreeModel, DomModel, ImageModel, TreeModel, LocaleModel, QTreeModel, QTableModel, MyModel, StorageModel, Model, and TableModel.
Definition at line 2715 of file qabstractitemmodel.cpp.
|
signal |
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 to the last need to be updated.
When reimplementing the setHeaderData() function, this signal must be emitted explicitly.
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 class description for details).
|
pure virtual |
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.
Implemented in StepTreeModel, MyAbstractItemModel, SelectionProxyModel, QStreamHelper, SubQAbstractProxyModel, QEmptyItemModel, QListModel, QAbstractListModel, SwappingProxy, EvilModel, QtTestModel, SimpleModel, DynamicTreeModel, QtTestModel, QtTestModel, QUndoModel, QTableModel, QStandardItemModel, QFileSystemModel, QTransposeProxyModel, QSortFilterProxyModel, QIdentityProxyModel, QConcatenateTablesProxyModel, QAbstractTableModel, TreeModel, DomModel, TreeModel, LocaleModel, ListModel, Model_11466, QTreeModel, Model, TstMoveModel, QCompletionModel, QTBUG53221_Model, and DataChangedModel.
|
inline |
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}.
Definition at line 444 of file qabstractitemmodel.h.
|
virtual |
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.
Reimplemented in MyAbstractItemModel, QtTestTableModel, QtTestTableModel, TableModel, TreeModel, QTableModel, QtTestModel, QSqlQueryModel, QStandardItemModel, QTransposeProxyModel, QSortFilterProxyModel, QIdentityProxyModel, and QTreeModel.
Definition at line 2348 of file qabstractitemmodel.cpp.
|
inline |
Inserts a single row before the given row in the child items of the parent specified.
Returns {true} if the row is inserted; otherwise returns
{false}.
Definition at line 442 of file qabstractitemmodel.h.
|
virtual |
{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.
Reimplemented in MyAbstractItemModel, QtTestTableModel, QtTestTableModel, QTableModel, QListModel, XResetModel, QtTestModel, QSqlTableModel, QStandardItemModel, QTransposeProxyModel, QStringListModel, QSortFilterProxyModel, QIdentityProxyModel, QTreeModel, TableModel, TreeModel, StringListModel, and TableModel.
Definition at line 2319 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in QConcatenateTablesProxyModel, AppendStringProxy, QTreeModel, QTableModel, QListModel, QStandardItemModel, QTransposeProxyModel, QStringListModel, and QAbstractProxyModel.
Definition at line 2037 of file qabstractitemmodel.cpp.
|
signal |
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().
The optional parents parameter is used to give a more specific notification about what parts of the layout of the model are changing. An empty list indicates a change to the layout of the entire model. The order of elements in the parents list is not significant. The optional hint parameter is used to give a hint about what is happening while the model is relayouting.
|
signal |
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.
When subclassing QAbstractItemModel or QAbstractProxyModel, ensure that you emit 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.
The optional parents parameter is used to give a more specific notification about what parts of the layout of the model are changing. An empty list indicates a change to the layout of the entire model. The order of elements in the parents list is not significant. The optional hint parameter is used to give a hint about what is happening while the model is relayouting.
Subclasses should update any persistent model indexes before emitting layoutChanged(). In other words, when the structure changes:
\list
|
virtual |
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 cannot 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.
Reimplemented in CheckerModel, QSortFilterProxyModel, and QIdentityProxyModel.
Definition at line 2533 of file qabstractitemmodel.cpp.
|
virtual |
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, \nullptr is returned rather than a serialized empty list.
Reimplemented in QTreeModel, QTableModel, QListModel, DragDropListModel, QUrlModel, QStandardItemModel, QFileSystemModel, QSortFilterProxyModel, QConcatenateTablesProxyModel, QAbstractProxyModel, and PiecesModel.
Definition at line 2156 of file qabstractitemmodel.cpp.
|
virtual |
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().
Reimplemented in StandardItemModelWithCustomDragAndDrop, QTreeModel, QTableModel, QListModel, DragDropListModel, QUrlModel, QStandardItemModel, QFileSystemModel, QSortFilterProxyModel, QConcatenateTablesProxyModel, QAbstractProxyModel, and PiecesModel.
Definition at line 2136 of file qabstractitemmodel.cpp.
|
signal |
This signal is emitted when beginResetModel() is called, before the model's internal state (e.g. persistent model indexes) has been invalidated.
|
signal |
This signal is emitted when endResetModel() is called, after the model's internal state (e.g. persistent model indexes) has been invalidated.
Note that if a model is reset it should be considered that all information previously retrieved from it is invalid. This includes but is not limited to the rowCount() and columnCount(), flags(), data retrieved through data(), and roleNames().
|
inline |
On models that support this, moves sourceColumn from sourceParent to destinationChild under destinationParent.
Returns {true} if the columns were successfully moved; otherwise returns
{false}.
Definition at line 453 of file qabstractitemmodel.h.
|
virtual |
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.
Reimplemented in QtTestModel, QTransposeProxyModel, and QIdentityProxyModel.
Definition at line 2432 of file qabstractitemmodel.cpp.
|
inline |
On models that support this, moves sourceRow from sourceParent to destinationChild under destinationParent.
Returns {true} if the rows were successfully moved; otherwise returns
{false}.
Definition at line 450 of file qabstractitemmodel.h.
|
virtual |
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.
Reimplemented in TstMoveModel, QtTestModel, QListModel, QTransposeProxyModel, QStringListModel, and QIdentityProxyModel.
Definition at line 2411 of file qabstractitemmodel.cpp.
|
virtual |
Fills the roleDataSpan with the requested data for the given index.
The default implementation will call simply data() for each role in the span. A subclass can reimplement this function to provide data to views more efficiently:
In the snippet above, {index} is the same for the entire call. This means that accessing to the necessary data structures in order to retrieve the information for
{index} can be done only once (hoisting the relevant code out of the loop).
The usage of QModelRoleData::setData(), or similarly QVariant::setValue(), is encouraged over constructing a QVariant separately and using a plain assignment operator; this is because the former allow to re-use the memory already allocated for the QVariant object stored inside a QModelRoleData, while the latter always allocates the new variant and then destroys the old one.
Note that views may call multiData() with spans that have been used in previous calls, and therefore may already contain some data. Therefore, it is imperative that if the model cannot return the data for a given role, then it must clear the data in the corresponding QModelRoleData object. This can be done by calling QModelRoleData::clearData(), or similarly by setting a default constructed QVariant, and so on. Failure to clear the data will result in the view believing that the "old" data is meant to be used for the corresponding role.
Finally, in order to avoid code duplication, a subclass may also decide to reimplement data() in terms of multiData(), by supplying a span of just one element:
Reimplemented in QStandardItemModel.
Definition at line 3699 of file qabstractitemmodel.cpp.
|
inline |
Returns a pointer to the parent object.
Definition at line 409 of file qobject.h.
|
pure virtual |
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.
Implemented in SwappingProxy, Model_11466, EvilModel, QtTestModel, TstMoveModel, DynamicTreeModel, StepTreeModel, QtTestModel, QTransposeProxyModel, QConcatenateTablesProxyModel, TreeModel, TreeModel, LocaleModel, CheckerModel, QUndoModel, QTreeModel, QStandardItemModel, QFileSystemModel, QSortFilterProxyModel, QIdentityProxyModel, DomModel, Model, QCompletionModel, MyAbstractItemModel, QTBUG53221_Model, SimpleModel, SelectionProxyModel, QStreamHelper, SubQAbstractProxyModel, QtTestModel, and QEmptyItemModel.
|
protected |
Returns the list of indexes stored as persistent indexes in the model.
Definition at line 3507 of file qabstractitemmodel.cpp.
|
inline |
Removes the given column from the child items of the parent specified.
Returns {true} if the column is removed; otherwise returns
{false}.
Definition at line 448 of file qabstractitemmodel.h.
|
virtual |
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.
Reimplemented in MyAbstractItemModel, QtTestTableModel, QtTestTableModel, TableModel, TreeModel, QTableModel, QtTestModel, QSqlTableModel, QSqlRelationalTableModel, QSqlQueryModel, QStandardItemModel, QTransposeProxyModel, QSortFilterProxyModel, and QIdentityProxyModel.
Definition at line 2390 of file qabstractitemmodel.cpp.
|
inline |
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.
Definition at line 446 of file qabstractitemmodel.h.
|
virtual |
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.
Reimplemented in MyAbstractItemModel, QtTestTableModel, QtTestTableModel, QTableModel, QListModel, XResetModel, QtTestModel, QTreeModel, QSqlTableModel, QStandardItemModel, QTransposeProxyModel, QStringListModel, QSortFilterProxyModel, QIdentityProxyModel, PiecesModel, TableModel, TreeModel, StringListModel, and TableModel.
Definition at line 2369 of file qabstractitemmodel.cpp.
|
protectedvirtualslot |
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 which maintain extra data.
Definition at line 1180 of file qabstractitemmodel.cpp.
|
virtualslot |
Lets the model know that it should discard cached information. This function is typically used for row editing.
Reimplemented in QAbstractProxyModel.
Definition at line 2699 of file qabstractitemmodel.cpp.
|
virtual |
Returns the model's role names.
The default role names set by Qt are:
\table \header
Reimplemented in CustomRoleNameModel, AnotherStandardItemModelWithCustomRoleNames, StandardItemModelWithCustomRoleNames, OverrideRoleNamesAndDragActions, ModelWithCustomRole, QSqlQueryModel, QStandardItemModel, QFileSystemModel, and QAbstractProxyModel.
Definition at line 2673 of file qabstractitemmodel.cpp.
|
pure virtual |
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.
Implemented in SwappingProxy, EvilModel, QtTestModel, BigModel, CheckFilteredIndexes::TableModel, StepTreeModel, DropOnOddRows, CustomRoleNameModel, QtTestModel, QUndoModel, QTableModel, QListModel, StringListModel, TableModel, QSqlTableModel, QSqlQueryModel, QStandardItemModel, QFileSystemModel, QTransposeProxyModel, QStringListModel, QSortFilterProxyModel, QIdentityProxyModel, QConcatenateTablesProxyModel, MyModel, MyModel, MyModel, MyModel, MyModel, TreeModel, DomModel, ImageModel, FileListModel, TreeModel, LocaleModel, ListModel, Model_11466, TestItemModel, DataChangedModel, QtTestModel, QTreeModel, StorageModel, PiecesModel, Model, TableModel, DynamicTreeModel, QCompletionModel, TstMoveModel, SpanModel, QtTestTableModel, QtTestTableModel, SimpleModel, CustomStringListModel, QtTestTableModel, QStreamHelper, RandomListModel, MyAbstractItemModel, Model, QtTestModel, QTBUG53221_Model, QtTestModel, SelectionProxyModel, TestModel, SubQAbstractProxyModel, NonMultiDataRoleModel, and QEmptyItemModel.
|
signal |
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 item.
|
signal |
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.
{Note:} 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.
|
signal |
This signal is emitted just before rows are removed from the model. The items that will be removed are those between first and last inclusive, under the given parent item.
|
signal |
This signal is emitted after rows have been inserted into the model. The new items are those between first and last inclusive, under the given parent item.
|
signal |
This signal is emitted after rows have been moved within the model. The items between start and end inclusive, under the given parent item have been moved to destination starting at the row row.
{Note:} 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.
|
signal |
This signal is emitted after rows have been removed from the model. The removed items are those between first and last inclusive, under the given parent item.
|
virtual |
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.
Reimplemented in QSqlRelationalTableModel, CheckerModel, SetRecordReimplModel, StringListModel, TableModel, QUrlModel, QSqlTableModel, QStandardItemModel, QFileSystemModel, QStringListModel, QSortFilterProxyModel, QConcatenateTablesProxyModel, QAbstractProxyModel, MyModel, TreeModel, TableModel, LocaleModel, ListModel, CustomStringListModel, QTreeModel, QTableModel, QListModel, EditableSqlModel, QtTestModel, MyAbstractItemModel, and TestModel.
Definition at line 2061 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in CheckerModel, QSqlQueryModel, QStandardItemModel, QTransposeProxyModel, QSortFilterProxyModel, QAbstractProxyModel, TreeModel, QTreeModel, and QTableModel.
Definition at line 2735 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in QTableModel, QStandardItemModel, QTransposeProxyModel, QStringListModel, QConcatenateTablesProxyModel, and QAbstractProxyModel.
Definition at line 2106 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in QFileSystemModel, QStringListModel, QSortFilterProxyModel, QIdentityProxyModel, QAbstractProxyModel, QAbstractListModel, and QAbstractTableModel.
Definition at line 2022 of file qabstractitemmodel.cpp.
|
virtual |
Sorts the model by column in the given order.
The base class implementation does nothing.
Reimplemented in CheckerModel, QStandardItemModel, QFileSystemModel, QTransposeProxyModel, QStringListModel, QSortFilterProxyModel, QAbstractProxyModel, QTreeModel, QTableModel, QListModel, and QSqlTableModel.
Definition at line 2491 of file qabstractitemmodel.cpp.
|
virtual |
Returns the row and column span of the item represented by index.
Reimplemented in QTransposeProxyModel, QSortFilterProxyModel, QConcatenateTablesProxyModel, and QAbstractProxyModel.
Definition at line 2637 of file qabstractitemmodel.cpp.
|
virtualslot |
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}.
Reimplemented in QAbstractProxyModel.
Definition at line 2687 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in StandardItemModelWithCustomDragAndDrop, OverrideRoleNamesAndDragActions, and QAbstractProxyModel.
Definition at line 2287 of file qabstractitemmodel.cpp.
|
virtual |
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.
Reimplemented in StandardItemModelWithCustomDragAndDrop, OverrideDropActions, QTreeModel, QTableModel, DragDropListModel, QStandardItemModel, QFileSystemModel, QStringListModel, QSortFilterProxyModel, QAbstractProxyModel, and PiecesModel.
Definition at line 2271 of file qabstractitemmodel.cpp.
|
friend |
Definition at line 274 of file qabstractitemmodel.h.
|
friend |
Definition at line 275 of file qabstractitemmodel.h.
|
friend |
Definition at line 273 of file qabstractitemmodel.h.