Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.trolltech.qt.core
Class QAbstractItemModel

    java.lang.Object
      com.trolltech.qt.QSignalEmitter
          com.trolltech.qt.QtJambiObject
              com.trolltech.qt.core.QObject
                  com.trolltech.qt.core.QAbstractItemModel

All Implemented Interfaces:
  QtJambiInterface

Direct Known Subclasses:
  QAbstractListModel, QAbstractProxyModel, QAbstractTableModel, QDirModel, QFileSystemModel, QProxyModel, QStandardItemModel, QTreeModel

    public abstract class QAbstractItemModel

extends QObject

The `QAbstractItemModel` class provides the abstract interface for item model classes. 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 Model/View Classes and is part of Qt's model/view framework.

If you need a model to use with a `QListView` or a `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 don't 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 that is obtained 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 each of these can be retrieved by specifying a role (see `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 `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 `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.

If the model is sortable, it can be sorted with `sort()`.

## Subclassing

Note: Some general guidelines for subclassing models are available in the Model Subclassing Reference.

When subclassing `QAbstractItemModel`, at the very least you must implement `index()`, `parent()`, `rowCount()`, `columnCount()`, and `data()`. These functions are used in all read-only models, and form the basis of editable models.

You can also reimplement `hasChildren()` to provide special behavior for models where the implementation of `rowCount()` 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 lazy population of model data.

To enable editing in your model, you must also implement `setData()`, and reimplement `flags()` to ensure that `ItemIsEditable` is returned. You can also reimplement `headerData()` and `setHeaderData()` to control the way the headers for your model are presented.

Note that the `dataChanged()` and `headerDataChanged()` signals must be emitted explicitly when reimplementing the `setData()` and `setHeaderData()` functions, respectively.

Custom models need to create model indexes for other components to use. To do this, call `createIndex()` with suitable row and column numbers for the item, and an identifier for it, either as a pointer or as an integer value. The combination of these values must be unique for each item. Custom models typically use these unique identifiers in other reimplemented functions to retrieve item data and access information about the item's parents and children. See the Simple Tree Model example for more information about unique identifiers.

It is not necessary to support every role defined in `Qt::ItemDataRole` . Depending on the type of data contained within a model, it may only be useful to implement the `data()` function to return valid information for some of the more common roles. Most models provide at least a textual representation of item data for the `Qt::DisplayRole` , and well-behaved models should also provide valid information for the `Qt::ToolTipRole` and `Qt::WhatsThisRole` . Supporting these roles enables models to be used with standard Qt views. However, for some models that handle highly-specialized data, it may be appropriate to provide data only for user-defined roles.

Models that provide interfaces to resizable data structures can provide implementations of `insertRows()`, `removeRows()`, `insertColumns()`, and `removeColumns()`. When implementing these functions, it is important to notify any connected views about changes to the model's dimensions both before and after they occur:

- An `insertRows()` implementation must call `beginInsertRows()`before inserting new rows into the data structure, and it must call `endInsertRows()`immediately afterwards.
- An `insertColumns()` implementation must call `beginInsertColumns()`before inserting new columns into the data structure, and it must call `endInsertColumns()`immediately afterwards.
- A `removeRows()` implementation must call `beginRemoveRows()`before the rows are removed from the data structure, and it must call `endRemoveRows()`immediately afterwards.
- A `removeColumns()` implementation must call `beginRemoveColumns()`before the columns are removed from the data structure, and it must call `endRemoveColumns()`immediately afterwards.

The private signals that these functions emit give attached components the chance to take action before any data becomes unavailable. The encapsulation of the insert and remove operations with these begin and end functions also enables the model to manage `persistent model indexes` correctly. If you want selections to be handled properly, you must ensure that you call these functions.

See also:
  Model Classes, Model Subclassing Reference, QModelIndex, `QAbstractItemView`, Using Drag and Drop with Item Views, Simple DOM Model Example, and Simple Tree Model Example.

Nested Class Summary

Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
`QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9`

Field Summary
`QSignalEmitter.Signal2` | `dataChanged` This signal is emitted whenever the data in an existing item changes.
`QSignalEmitter.Signal3` | `headerDataChanged` This signal is emitted whenever a header is changed.
`QSignalEmitter.Signal0` | `layoutAboutToBeChanged` This signal is emitted just before the layout of a model is changed.
`QSignalEmitter.Signal0` | `layoutChanged` This signal is emitted whenever the layout of items exposed by the model has changed; for example, when the model has been sorted.

Constructor Summary
`QAbstractItemModel()` Constructs an abstract item model with the given `parent`.
`QAbstractItemModel(QObject parent)` Constructs an abstract item model with the given `parent`.

Method Summary
`protected void` | `beginInsertColumns(QModelIndex parent, int first, int last)` Begins a column insertion operation.
`protected void` | `beginInsertRows(QModelIndex parent, int first, int last)` Begins a row insertion operation.
`protected void` | `beginRemoveColumns(QModelIndex parent, int first, int last)` Begins a column removal operation.
`protected void` | `beginRemoveRows(QModelIndex parent, int first, int last)` Begins a row removal operation.
`QModelIndex` | `buddy(QModelIndex index)` Returns a model index for the buddy of the item represented by `index`.
`boolean` | `canFetchMore(QModelIndex parent)` Returns true if there is more data available for `parent`, otherwise false.
`protected void` | `changePersistentIndex(QModelIndex from, QModelIndex to)` Changes the `QPersistentModelIndex` that is equal to the given `from` model index to the given `to` model index.
`protected void` | `changePersistentIndexList(java.util.List from, java.util.List to)` Changes the `QPersistentModelIndexes` that is equal to the indexes in the given `from` model index list to the given `to` model index list.
`int` | `columnCount()` Returns the number of columns for the children of the given `parent`.
`abstract int` | `columnCount(QModelIndex parent)` Returns the number of columns for the children of the given `parent`.
`protected QModelIndex` | `createIndex(int row, int column)` Creates a model index for the given `row` and `column` with the internal pointer `ptr`.
`protected QModelIndex` | `createIndex(int row, int column, int id)` Use QModelIndexQAbstractItemModel.:createIndex(int row, int column, quint32 id) instead.
`protected QModelIndex` | `createIndex(int row, int column, QNativePointer data)` Creates a model index for the given `row` and `column` with the internal pointer `ptr`.
`java.lang.Object` | `data(int row, int col)` Returns the data in the display role at row `row` and column `col`.
`java.lang.Object` | `data(int row, int col, int role)` Returns the data with the specified `role` at row `row` and column `col`
`java.lang.Object` | `data(QModelIndex index)` Returns the data stored under the given `role` for the item referred to by the `index`.
`abstract java.lang.Object` | `data(QModelIndex index, int role)` Returns the data stored under the given `role` for the item referred to by the `index`.
`boolean` | `dropMimeData(QMimeData data, Qt.DropAction action, int row, int column, QModelIndex parent)` Handles the `data` supplied by a drag and drop operation that ended with the given `action`.
`protected void` | `endInsertColumns()` Ends a column insertion operation.
`protected void` | `endInsertRows()` Ends a row insertion operation.
`protected void` | `endRemoveColumns()` Ends a column removal operation.
`protected void` | `endRemoveRows()` Ends a row removal operation.
`void` | `fetchMore(QModelIndex parent)` Fetches any available data for the items with the parent specified by the `parent` index.
`Qt.ItemFlags` | `flags(QModelIndex index)` Returns the item flags for the given `index`.
`static QAbstractItemModel` | `fromNativePointer(QNativePointer nativePointer)` This method returns the QAbstractItemModel instance pointed to by `nativePointer`.
`boolean` | `hasChildren()` Returns true if `parent` has any children; otherwise returns false.
`boolean` | `hasChildren(QModelIndex parent)` Returns true if `parent` has any children; otherwise returns false.
`boolean` | `hasIndex(int row, int column)` Returns true if the model returns a valid QModelIndex for `row` and `column` with `parent`, otherwise returns false.
`boolean` | `hasIndex(int row, int column, QModelIndex parent)` Returns true if the model returns a valid QModelIndex for `row` and `column` with `parent`, otherwise returns false.
`java.lang.Object` | `headerData(int section, Qt.Orientation orientation)` Returns the data for the given `role` and `section` in the header with the specified `orientation`.
`java.lang.Object` | `headerData(int section, Qt.Orientation orientation, int role)` Returns the data for the given `role` and `section` in the header with the specified `orientation`.
`QModelIndex` | `index(int row, int column)` Returns the index of the item in the model specified by the given `row`, `column` and `parent` index.
`abstract QModelIndex` | `index(int row, int column, QModelIndex parent)` Returns the index of the item in the model specified by the given `row`, `column` and `parent` index.
`boolean` | `insertColumn(int column)` Inserts a single column before the given `column` in the child items of the `parent` specified.
`boolean` | `insertColumn(int column, QModelIndex parent)` Inserts a single column before the given `column` in the child items of the `parent` specified.
`boolean` | `insertColumns(int column, int count)` On models that support this, inserts `count` new columns into the model before the given `column`.
`boolean` | `insertColumns(int column, int count, QModelIndex parent)` On models that support this, inserts `count` new columns into the model before the given `column`.
`boolean` | `insertRow(int row)` Inserts a single row before the given `row` in the child items of the `parent` specified.
`boolean` | `insertRow(int row, QModelIndex parent)` Inserts a single row before the given `row` in the child items of the `parent` specified.
`boolean` | `insertRows(int row, int count)` On models that support this, inserts `count` rows into the model before the given `row`.
`boolean` | `insertRows(int row, int count, QModelIndex parent)` On models that support this, inserts `count` rows into the model before the given `row`.
`java.util.SortedMap` | `itemData(QModelIndex index)` Returns a map with values for all predefined roles in the model for the item at the given `index`.
`java.util.List` | `match(QModelIndex start, int role, java.lang.Object value)` This is an overloaded function provided for convenience.
`java.util.List` | `match(QModelIndex start, int role, java.lang.Object value, int hits)` This is an overloaded function provided for convenience.
`java.util.List` | `match(QModelIndex start, int role, java.lang.Object value, int hits, Qt.MatchFlag[] flags)` Returns a list of indexes for the items in the column of the `start` index where the data stored under the given `role` matches the specified `value`.
`java.util.List` | `match(QModelIndex start, int role, java.lang.Object value, int hits, Qt.MatchFlags flags)` Returns a list of indexes for the items in the column of the `start` index where the data stored under the given `role` matches the specified `value`.
`QMimeData` | `mimeData(java.util.List indexes)` Returns an object that contains serialized items of data corresponding to the list of `indexes` specified.
`java.util.List` | `mimeTypes()` Returns a list of MIME types that can be used to describe a list of model indexes.
`abstract QModelIndex` | `parent(QModelIndex child)` Returns the parent of the model item with the given `index`, or QModelIndex() if it has no parent.
`protected java.util.List` | `persistentIndexList()` Returns the list of indexes stored as persistent indexes in the model.
`boolean` | `removeColumn(int column)` Removes the given `column` from the child items of the `parent` specified.
`boolean` | `removeColumn(int column, QModelIndex parent)` Removes the given `column` from the child items of the `parent` specified.
`boolean` | `removeColumns(int column, int count)` On models that support this, removes `count` columns starting with the given `column` under parent `parent` from the model.
`boolean` | `removeColumns(int column, int count, QModelIndex parent)` On models that support this, removes `count` columns starting with the given `column` under parent `parent` from the model.
`boolean` | `removeRow(int row)` Removes the given `row` from the child items of the `parent` specified.
`boolean` | `removeRow(int row, QModelIndex parent)` Removes the given `row` from the child items of the `parent` specified.
`boolean` | `removeRows(int row, int count)` On models that support this, removes `count` rows starting with the given `row` under parent `parent` from the model.
`boolean` | `removeRows(int row, int count, QModelIndex parent)` On models that support this, removes `count` rows starting with the given `row` under parent `parent` from the model.
`protected void` | `reset()` Resets the model to its original state in any attached views.
`void` | `revert()` Called to let the model know that it should discard whatever it has cached.
`int` | `rowCount()` Returns the number of rows under the given `parent`.
`abstract int` | `rowCount(QModelIndex parent)` Returns the number of rows under the given `parent`.
`boolean` | `setData(int row, int col, java.lang.Object value)` Sets the data for the item at `row` and `col` to `value`.
`boolean` | `setData(int row, int col, java.lang.Object value, int role)` Sets the models data at `row` and `col` to `value`.
`boolean` | `setData(QModelIndex index, java.lang.Object value)` Sets the `role` data for the item at `index` to `value`.
`boolean` | `setData(QModelIndex index, java.lang.Object value, int role)` Sets the `role` data for the item at `index` to `value`.
`boolean` | `setHeaderData(int section, Qt.Orientation orientation, java.lang.Object value)` Sets the data for the given `role` and `section` in the header with the specified `orientation` to the `value` supplied.
`boolean` | `setHeaderData(int section, Qt.Orientation orientation, java.lang.Object value, int role)` Sets the data for the given `role` and `section` in the header with the specified `orientation` to the `value` supplied.
`boolean` | `setItemData(QModelIndex index, java.util.SortedMap roles)` This is an overloaded function provided for convenience.
`void` | `setSupportedDragActions(Qt.DropAction[] arg__1)` Sets the supported drag `actions` for the items in the model.
`void` | `setSupportedDragActions(Qt.DropActions arg__1)` Sets the supported drag `actions` for the items in the model.
`QModelIndex` | `sibling(int row, int column, QModelIndex idx)` Returns the sibling at `row` and `column` for the item at `index`, or an invalid QModelIndex if there is no sibling at that location.
`void` | `sort(int column)` Sorts the model by `column` in the given `order`.
`void` | `sort(int column, Qt.SortOrder order)` Sorts the model by `column` in the given `order`.
`QSize` | `span(QModelIndex index)` Returns the row and column span of the item represented by `index`.
`boolean` | `submit()` Called to let the model know that it should submit whatever it has cached to the permanent storage.
`Qt.DropActions` | `supportedDragActions()` Returns the actions supported by the data in this model.
`Qt.DropActions` | `supportedDropActions()` Returns the drop actions supported by this model.

