QAbstractProxyModel Class | Qt Core 5.6

Qt 5.6 | Qt Core | C++ Classes | QAbstractProxyModel

Qt 5.6.2 Reference Documentation

# QAbstractProxyModel Class

The QAbstractProxyModel class provides a base class for proxy item models that can do sorting, filtering or other data processing tasks. More...

Header: | #include <QAbstractProxyModel>
qmake: | QT += core
Since: | Qt 4.1
Inherits: | QAbstractItemModel
Inherited By: | QIdentityProxyModel and QSortFilterProxyModel

- List of all members, including inherited members

## Properties

- sourceModel : QAbstractItemModel *

- 1 property inherited from QObject

## Public Functions

| QAbstractProxyModel(QObject *parent = Q_NULLPTR)
| ~QAbstractProxyModel()
virtual QModelIndex | mapFromSource(const QModelIndex &sourceIndex) const = 0
virtual QItemSelection | mapSelectionFromSource(const QItemSelection &sourceSelection) const
virtual QItemSelection | mapSelectionToSource(const QItemSelection &proxySelection) const
virtual QModelIndex | mapToSource(const QModelIndex &proxyIndex) const = 0
virtual void | setSourceModel(QAbstractItemModel *sourceModel)
QAbstractItemModel * | sourceModel() const

## Reimplemented Public Functions

virtual QModelIndex | buddy(const QModelIndex &index) const
virtual bool | canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
virtual bool | canFetchMore(const QModelIndex &parent) const
virtual QVariant | data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const
virtual bool | dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
virtual void | fetchMore(const QModelIndex &parent)
virtual Qt::ItemFlags | flags(const QModelIndex &index) const
virtual bool | hasChildren(const QModelIndex &parent = QModelIndex()) const
virtual QVariant | headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
virtual QMap<int, QVariant> | itemData(const QModelIndex &proxyIndex) const
virtual QMimeData * | mimeData(const QModelIndexList &indexes) const
virtual QStringList | mimeTypes() const
virtual void | revert()
virtual bool | setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
virtual bool | setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole)
virtual bool | setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)
virtual QModelIndex | sibling(int row, int column, const QModelIndex &idx) const
virtual void | sort(int column, Qt::SortOrder order = Qt::AscendingOrder)
virtual QSize | span(const QModelIndex &index) const
virtual bool | submit()
virtual Qt::DropActions | supportedDragActions() const
virtual Qt::DropActions | supportedDropActions() const

- 39 public functions inherited from QAbstractItemModel
- 31 public functions inherited from QObject

## Signals

void | sourceModelChanged()

- 18 signals inherited from QAbstractItemModel
- 2 signals inherited from QObject

## Protected Slots

void | resetInternalData()

- 1 protected slot inherited from QAbstractItemModel

### Additional Inherited Members

- 2 public slots inherited from QAbstractItemModel
- 1 public slot inherited from QObject
- 11 static public members inherited from QObject
- 19 protected functions inherited from QAbstractItemModel
- 9 protected functions inherited from QObject

## Detailed Description

The QAbstractProxyModel class provides a base class for proxy item models that can do sorting, filtering or other data processing tasks.

This class defines the standard interface that proxy models must use to be able to interoperate correctly with other model/view components. It is not supposed to be instantiated directly.

All standard proxy models are derived from the QAbstractProxyModel class. If you need to create a new proxy model class, it is usually better to subclass an existing class that provides the closest behavior to the one you want to provide.

Proxy models that filter or sort items of data from a source model should be created by using or subclassing QSortFilterProxyModel.

To subclass QAbstractProxyModel, you need to implement mapFromSource() and mapToSource(). The mapSelectionFromSource() and mapSelectionToSource() functions only need to be reimplemented if you need a behavior different from the default behavior.

Note: If the source model is deleted or no source model is specified, the proxy model operates on a empty placeholder model.

See also QSortFilterProxyModel, QAbstractItemModel, and Model/View Programming.

## Property Documentation

### sourceModel : QAbstractItemModel *

This property holds the source model this proxy model.

Access functions:

QAbstractItemModel * | sourceModel() const
virtual void | setSourceModel(QAbstractItemModel *sourceModel)

Notifier signal:

void | sourceModelChanged() | [see note below]

Note: This is a private signal. It can be used in signal connections but cannot be emitted by the user.

## Member Function Documentation

### QAbstractProxyModel::QAbstractProxyModel(QObject *parent = Q_NULLPTR)

Constructs a proxy model with the given parent.

### QAbstractProxyModel::~QAbstractProxyModel()

Destroys the proxy model.

### `[virtual]` QModelIndex QAbstractProxyModel::buddy(const QModelIndex &index) const

