Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
org.qtproject.qt.android.QtAbstractItemModel Class Referenceabstract
+ Inheritance diagram for org.qtproject.qt.android.QtAbstractItemModel:
+ Collaboration diagram for org.qtproject.qt.android.QtAbstractItemModel:

Public Member Functions

 QtAbstractItemModel ()
 
abstract int columnCount (QtModelIndex parent)
 
abstract Object data (QtModelIndex index, int role)
 
abstract QtModelIndex index (int row, int column, QtModelIndex parent)
 
abstract QtModelIndex parent (QtModelIndex index)
 
abstract int rowCount (QtModelIndex parent)
 
native boolean canFetchMore (QtModelIndex parent)
 
native void fetchMore (QtModelIndex parent)
 
native boolean hasChildren (QtModelIndex parent)
 
native boolean hasIndex (int row, int column, QtModelIndex parent)
 
HashMap< Integer, String > roleNames ()
 
QtModelIndex sibling (int row, int column, QtModelIndex parent)
 

Protected Member Functions

final void beginInsertColumns (QtModelIndex parent, int first, int last)
 
final void beginInsertRows (QtModelIndex parent, int first, int last)
 
final boolean beginMoveColumns (QtModelIndex sourceParent, int sourceFirst, int sourceLast, QtModelIndex destinationParent, int destinationChild)
 
final boolean beginMoveRows (QtModelIndex sourceParent, int sourceFirst, int sourceLast, QtModelIndex destinationParent, int destinationChild)
 
final void beginRemoveColumns (QtModelIndex parent, int first, int last)
 
final void beginRemoveRows (QtModelIndex parent, int first, int last)
 
final void beginResetModel ()
 
final QtModelIndex createIndex (int row, int column, long id)
 
final void endInsertColumns ()
 
final void endInsertRows ()
 
final void endMoveColumns ()
 
final void endMoveRows ()
 
final void endRemoveColumns ()
 
final void endRemoveRows ()
 
final void endResetModel ()
 

Detailed Description

QtAbstractItemModel is a base class for implementing custom models in Java, similar to the C++ QAbstractItemModel.

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 extend it to create new models.

A QtAbstractItemModel can be used as the underlying data model for the item view elements in QML.

If you need a model to use with an item view, such as QML's ListView element, you should consider extending QtAbstractListModel instead of this class.

The underlying data model is exposed to views and delegates as a hierarchy of tables. If you do not use the hierarchy, the model is a simple table of rows and columns. Each item has a unique index specified by a QtModelIndex.

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(int, int) method. Each index may have a sibling(int, int) index; child items have a parent() index.

Each item has data elements associated with it, and they can be retrieved by specifying a role to the model's data(QtModelIndex, int) function.

If an item has child objects, hasChildren(QtModelIndex) returns true for the corresponding index.

The model has a rowCount(QtModelIndex) and a columnCount(QtModelIndex) for each level of the hierarchy.

Extending QtAbstractItemModel:

Some general guidelines for sub-classing models are available in the https://doc.qt.io/qt-6/model-view-programming.html#model-subclassing-reference model sub-classing reference.

When sub-classing QtAbstractItemModel, at the very least, you must implement index(int, int), parent(QtModelIndex),rowCount(QtModelIndex), columnCount(QtModelIndex), and data(QtModelIndex, int). These abstract methods are used in all models.

You can also re-implement hasChildren(QtModelIndex) to provide special behavior for models where the implementation of rowCount(QtModelIndex) is expensive. This makes it possible for models to restrict the amount of data requested by views and can be used as a way to implement the population of model data.

Custom models need to create model indexes for other components to use. To do this, call createIndex(int, int, long) with suitable row and column numbers for the item, and a long type identifier for it. The combination of these values must be unique for each item. Custom models typically use these unique identifiers in other re-implemented functions to retrieve item data and access information about the item's parents and children.