Methods inherited from class com.trolltech.qt.core.QObject
`childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty`

Methods inherited from class com.trolltech.qt.QtJambiObject
`dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr`

Methods inherited from class com.trolltech.qt.QSignalEmitter
`blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread`

Methods inherited from class java.lang.Object
`clone, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface com.trolltech.qt.QtJambiInterface
`disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership`

Field Detail

### dataChanged

    public final QSignalEmitter.Signal2 dataChanged

  This signal is emitted whenever the data in an existing item changes. The affected items are those between `topLeft` and `bottomRight` inclusive (of the same parent).

  Note that this signal must be emitted explicitly when reimplementing the `setData()` function.

See also:
  `headerDataChanged()` , `setData()`, and `layoutChanged()` .

### headerDataChanged

    public final QSignalEmitter.Signal3 headerDataChanged

  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.

  Note that this signal must be emitted explicitly when reimplementing the `setHeaderData()` function.

  If you are changing the number of columns or rows you don't need to emit this signal, but use the begin/end functions.

See also:
  `headerData()`, `setHeaderData()`, and `dataChanged()` .

### layoutAboutToBeChanged

    public final QSignalEmitter.Signal0 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()` .

See also:
  `layoutChanged()` , and `changePersistentIndex()`.

### layoutChanged

    public final QSignalEmitter.Signal0 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.

  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.

  Subclasses should update any persistent model indexes before emitting `layoutChanged()` .

See also:
  `layoutAboutToBeChanged()` , `dataChanged()` , `headerDataChanged()` , `reset()`, and `changePersistentIndex()`.

Constructor Detail

### QAbstractItemModel

    public QAbstractItemModel()

  Constructs an abstract item model with the given `parent`.

### QAbstractItemModel

    public QAbstractItemModel(QObject parent)

  Constructs an abstract item model with the given `parent`.

Method Detail

### beginInsertColumns

    protected final void beginInsertColumns(QModelIndex parent,
                                            int first,
                                            int last)

  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.

  | 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:
              itemModel.beginInsertColumns(null, 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:
              itemModel.beginInsertColumns(null, 6, 8);
  This appends the two new columns as columns 6, 7, and 8.

See also:
  `endInsertColumns()`.

### beginInsertRows

    protected final void beginInsertRows(QModelIndex parent,
                                         int first,
                                         int last)

  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.

  | 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:
              itemModel.beginInsertRows(null, 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:
              itemModel.beginInsertRows(null, 4, 5);
  This appends the two new rows as rows 4 and 5.

See also:
  `endInsertRows()`.

### beginRemoveColumns

    protected final void beginRemoveColumns(QModelIndex parent,
                                            int first,
                                            int last)

  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.

  | 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:
              itemModel.beginRemoveColumns(null, 4, 6);

See also:
  `endRemoveColumns()`.

### beginRemoveRows

    protected final void beginRemoveRows(QModelIndex parent,
                                         int first,
                                         int last)

  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.

  | 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:
              itemModel.beginRemoveRows(null, 2, 3);

See also:
  `endRemoveRows()`.

### changePersistentIndex

    protected final void changePersistentIndex(QModelIndex from,
                                               QModelIndex to)

  Changes the `QPersistentModelIndex` that is equal to the given `from` model index to the given `to` model index.

  If no persistent model index equal to the given `from` model index was found, nothing is changed.

See also:
  `persistentIndexList()`, and `changePersistentIndexList()`.

### changePersistentIndexList

    protected final void changePersistentIndexList(java.util.List from,
                                                   java.util.List to)

  Changes the `QPersistentModelIndexes` that is 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 was found, nothing is changed.

See also:
  `persistentIndexList()`, and `changePersistentIndex()`.

### createIndex

    protected final QModelIndex createIndex(int row,
                                            int column,
                                            int id)

  Use QModelIndexQAbstractItemModel.:createIndex(int row, int column, quint32 id) instead.

### createIndex

    protected final QModelIndex createIndex(int row,
                                            int column)

  Creates a model index for the given `row` and `column` with the internal pointer `ptr`.

  Note that when you are using a `QSortFilterProxyModel` its indexes have their own internal pointer. It is not advisable to access the internal pointer in the index outside of the model. Use the `data()` function instead.

  This function provides a consistent interface that model subclasses must use to create model indexes.

### createIndex

    protected final QModelIndex createIndex(int row,
                                            int column,
                                            QNativePointer data)

  Creates a model index for the given `row` and `column` with the internal pointer `ptr`.

  Note that when you are using a `QSortFilterProxyModel` its indexes have their own internal pointer. It is not advisable to access the internal pointer in the index outside of the model. Use the `data()` function instead.

  This function provides a consistent interface that model subclasses must use to create model indexes.

### endInsertColumns

    protected final void endInsertColumns()

  Ends a column insertion operation.

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

See also:
  `beginInsertColumns()`.

### endInsertRows

    protected final void endInsertRows()

  Ends a row insertion operation.

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

See also:
  `beginInsertRows()`.

### endRemoveColumns

    protected final void endRemoveColumns()

  Ends a column removal operation.

  When reimplementing `removeColumns()` in a subclass, you must call this function after removing data from the model's underlying data store.

See also:
  `beginRemoveColumns()`.

### endRemoveRows

    protected final void endRemoveRows()

  Ends a row removal operation.

  When reimplementing `removeRows()` in a subclass, you must call this function after removing data from the model's underlying data store.

See also:
  `beginRemoveRows()`.

### hasIndex

    public final boolean hasIndex(int row,
                                  int column)

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

### hasIndex

    public final boolean hasIndex(int row,
                                  int column,
                                  QModelIndex parent)

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

### insertColumn

    public final boolean insertColumn(int column)

  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.

See also:
  `insertColumns()`, `insertRow()`, and `removeColumn()`.

### insertColumn

    public final boolean insertColumn(int column,
                                      QModelIndex parent)

  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.

See also:
  `insertColumns()`, `insertRow()`, and `removeColumn()`.

### insertRow

    public final boolean insertRow(int row)

  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.

See also:
  `insertRows()`, `insertColumn()`, and `removeRow()`.

### insertRow

    public final boolean insertRow(int row,
                                   QModelIndex parent)

  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.

See also:
  `insertRows()`, `insertColumn()`, and `removeRow()`.

### persistentIndexList

    protected final java.util.List persistentIndexList()

  Returns the list of indexes stored as persistent indexes in the model.

### removeColumn

    public final boolean removeColumn(int column)

  Removes the given `column` from the child items of the `parent` specified. Returns true if the column is removed; otherwise returns false.

See also:
  `removeColumns()`, `removeRow()`, and `insertColumn()`.

### removeColumn

    public final boolean removeColumn(int column,
                                      QModelIndex parent)

  Removes the given `column` from the child items of the `parent` specified. Returns true if the column is removed; otherwise returns false.

See also:
  `removeColumns()`, `removeRow()`, and `insertColumn()`.

### removeRow

    public final boolean removeRow(int row)

  Removes the given `row` from the child items of the `parent` specified. Returns true if the row is removed; otherwise returns false.

  The `removeRow()` is a convenience function that calls `removeRows()`. The `QAbstractItemModel` implementation of `removeRows` does nothing.

See also:
  `removeRows()`, `removeColumn()`, and `insertRow()`.

### removeRow

    public final boolean removeRow(int row,
                                   QModelIndex parent)

  Removes the given `row` from the child items of the `parent` specified. Returns true if the row is removed; otherwise returns false.

  The `removeRow()` is a convenience function that calls `removeRows()`. The `QAbstractItemModel` implementation of `removeRows` does nothing.

See also:
  `removeRows()`, `removeColumn()`, and `insertRow()`.

### reset

    protected final void reset()

  Resets the model to its original 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.

  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.

See also:
  modelAboutToBeReset(), and modelReset().

### setSupportedDragActions

    public final void setSupportedDragActions(Qt.DropAction[] arg__1)

  Sets the supported drag `actions` for the items in the model.

See also:
  `supportedDragActions()`, and Using Drag and Drop with Item Views.

### setSupportedDragActions

    public final void setSupportedDragActions(Qt.DropActions arg__1)

  Sets the supported drag `actions` for the items in the model.

See also:
  `supportedDragActions()`, and Using Drag and Drop with Item Views.

### sibling

    public final QModelIndex sibling(int row,
                                     int column,
                                     QModelIndex idx)

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

See also:
  `index()`, QModelIndex::row(), and QModelIndex::column().

### supportedDragActions

    public final Qt.DropActions supportedDragActions()

  Returns the actions supported by the data in this model.

  The default implementation returns `supportedDropActions()` unless specific values have been set with `setSupportedDragActions()`.

  `supportedDragActions()` is used by `QAbstractItemView::startDrag()` as the default values when a drag occurs.

See also:
  `setSupportedDragActions()`, Qt::DropActions, and Using Drag and Drop with Item Views.

### buddy

    public QModelIndex buddy(QModelIndex index)

  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, and construct a delegate using the model index returned by the buddy item.

  In the default implementation each item is its own buddy.

### canFetchMore

    public boolean canFetchMore(QModelIndex parent)

  Returns true if there is more data available for `parent`, otherwise false.

  The default implementation always returns false.

See also:
  `fetchMore()`.

### columnCount

    public final int columnCount()

  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:
  The following code example is written in c++.

      int DomModel::columnCount(const QModelIndex &parent) const
      {
          return 3;
      }

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

See also:
  `rowCount()`.

### columnCount

    public abstract int columnCount(QModelIndex parent)

  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:
  The following code example is written in c++.

      int DomModel::columnCount(const QModelIndex &parent) const
      {
          return 3;
      }

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

See also:
  `rowCount()`.

### data

    public final java.lang.Object data(QModelIndex index)

  Returns the data stored under the given `role` for the item referred to by the `index`.

  Note: If you do not have a value to return, return an emptyQVariant() instead of returning 0.

See also:
  `Qt::ItemDataRole` , `setData()`, and `headerData()`.

### data

    public abstract java.lang.Object data(QModelIndex index,
                                          int role)

  Returns the data stored under the given `role` for the item referred to by the `index`.

  Note: If you do not have a value to return, return an emptyQVariant() instead of returning 0.

See also:
  `Qt::ItemDataRole` , `setData()`, and `headerData()`.

### dropMimeData

    public boolean dropMimeData(QMimeData data,
                                Qt.DropAction action,
                                int row,
                                int column,
                                QModelIndex parent)

  Handles the `data` supplied by a drag and drop operation that ended with the given `action`. Returns true if the data and action can be handled by the model; otherwise returns false.

  Although 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 view to provide a suitable location for where the data should be inserted.

  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 it is up to the model to decide where to place the data. This can occur in a tree when data is dropped on a parent. Models will usually append the data to the parent in this case.

  Returns true if the dropping was successful otherwise false.

See also:
  `supportedDropActions()`, and Using Drag and Drop with Item Views.

### fetchMore

    public void fetchMore(QModelIndex parent)

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

  Reimplement this if you have incremental data.

  The default implementation does nothing.

See also:
  `canFetchMore()`.

### flags

    public Qt.ItemFlags flags(QModelIndex index)

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

See also:
  Qt::ItemFlags.

### hasChildren

    public final boolean hasChildren()

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

See also:
  `parent()`, and `index()`.

### hasChildren

    public boolean hasChildren(QModelIndex parent)

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

See also:
  `parent()`, and `index()`.

### headerData

    public final java.lang.Object headerData(int section,
                                             Qt.Orientation orientation)

  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 of items shown beneath it. For vertical headers, the section number typically to the row number of items shown alongside it.

See also:
  `Qt::ItemDataRole` , `setHeaderData()`, and `QHeaderView`.

### headerData

    public java.lang.Object headerData(int section,
                                       Qt.Orientation orientation,
                                       int role)

  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 of items shown beneath it. For vertical headers, the section number typically to the row number of items shown alongside it.

See also:
  `Qt::ItemDataRole` , `setHeaderData()`, and `QHeaderView`.

### index

    public final QModelIndex index(int row,
                                   int column)

  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.

See also:
  `createIndex()`.

### index

    public abstract QModelIndex index(int row,
                                      int column,
                                      QModelIndex parent)

  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.

See also:
  `createIndex()`.

### insertColumns

    public final boolean insertColumns(int column,
                                       int count)

  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 you own API for altering the data.

See also:
  `insertRows()`, `removeColumns()`, `beginInsertColumns()`, and `endInsertColumns()`.

### insertColumns

    public boolean insertColumns(int column,
                                 int count,
                                 QModelIndex parent)

  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 you own API for altering the data.

See also:
  `insertRows()`, `removeColumns()`, `beginInsertColumns()`, and `endInsertColumns()`.

### insertRows

    public final boolean insertRows(int row,
                                    int count)

  On models that support this, inserts `count` rows into the model before the given `row`. The 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.

  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 you own API for altering the data.

See also:
  `insertColumns()`, `removeRows()`, `beginInsertRows()`, and `endInsertRows()`.

### insertRows

    public boolean insertRows(int row,
                              int count,
                              QModelIndex parent)

  On models that support this, inserts `count` rows into the model before the given `row`. The 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.

  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 you own API for altering the data.

See also:
  `insertColumns()`, `removeRows()`, `beginInsertRows()`, and `endInsertRows()`.

### itemData

    public java.util.SortedMap itemData(QModelIndex index)

  Returns a map with values for all predefined roles in the model for the item at the given `index`.

  Reimplemented this function if you want to extend the default behavior of this function to include custom roles in the map.

See also:
  `setItemData()`, `Qt::ItemDataRole` , and `data()`.

### match

    public final java.util.List match(QModelIndex start,
                                      int role,
                                      java.lang.Object value,
                                      int hits,
                                      Qt.MatchFlag[] flags)

  Returns a list of indexes for the items in the column of the `start` index where the 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 starts 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`.

  Note: The default implementation of this function only searches columns, This function can be reimplemented to include other search behavior.

### match

    public final java.util.List match(QModelIndex start,
                                      int role,
                                      java.lang.Object value,
                                      int hits)

  This is an overloaded function provided for convenience.

### match

    public final java.util.List match(QModelIndex start,
                                      int role,
                                      java.lang.Object value)

  This is an overloaded function provided for convenience.

### match

    public java.util.List match(QModelIndex start,
                                int role,
                                java.lang.Object value,
                                int hits,
                                Qt.MatchFlags flags)

  Returns a list of indexes for the items in the column of the `start` index where the 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 starts 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`.

  Note: The default implementation of this function only searches columns, This function can be reimplemented to include other search behavior.

### mimeData

    public QMimeData mimeData(java.util.List indexes)

  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()` function.

  If the list of indexes is empty, or there are no supported MIME types, 0 is returned rather than a serialized empty list.

See also:
  `mimeTypes()`, and `dropMimeData()`.

### mimeTypes

    public java.util.List mimeTypes()

  Returns a list of MIME types that can be used to describe a list of model indexes.

See also:
  `mimeData()`.

### parent

    public abstract QModelIndex parent(QModelIndex child)

  Returns the parent of the model item with the given `index`, or QModelIndex() if it has no parent.

  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.

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

See also:
  `createIndex()`.

### removeColumns

    public final boolean removeColumns(int column,
                                       int count)

  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 you own API for altering the data.

See also:
  `removeColumn()`, `removeRows()`, `insertColumns()`, `beginRemoveColumns()`, and `endRemoveColumns()`.

### removeColumns

    public boolean removeColumns(int column,
                                 int count,
                                 QModelIndex parent)

  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 you own API for altering the data.

See also:
  `removeColumn()`, `removeRows()`, `insertColumns()`, `beginRemoveColumns()`, and `endRemoveColumns()`.

### removeRows

    public final boolean removeRows(int row,
                                    int count)

  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 you own API for altering the data.

See also:
  `removeRow()`, `removeColumns()`, `insertColumns()`, `beginRemoveRows()`, and `endRemoveRows()`.

### removeRows

    public boolean removeRows(int row,
                              int count,
                              QModelIndex parent)

  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 you own API for altering the data.

See also:
  `removeRow()`, `removeColumns()`, `insertColumns()`, `beginRemoveRows()`, and `endRemoveRows()`.

### revert

    public void revert()

  Called to let the model know that it should discard whatever it has cached. Typically used for row editing.

### rowCount

    public final int rowCount()

  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.

  Tip: When implementing a table based model, `rowCount()` should return 0 when the parent is valid.

See also:
  `columnCount()`.

### rowCount

    public abstract int rowCount(QModelIndex parent)

  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.

  Tip: When implementing a table based model, `rowCount()` should return 0 when the parent is valid.

See also:
  `columnCount()`.

### setData

    public final boolean setData(QModelIndex index,
                                 java.lang.Object value)

  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. Note that the `dataChanged()` signal must be emitted explicitly when reimplementing this function.

See also:
  `Qt::ItemDataRole` , `data()`, and `itemData()`.

### setData

    public boolean setData(QModelIndex index,
                           java.lang.Object value,
                           int role)

  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. Note that the `dataChanged()` signal must be emitted explicitly when reimplementing this function.

See also:
  `Qt::ItemDataRole` , `data()`, and `itemData()`.

### setHeaderData

    public final boolean setHeaderData(int section,
                                       Qt.Orientation orientation,
                                       java.lang.Object value)

  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.

  Note that the `headerDataChanged()` signal must be emitted explicitly when reimplementing this function.

See also:
  `Qt::ItemDataRole` , and `headerData()`.

### setHeaderData

    public boolean setHeaderData(int section,
                                 Qt.Orientation orientation,
                                 java.lang.Object value,
                                 int role)

  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.

  Note that the `headerDataChanged()` signal must be emitted explicitly when reimplementing this function.

See also:
  `Qt::ItemDataRole` , and `headerData()`.

### setItemData

    public boolean setItemData(QModelIndex index,
                               java.util.SortedMap roles)

  This is an overloaded function provided for convenience.

### sort

    public final void sort(int column)

  Sorts the model by `column` in the given `order`.

  The base class implementation does nothing.

### sort

    public void sort(int column,
                     Qt.SortOrder order)

  Sorts the model by `column` in the given `order`.

  The base class implementation does nothing.

### span

    public QSize span(QModelIndex index)

  Returns the row and column span of the item represented by `index`.

  Note: span is not used currently, but will be in the future.

### submit

    public boolean submit()

  Called to let the model know that it should submit whatever it has cached to the permanent storage. Typically used for row editing.

  Returns false on error, otherwise true.

### supportedDropActions

    public Qt.DropActions supportedDropActions()

  Returns the drop actions supported by this model.

  The default implementation returns `Qt::CopyAction` . Reimplement this function if you wish to support additional actions. Note that you must also reimplement the `dropMimeData()` function to handle the additional operations.

See also:
  `dropMimeData()`, Qt::DropActions, and Using Drag and Drop with Item Views.

### fromNativePointer

    public static QAbstractItemModel fromNativePointer(QNativePointer nativePointer)

  This method returns the QAbstractItemModel instance pointed to by `nativePointer`.

### setData

    public final boolean setData(int row,
                                 int col,
                                 java.lang.Object value)

  Sets the data for the item at `row` and `col` 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. Note that the dataChanged() signal must be emitted explicitly when reimplementing this function.

### setData

    public final boolean setData(int row,
                                 int col,
                                 java.lang.Object value,
                                 int role)

  Sets the models data at `row` and `col` to `value`. The data is stored in the `role` role.

  Returns true if successful; otherwise, returns false.

### data

    public final java.lang.Object data(int row,
                                       int col,
                                       int role)

  Returns the data with the specified `role` at row `row` and column `col`

### data

    public final java.lang.Object data(int row,
                                       int col)

  Returns the data in the display role at row `row` and column `col`.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD