CopperSpice API  1.7.2
QAbstractProxyModel Class Referenceabstract

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

Inheritance diagram for QAbstractProxyModel:
QAbstractItemModel QObject QIdentityProxyModel QSortFilterProxyModel

Public Signals

void sourceModelChanged ()
 
- Public Signals inherited from QAbstractItemModel
void columnsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void columnsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 
void columnsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void columnsInserted (const QModelIndex &parent, int first, int last)
 
void columnsMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn)
 
void columnsRemoved (const QModelIndex &parent, int first, int last)
 
void dataChanged (const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector< int > &roles=QVector< int >())
 
void headerDataChanged (Qt::Orientation orientation, int first, int last)
 
void layoutAboutToBeChanged (const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
 
void layoutChanged (const QList< QPersistentModelIndex > &parents=QList< QPersistentModelIndex >(), QAbstractItemModel::LayoutChangeHint hint=QAbstractItemModel::NoLayoutChangeHint)
 
void modelAboutToBeReset ()
 
void modelReset ()
 
void rowsAboutToBeInserted (const QModelIndex &parent, int first, int last)
 
void rowsAboutToBeMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int first, int last)
 
void rowsInserted (const QModelIndex &parent, int first, int last)
 
void rowsMoved (const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow)
 
void rowsRemoved (const QModelIndex &parent, int first, int last)
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Methods

 QAbstractProxyModel (QObject *parent=nullptr)
 
 ~QAbstractProxyModel () = default
 
QModelIndex buddy (const QModelIndex &index) const override
 
bool canDropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override
 
bool canFetchMore (const QModelIndex &parent) const override
 
QVariant data (const QModelIndex &proxyIndex, int role=Qt::DisplayRole) const override
 
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
 
void fetchMore (const QModelIndex &parent) override
 
Qt::ItemFlags flags (const QModelIndex &index) const override
 
bool hasChildren (const QModelIndex &parent=QModelIndex ()) const override
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const override
 
QMap< int, QVariantitemData (const QModelIndex &proxyIndex) const override
 
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
 
QMimeDatamimeData (const QModelIndexList &indexes) const override
 
QStringList mimeTypes () const override
 
void revert () override
 
bool setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
 
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) override
 
bool setItemData (const QModelIndex &index, const QMap< int, QVariant > &roles) override
 
virtual void setSourceModel (QAbstractItemModel *sourceModel)
 
QModelIndex sibling (int row, int column, const QModelIndex &idx) const override
 
void sort (int column, Qt::SortOrder order=Qt::AscendingOrder) override
 
QAbstractItemModelsourceModel () const
 
QSize span (const QModelIndex &index) const override
 
bool submit () override
 
Qt::DropActions supportedDragActions () const override
 
Qt::DropActions supportedDropActions () const override
 
- Public Methods inherited from QAbstractItemModel
 QAbstractItemModel (QObject *parent=nullptr)
 
virtual ~QAbstractItemModel ()
 
virtual int columnCount (const QModelIndex &parent=QModelIndex ()) const = 0
 
bool hasIndex (int row, int column, const QModelIndex &parent=QModelIndex ()) const
 
virtual QModelIndex index (int row, int column, const QModelIndex &parent=QModelIndex ()) const = 0
 
bool insertColumn (int column, const QModelIndex &parent=QModelIndex ())
 
virtual bool insertColumns (int column, int count, const QModelIndex &parent=QModelIndex ())
 
bool insertRow (int row, const QModelIndex &parent=QModelIndex ())
 
virtual bool insertRows (int row, int count, const QModelIndex &parent=QModelIndex ())
 
virtual QModelIndexList match (const QModelIndex &start, int role, const QVariant &value, int hits=1, Qt::MatchFlags flags=Qt::MatchFlags (Qt::MatchStartsWith|Qt::MatchWrap)) const
 
bool moveColumn (const QModelIndex &sourceParent, int sourceColumn, const QModelIndex &destinationParent, int destinationChild)
 
virtual bool moveColumns (const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild)
 
bool moveRow (const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild)
 
virtual bool moveRows (const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
 
QObjectparent () const
 
virtual QModelIndex parent (const QModelIndex &index) const = 0
 
bool removeColumn (int column, const QModelIndex &parent=QModelIndex ())
 
virtual bool removeColumns (int column, int count, const QModelIndex &parent=QModelIndex ())
 
bool removeRow (int row, const QModelIndex &parent=QModelIndex ())
 
virtual bool removeRows (int row, int count, const QModelIndex &parent=QModelIndex ())
 
virtual QMultiHash< int, QStringroleNames () const
 
virtual int rowCount (const QModelIndex &parent=QModelIndex ()) const = 0
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &objName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Protected Slots

void resetInternalData ()
 
- Protected Slots inherited from QAbstractItemModel
void resetInternalData ()
 

Properties

 sourceModel
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

- Public Slots inherited from QAbstractItemModel
virtual void revert ()
 
virtual bool submit ()
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Methods inherited from QAbstractItemModel
void beginInsertColumns (const QModelIndex &parent, int first, int last)
 
void beginInsertRows (const QModelIndex &parent, int first, int last)
 
bool beginMoveColumns (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationColumn)
 
bool beginMoveRows (const QModelIndex &sourceParent, int sourceFirst, int sourceLast, const QModelIndex &destinationParent, int destinationRow)
 
void beginRemoveColumns (const QModelIndex &parent, int first, int last)
 
void beginRemoveRows (const QModelIndex &parent, int first, int last)
 
void beginResetModel ()
 
void changePersistentIndex (const QModelIndex &from, const QModelIndex &to)
 
void changePersistentIndexList (const QModelIndexList &from, const QModelIndexList &to)
 
QModelIndex createIndex (int row, int column, quintptr id) const
 
QModelIndex createIndex (int row, int column, void *data=nullptr) const
 
void endInsertColumns ()
 
void endInsertRows ()
 
void endMoveColumns ()
 
void endMoveRows ()
 
void endRemoveColumns ()
 
void endRemoveRows ()
 
void endResetModel ()
 
QModelIndexList persistentIndexList () const
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

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.

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

See also
QSortFilterProxyModel, QAbstractItemModel, Model/View Programming

Constructor & Destructor Documentation

QAbstractProxyModel::QAbstractProxyModel ( QObject parent = nullptr)
explicit

Constructs a proxy model with the given parent.

QAbstractProxyModel::~QAbstractProxyModel ( )
default

Destroys the proxy model.

Method Documentation

QModelIndex QAbstractProxyModel::buddy ( const QModelIndex index) const
overridevirtual

Reimplemented from QAbstractItemModel::buddy().

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

bool QAbstractProxyModel::canDropMimeData ( const QMimeData data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex parent 
) const
overridevirtual

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 do not need that test, it is not necessary to reimplement this function.

See also
dropMimeData(), model-view-using-dnd

Reimplemented from QAbstractItemModel.

bool QAbstractProxyModel::canFetchMore ( const QModelIndex parent) const
overridevirtual

Reimplemented from QAbstractItemModel::canFetchMore().

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

QVariant QAbstractProxyModel::data ( const QModelIndex proxyIndex,
int  role = Qt::DisplayRole 
) const
overridevirtual

Reimplemented from QAbstractItemModel::data().

See also
setData()

Implements QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

bool QAbstractProxyModel::dropMimeData ( const QMimeData data,
Qt::DropAction  action,
int  row,
int  column,
const QModelIndex parent 
)
overridevirtual

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.

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.

See also
supportedDropActions(), model-view-using-dnd

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel, and QIdentityProxyModel.

void QAbstractProxyModel::fetchMore ( const QModelIndex parent)
overridevirtual

Reimplemented from QAbstractItemModel::fetchMore().

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

Qt::ItemFlags QAbstractProxyModel::flags ( const QModelIndex index) const
overridevirtual

Reimplemented from QAbstractItemModel::flags().

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

bool QAbstractProxyModel::hasChildren ( const QModelIndex parent = QModelIndex()) const
overridevirtual

Reimplemented from QAbstractItemModel::hasChildren().

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

QVariant QAbstractProxyModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const
overridevirtual

Reimplemented from QAbstractItemModel::headerData().

See also
setHeaderData()

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel, and QIdentityProxyModel.

QMap< int, QVariant > QAbstractProxyModel::itemData ( const QModelIndex proxyIndex) const
overridevirtual

Reimplemented from QAbstractItemModel::itemData().

See also
setItemData()

Reimplemented from QAbstractItemModel.

QModelIndex QAbstractProxyModel::mapFromSource ( const QModelIndex sourceIndex) const
pure virtual

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

See also
mapToSource()

Implemented in QSortFilterProxyModel, and QIdentityProxyModel.

QItemSelection QAbstractProxyModel::mapSelectionFromSource ( const QItemSelection sourceSelection) const
virtual

Returns a proxy selection mapped from the specified sourceSelection. Reimplement this method to map source selections to proxy selections.

Reimplemented in QSortFilterProxyModel, and QIdentityProxyModel.

QItemSelection QAbstractProxyModel::mapSelectionToSource ( const QItemSelection proxySelection) const
virtual

Returns a source selection mapped from the specified proxySelection. Reimplement this method to map proxy selections to source selections.

Reimplemented in QIdentityProxyModel, and QSortFilterProxyModel.

QModelIndex QAbstractProxyModel::mapToSource ( const QModelIndex proxyIndex) const
pure virtual

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

See also
mapFromSource()

Implemented in QSortFilterProxyModel, and QIdentityProxyModel.

QMimeData * QAbstractProxyModel::mimeData ( const QModelIndexList indexes) const
overridevirtual

Reimplemented from QAbstractItemModel::mimeData().

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

QStringList QAbstractProxyModel::mimeTypes ( ) const
overridevirtual

Reimplemented from QAbstractItemModel::mimeTypes().

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

void QAbstractProxyModel::resetInternalData ( )
protectedslot

Clears the roleNames of this proxy model.

void QAbstractProxyModel::revert ( )
override

Reimplemented from QAbstractItemModel::revert().

bool QAbstractProxyModel::setData ( const QModelIndex index,
const QVariant value,
int  role = Qt::EditRole 
)
overridevirtual

Reimplemented from QAbstractItemModel::setData().

See also
data()

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

bool QAbstractProxyModel::setHeaderData ( int  section,
Qt::Orientation  orientation,
const QVariant value,
int  role = Qt::EditRole 
)
overridevirtual

Reimplemented from QAbstractItemModel::setHeaderData().

See also
headerData()

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

bool QAbstractProxyModel::setItemData ( const QModelIndex index,
const QMap< int, QVariant > &  roles 
)
overridevirtual

Reimplemented from QAbstractItemModel::setItemData().

See also
itemData()

Reimplemented from QAbstractItemModel.

void QAbstractProxyModel::setSourceModel ( QAbstractItemModel sourceModel)
virtual

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

See also
sourceModel()

Reimplemented in QSortFilterProxyModel, and QIdentityProxyModel.

QModelIndex QAbstractProxyModel::sibling ( int  row,
int  column,
const QModelIndex index 
) const
overridevirtual

Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location. The 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(), QModelIndex::column()

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel, and QIdentityProxyModel.

void QAbstractProxyModel::sort ( int  column,
Qt::SortOrder  order = Qt::AscendingOrder 
)
overridevirtual

Reimplemented from QAbstractItemModel::sort().

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

QAbstractItemModel * QAbstractProxyModel::sourceModel ( ) const

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

See also
setSourceModel()
void QAbstractProxyModel::sourceModelChanged ( )
signal

This signal is emitted when the source model property changes.

QSize QAbstractProxyModel::span ( const QModelIndex index) const
overridevirtual

Reimplemented from QAbstractItemModel::span().

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

bool QAbstractProxyModel::submit ( )
override

Reimplemented from QAbstractItemModel::submit().

Qt::DropActions QAbstractProxyModel::supportedDragActions ( ) const
overridevirtual

Returns the actions supported by the data in this model. The default implementation returns supportedDropActions() unless specific values have been set with setSupportedDragActions().

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

See also
setSupportedDragActions(), Qt::DropActions, model-view-using-dnd

Reimplemented from QAbstractItemModel.

Qt::DropActions QAbstractProxyModel::supportedDropActions ( ) const
overridevirtual

Reimplemented from QAbstractItemModel::supportedDropActions().

Reimplemented from QAbstractItemModel.

Reimplemented in QSortFilterProxyModel.

Property Documentation

QAbstractProxyModel::sourceModel

This property holds the source model of this proxy model.

PropertiesClass Methods
read sourceModel
write setSourceModel
notify sourceModelChanged