Reimplemented from QAbstractItemModel::buddy().

### `[virtual]` bool QAbstractProxyModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const

Reimplemented from QAbstractItemModel::canDropMimeData().

This function was introduced in Qt 5.4.

### `[virtual]` bool QAbstractProxyModel::canFetchMore(const QModelIndex &parent) const

Reimplemented from QAbstractItemModel::canFetchMore().

### `[virtual]` QVariant QAbstractProxyModel::data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const

Reimplemented from QAbstractItemModel::data().

See also setData().

### `[virtual]` bool QAbstractProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)

Reimplemented from QAbstractItemModel::dropMimeData().

This function was introduced in Qt 5.4.

### `[virtual]` void QAbstractProxyModel::fetchMore(const QModelIndex &parent)

Reimplemented from QAbstractItemModel::fetchMore().

### `[virtual]` Qt::ItemFlags QAbstractProxyModel::flags(const QModelIndex &index) const

Reimplemented from QAbstractItemModel::flags().

### `[virtual]` bool QAbstractProxyModel::hasChildren(const QModelIndex &parent = QModelIndex()) const

Reimplemented from QAbstractItemModel::hasChildren().

### `[virtual]` QVariant QAbstractProxyModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const

Reimplemented from QAbstractItemModel::headerData().

See also setHeaderData().

### `[virtual]` QMap<int, QVariant> QAbstractProxyModel::itemData(const QModelIndex &proxyIndex) const

Reimplemented from QAbstractItemModel::itemData().

See also setItemData().

### `[pure virtual]` QModelIndex QAbstractProxyModel::mapFromSource(const QModelIndex &sourceIndex) const

Reimplement this function to return the model index in the proxy model that corresponds to the sourceIndex from the source model.

See also mapToSource().

### `[virtual]` QItemSelection QAbstractProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const

Returns a proxy selection mapped from the specified sourceSelection.

Reimplement this method to map source selections to proxy selections.

### `[virtual]` QItemSelection QAbstractProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const

Returns a source selection mapped from the specified proxySelection.

Reimplement this method to map proxy selections to source selections.

### `[pure virtual]` QModelIndex QAbstractProxyModel::mapToSource(const QModelIndex &proxyIndex) const

Reimplement this function to return the model index in the source model that corresponds to the proxyIndex in the proxy model.

See also mapFromSource().

### `[virtual]` QMimeData *QAbstractProxyModel::mimeData(const QModelIndexList &indexes) const

Reimplemented from QAbstractItemModel::mimeData().

### `[virtual]` QStringList QAbstractProxyModel::mimeTypes() const

Reimplemented from QAbstractItemModel::mimeTypes().

### `[protected slot]` void QAbstractProxyModel::resetInternalData()

Clears the roleNames of this proxy model.

### `[virtual]` void QAbstractProxyModel::revert()

Reimplemented from QAbstractItemModel::revert().

### `[virtual]` bool QAbstractProxyModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)

Reimplemented from QAbstractItemModel::setData().

See also data().

### `[virtual]` bool QAbstractProxyModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole)

Reimplemented from QAbstractItemModel::setHeaderData().

See also headerData().

### `[virtual]` bool QAbstractProxyModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)

Reimplemented from QAbstractItemModel::setItemData().

See also itemData().

### `[virtual]` void QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel)

Sets the given sourceModel to be processed by the proxy model.

Subclasses should call beginResetModel() at the beginning of the method, disconnect from the old model, call this method, connect to the new model, and call endResetModel().

Note: Setter function for property sourceModel.

See also sourceModel().

### `[virtual]` QModelIndex QAbstractProxyModel::sibling(int row, int column, const QModelIndex &idx) const

Reimplemented from QAbstractItemModel::sibling().

### `[virtual]` void QAbstractProxyModel::sort(int column, Qt::SortOrder order = Qt::AscendingOrder)

Reimplemented from QAbstractItemModel::sort().

### QAbstractItemModel *QAbstractProxyModel::sourceModel() const

Returns the model that contains the data that is available through the proxy model.

Note: Getter function for property sourceModel.

See also setSourceModel().

### `[virtual]` QSize QAbstractProxyModel::span(const QModelIndex &index) const

Reimplemented from QAbstractItemModel::span().

### `[virtual]` bool QAbstractProxyModel::submit()

Reimplemented from QAbstractItemModel::submit().

### `[virtual]` Qt::DropActions QAbstractProxyModel::supportedDragActions() const

Reimplemented from QAbstractItemModel::supportedDragActions().

### `[virtual]` Qt::DropActions QAbstractProxyModel::supportedDropActions() const

Reimplemented from QAbstractItemModel::supportedDropActions().