To create models that populate incrementally, you can re-implement fetchMore(QtModelIndex) and canFetchMore(QtModelIndex). If the re-implementation of fetchMore(QtModelIndex) adds rows to the model, QtAbstractItemModel#beginInsertRows(QtModelIndex, int, int) and QtAbstractItemModel#endInsertRows() must be called.

Since
6.8

Definition at line 74 of file QtAbstractItemModel.java.

Constructor & Destructor Documentation

◆ QtAbstractItemModel()

org.qtproject.qt.android.QtAbstractItemModel.QtAbstractItemModel ( )
inline

Constructs a new QtAbstractItemModel.

Definition at line 79 of file QtAbstractItemModel.java.

Member Function Documentation

◆ beginInsertColumns()

final void org.qtproject.qt.android.QtAbstractItemModel.beginInsertColumns ( QtModelIndex parent,
int first,
int last )
inlineprotected

Begins a column insertion operation.

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.

See also
#endInsertColumns()

Definition at line 231 of file QtAbstractItemModel.java.

References org.qtproject.qt.android.QtAbstractItemModel.parent().

+ Here is the call graph for this function:

◆ beginInsertRows()

final void org.qtproject.qt.android.QtAbstractItemModel.beginInsertRows ( QtModelIndex parent,
int first,
int last )
inlineprotected

Begins a row insertion operation. Parent index corresponds to the parent into which the new rows are inserted; first and last are the row numbers the new rows will have after they have been inserted.

See also
#endInsertRows()

Definition at line 243 of file QtAbstractItemModel.java.

References org.qtproject.qt.android.QtAbstractItemModel.parent().

+ Here is the call graph for this function:

◆ beginMoveColumns()

final boolean org.qtproject.qt.android.QtAbstractItemModel.beginMoveColumns ( QtModelIndex sourceParent,
int sourceFirst,
int sourceLast,
QtModelIndex destinationParent,
int destinationChild )
inlineprotected

Begins a column move operation.

When re-implementing a subclass, this method simplifies moving entities in your model. This method is responsible for moving persistent indexes in the model.

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. 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.

See also
endMoveColumns()

Definition at line 279 of file QtAbstractItemModel.java.

◆ beginMoveRows()

final boolean org.qtproject.qt.android.QtAbstractItemModel.beginMoveRows ( QtModelIndex sourceParent,
int sourceFirst,
int sourceLast,
QtModelIndex destinationParent,
int destinationChild )
inlineprotected

Begins a row move operation.

When re-implementing a subclass, this method simplifies moving entities in your model.

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.

PossibleOps

See also
#endMoveRows()

Definition at line 320 of file QtAbstractItemModel.java.

◆ beginRemoveColumns()

final void org.qtproject.qt.android.QtAbstractItemModel.beginRemoveColumns ( QtModelIndex parent,
int first,
int last )
inlineprotected

Begins a column removal operation.

When re-implementing 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.

RemoveColums

See also
#endRemoveColumns()

Definition at line 340 of file QtAbstractItemModel.java.

References org.qtproject.qt.android.QtAbstractItemModel.parent().

+ Here is the call graph for this function:

◆ beginRemoveRows()

final void org.qtproject.qt.android.QtAbstractItemModel.beginRemoveRows ( QtModelIndex parent,
int first,
int last )
inlineprotected

Begins a row removal operation.

When re-implementing 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.

RemoveRows

See also
#endRemoveRow()

Definition at line 356 of file QtAbstractItemModel.java.

References org.qtproject.qt.android.QtAbstractItemModel.parent().

+ Here is the call graph for this function:

◆ beginResetModel()

final void org.qtproject.qt.android.QtAbstractItemModel.beginResetModel ( )
inlineprotected

Begins a model reset operation.

A reset operation resets the model to its current state in any attached views.

Note: any views attached to this model will also be reset.

When a model is reset, any previous data reported from the model is now invalid and has to be queried again. This also means that the current 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.

See also
#modelAboutToBeReset()
#modelReset()
#endResetModel()

Definition at line 382 of file QtAbstractItemModel.java.

◆ canFetchMore()

native boolean org.qtproject.qt.android.QtAbstractItemModel.canFetchMore ( QtModelIndex parent)

Returns whether more items can be fetched for the given parent index.

Parameters
parentThe parent index.
Returns
True if more items can be fetched, false otherwise.

◆ columnCount()

abstract int org.qtproject.qt.android.QtAbstractItemModel.columnCount ( QtModelIndex parent)
abstract

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: @Override int columnCount(const QtModelIndex parent) { return 3; }

When implementing a table-based model, columnCount() should return 0, when the parent is valid.

Parameters
parentThe parent index.
Returns
The number of columns.
See also
#rowCount(QtModelIndex)

Reimplemented in org.qtproject.qt.android.QtAbstractListModel.

◆ createIndex()

final QtModelIndex org.qtproject.qt.android.QtAbstractItemModel.createIndex ( int row,
int column,
long id )
inlineprotected

Creates a model index for the given row and column with the internal identifier id.

This function provides a consistent interface, which model sub classes must use to create model indexes.

Definition at line 391 of file QtAbstractItemModel.java.

Referenced by org.qtproject.qt.android.QtAbstractListModel.index().

+ Here is the caller graph for this function:

◆ data()

abstract Object org.qtproject.qt.android.QtAbstractItemModel.data ( QtModelIndex index,
int role )
abstract

Returns the data for the given index and role. Types conversions are: QML <- Java int <- Integer string <- String double <- Double real <- Double bool <- Boolean

Parameters
indexThe index.
roleThe role.
Returns
The data object.

◆ endInsertColumns()

final void org.qtproject.qt.android.QtAbstractItemModel.endInsertColumns ( )
inlineprotected

Ends a column insertion operation.

When re-implementing insertColumns() in a subclass, you must call this function after inserting data into the model's underlying data store.

See also
beginInsertColumns()

Definition at line 404 of file QtAbstractItemModel.java.

◆ endInsertRows()

final void org.qtproject.qt.android.QtAbstractItemModel.endInsertRows ( )
inlineprotected

Ends a row insertion operation.

When re-implementing insertRows() in a subclass, you must call this function after inserting data into the model's underlying data store.

See also
beginInsertRows()

Definition at line 413 of file QtAbstractItemModel.java.

◆ endMoveColumns()

final void org.qtproject.qt.android.QtAbstractItemModel.endMoveColumns ( )
inlineprotected

Ends a column move operation.

When implementing a subclass, you must call this function after moving data within the model's underlying data store.

See also
#beginMoveColumns()

Definition at line 423 of file QtAbstractItemModel.java.

◆ endMoveRows()

final void org.qtproject.qt.android.QtAbstractItemModel.endMoveRows ( )
inlineprotected

Ends a row move operation.

When implementing a subclass, you must call this function after moving data within the model's underlying data store.

See also
beginMoveRows()

Definition at line 433 of file QtAbstractItemModel.java.

◆ endRemoveColumns()

final void org.qtproject.qt.android.QtAbstractItemModel.endRemoveColumns ( )
inlineprotected

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.

See also
beginRemoveColumns()

Definition at line 442 of file QtAbstractItemModel.java.

◆ endRemoveRows()

final void org.qtproject.qt.android.QtAbstractItemModel.endRemoveRows ( )
inlineprotected

Ends a row move operation.

When implementing a subclass, you must call this function after moving data within the model's underlying data store.

See also
#beginMoveRows(QtModelIndex sourceParent, int sourceFirst, int sourceLast, QtModelIndexdestinationParent, int destinationChild)

Definition at line 452 of file QtAbstractItemModel.java.

◆ endResetModel()

final void org.qtproject.qt.android.QtAbstractItemModel.endResetModel ( )
inlineprotected

Completes a model reset operation.

You must call this function after resetting any internal data structure in your model.

See also
#beginResetModel()

Definition at line 460 of file QtAbstractItemModel.java.

◆ fetchMore()

native void org.qtproject.qt.android.QtAbstractItemModel.fetchMore ( QtModelIndex parent)

Fetches any available data for the items with the parent specified by the parent index.

Parameters
parentThe parent index.

◆ hasChildren()

native boolean org.qtproject.qt.android.QtAbstractItemModel.hasChildren ( QtModelIndex parent)

Returns true if the parent has any children; otherwise, returns false. Use rowCount() on the parent to get the number of children.

Parameters
parentThe parent index.
Returns
True if the parent has children, false otherwise.
See also
#parent(QtModelIndex index)
index(int row, int column, QtModelIndex parent)

Reimplemented in org.qtproject.qt.android.QtAbstractListModel.

◆ hasIndex()

native boolean org.qtproject.qt.android.QtAbstractItemModel.hasIndex ( int row,
int column,
QtModelIndex parent )

Returns true if the model returns a valid QModelIndex for row and column with parent, otherwise returns {false}.

Parameters
rowThe row.
columnThe column.
parentThe parent index.
Returns
True if the index exists, false otherwise.

Referenced by org.qtproject.qt.android.QtAbstractListModel.index().

+ Here is the caller graph for this function:

◆ index()

abstract QtModelIndex org.qtproject.qt.android.QtAbstractItemModel.index ( int row,
int column,
QtModelIndex parent )
abstract

Returns the index for the specified row and column for the supplied parent index. When re-implementing this function in a subclass, call createIndex() to generate model indexes that other components can use to refer to items in your model.

Parameters
rowThe row.
columnThe column.
parentThe parent index.
Returns
The index.
See also
#createIndex(int row, int column, long id)

Reimplemented in org.qtproject.qt.android.QtAbstractListModel.

◆ parent()

abstract QtModelIndex org.qtproject.qt.android.QtAbstractItemModel.parent ( QtModelIndex index)
abstract

Returns the parent of the model item with the given index. If the item has no parent, then an invalid QtModelIndex 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 re-implementing this function in a subclass, the column of the returned QtModelIndex would be 0.

When re-implementing this function in a subclass, be careful to avoid calling QtModelIndex member functions, such as QtModelIndex::parent(), since indexes belonging to your model will call your implementation, leading to infinite recursion.

Parameters
indexThe index.
Returns
The parent index.
See also
#createIndex(int row, int column, long id)

Reimplemented in org.qtproject.qt.android.QtAbstractListModel.

Referenced by org.qtproject.qt.android.QtAbstractItemModel.beginInsertColumns(), org.qtproject.qt.android.QtAbstractItemModel.beginInsertRows(), org.qtproject.qt.android.QtAbstractItemModel.beginRemoveColumns(), org.qtproject.qt.android.QtAbstractItemModel.beginRemoveRows(), and org.qtproject.qt.android.QtAbstractItemModel.sibling().

+ Here is the caller graph for this function:

◆ roleNames()

HashMap< Integer, String > org.qtproject.qt.android.QtAbstractItemModel.roleNames ( )
inline

Returns a map of role names. You must override this to provide your own role names or the defaults will be used.

Returns
The role names map.

Definition at line 199 of file QtAbstractItemModel.java.

◆ rowCount()

abstract int org.qtproject.qt.android.QtAbstractItemModel.rowCount ( QtModelIndex parent)
abstract

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 the parent.

Note: when implementing a table-based model, rowCount() should return 0, when the parent is valid.

Parameters
parentThe parent index.
Returns
The number of rows.
See also
#columnCount(QtModelIndex parent)

Referenced by org.qtproject.qt.android.QtAbstractListModel.hasChildren().

+ Here is the caller graph for this function:

◆ sibling()

QtModelIndex org.qtproject.qt.android.QtAbstractItemModel.sibling ( int row,
int column,
QtModelIndex parent )
inline

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 to optimize a specific implementation.

Parameters
rowThe row.
columnThe column.
parentThe parent index.
Returns
The sibling index.

Reimplemented in org.qtproject.qt.android.QtAbstractListModel.

Definition at line 218 of file QtAbstractItemModel.java.

References org.qtproject.qt.android.QtAbstractItemModel.parent().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: