QAbstractProxyModel Class
Die Klasse „QAbstractProxyModel“ dient als Basisklasse für Proxy-Elementmodelle, die Sortier-, Filter- oder andere Datenverarbeitungsaufgaben ausführen können. Mehr...
| Header: | #include <QAbstractProxyModel> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| Erbt von: | QAbstractItemModel |
| Vererbt an: | QIdentityProxyModel, „ QSortFilterProxyModel “ sowie QTransposeProxyModel |
Eigenschaften
- sourceModel : QAbstractItemModel*
Öffentliche Funktionen
| QAbstractProxyModel(QObject *parent = nullptr) | |
| virtual | ~QAbstractProxyModel() |
| QBindable<QAbstractItemModel *> | bindableSourceModel() |
| 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 |
Neu implementierte öffentliche Funktionen
| virtual QModelIndex | buddy(const QModelIndex &index) const override |
| virtual bool | canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override |
| virtual bool | canFetchMore(const QModelIndex &parent) const override |
(since 6.0) virtual bool | clearItemData(const QModelIndex &index) override |
| virtual QVariant | data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const override |
| virtual bool | dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override |
| virtual void | fetchMore(const QModelIndex &parent) override |
| virtual Qt::ItemFlags | flags(const QModelIndex &index) const override |
| virtual bool | hasChildren(const QModelIndex &parent = QModelIndex()) const override |
| virtual QVariant | headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override |
| virtual QMap<int, QVariant> | itemData(const QModelIndex &proxyIndex) const override |
| virtual QMimeData * | mimeData(const QModelIndexList &indexes) const override |
| virtual QStringList | mimeTypes() const override |
| virtual void | revert() override |
| virtual QHash<int, QByteArray> | roleNames() const override |
| virtual bool | setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override |
| virtual bool | setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override |
| virtual bool | setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) override |
| virtual QModelIndex | sibling(int row, int column, const QModelIndex &idx) const override |
| virtual void | sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override |
| virtual QSize | span(const QModelIndex &index) const override |
| virtual bool | submit() override |
| virtual Qt::DropActions | supportedDragActions() const override |
| virtual Qt::DropActions | supportedDropActions() const override |
Signale
| void | sourceModelChanged() |
Geschützte Funktionen
(since 6.2) QModelIndex | createSourceIndex(int row, int col, void *internalPtr) const |
Detaillierte Beschreibung
Diese Klasse definiert die Standardschnittstelle, die Proxy-Modelle verwenden müssen, um korrekt mit anderen Modell-/Ansichtskomponenten zusammenarbeiten zu können. Sie ist nicht dafür vorgesehen, direkt instanziiert zu werden.
Alle Standard-Proxy-Modelle leiten sich von der Klasse `QAbstractProxyModel` ab. Wenn Sie eine neue Proxy-Modellklasse erstellen müssen, ist es in der Regel besser, eine Unterklasse einer bestehenden Klasse zu erstellen, deren Verhalten dem von Ihnen gewünschten am nächsten kommt.
Proxy-Modelle, die Datenelemente aus einem Quellmodell filtern oder sortieren, sollten unter Verwendung von ` QSortFilterProxyModel` erstellt oder davon abgeleitet werden.
Um eine Unterklasse von `QAbstractProxyModel` zu erstellen, müssen Sie die Methoden ` mapFromSource()` und ` mapToSource()` implementieren. Die Funktionen ` mapSelectionFromSource()` und ` mapSelectionToSource()` müssen nur neu implementiert werden, wenn Sie ein vom Standardverhalten abweichendes Verhalten benötigen.
Hinweis: Wenn das Quellmodell gelöscht wird oder kein Quellmodell angegeben ist, arbeitet das Proxy-Modell mit einem leeren Platzhaltermodell.
Siehe auch „ QSortFilterProxyModel “, „ QAbstractItemModel “ und „Model/View-Programmierung“.
Dokumentation zu Eigenschaften
[bindable] sourceModel : QAbstractItemModel*
Hinweis: Diese Eigenschaft unterstützt „ QProperty “-Bindungen.
Diese Eigenschaft enthält das Quellmodell dieses Proxy-Modells.
Zugriffsfunktionen:
| QAbstractItemModel * | sourceModel() const |
| virtual void | setSourceModel(QAbstractItemModel *sourceModel) |
Notifier-Signal:
| void | sourceModelChanged() | [see note below] |
Hinweis: Dies ist ein privates Signal. Es kann in Signalverbindungen verwendet werden, kann jedoch nicht vom Benutzer ausgelöst werden.
Dokumentation der Mitgliedsfunktionen
[explicit] QAbstractProxyModel::QAbstractProxyModel(QObject *parent = nullptr)
Erstellt ein Proxy-Modell mit dem angegebenen „ parent “.
[virtual noexcept] QAbstractProxyModel::~QAbstractProxyModel()
Zerstört das Proxy-Modell.
[override virtual] QModelIndex QAbstractProxyModel::buddy(const QModelIndex &index) const
Implementiert neu: ` QAbstractItemModel::buddy(const QModelIndex &index) const`.
[override virtual] bool QAbstractProxyModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
Implementiert: ` QAbstractItemModel::canDropMimeData` (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const.
[override virtual] bool QAbstractProxyModel::canFetchMore(const QModelIndex &parent) const
Implementiert: ` QAbstractItemModel::canFetchMore(const QModelIndex &parent) const`.
[override virtual, since 6.0] bool QAbstractProxyModel::clearItemData(const QModelIndex &index)
Implementiert: ` QAbstractItemModel::clearItemData(const QModelIndex &index)`.
Diese Funktion wurde in Qt 6.0 eingeführt.
[protected, since 6.2] QModelIndex QAbstractProxyModel::createSourceIndex(int row, int col, void *internalPtr) const
Entspricht dem Aufruf von `createIndex` für das Quellmodell.
Diese Methode ist nützlich, wenn Ihr Proxy-Modell die Eltern-Kind-Beziehung der Elemente im Quellmodell beibehalten möchte. Bei der Neuimplementierung von ` mapToSource()` können Sie diese Methode aufrufen, um einen Index für die Zeilen- row und die Spalten- col des Quellmodells zu erstellen.
Eine typische Anwendung wäre, den vom Quellmodell stammenden internen Zeiger bei der Neuimplementierung von ` mapFromSource()` im Proxy-Index zu speichern und denselben internen Zeiger als ` internalPtr ` zu verwenden, um den ursprünglichen Quellindex bei der Neuimplementierung von ` mapToSource()` wiederherzustellen.
Diese Funktion wurde in Qt 6.2 eingeführt.
[override virtual] QVariant QAbstractProxyModel::data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const
Implementiert neu: ` QAbstractItemModel::data(const QModelIndex &index, int role) const`.
Siehe auch setData().
[override virtual] bool QAbstractProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Implementiert: ` QAbstractItemModel::dropMimeData` (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent).
[override virtual] void QAbstractProxyModel::fetchMore(const QModelIndex &parent)
Implementiert: ` QAbstractItemModel::fetchMore(const QModelIndex &parent)`.
[override virtual] Qt::ItemFlags QAbstractProxyModel::flags(const QModelIndex &index) const
Implementiert neu: ` QAbstractItemModel::flags(const QModelIndex &index) const`.
[override virtual] bool QAbstractProxyModel::hasChildren(const QModelIndex &parent = QModelIndex()) const
Implementiert: ` QAbstractItemModel::hasChildren(const QModelIndex &parent) const`.
[override virtual] QVariant QAbstractProxyModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
Implementiert: ` QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role) const`.
Siehe auch ` setHeaderData()`.
[override virtual] QMap<int, QVariant> QAbstractProxyModel::itemData(const QModelIndex &proxyIndex) const
Implementiert neu: ` QAbstractItemModel::itemData(const QModelIndex &index) const`.
Siehe auch setItemData().
[pure virtual invokable] QModelIndex QAbstractProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
Implementieren Sie diese Funktion neu, um den Modellindex im Proxy-Modell zurückzugeben, der dem „ sourceIndex “ aus dem Quellmodell entspricht.
Hinweis: Diese Funktion kann über das Metaobjektsystem und aus QML aufgerufen werden. Siehe „ Q_INVOKABLE “.
Siehe auch ` mapToSource()`.
[virtual invokable] QItemSelection QAbstractProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const
Gibt eine Proxy-Auswahl zurück, die aus der angegebenen „ sourceSelection “ abgebildet wurde.
Implementieren Sie diese Methode neu, um Quellauswahlen auf Proxy-Auswahlen abzubilden.
Hinweis: Diese Funktion kann über das Metaobjektsystem und aus QML aufgerufen werden. Siehe Q_INVOKABLE.
[virtual invokable] QItemSelection QAbstractProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const
Gibt eine Quellauswahl zurück, die aus dem angegebenen ` proxySelection` abgebildet wurde.
Implementieren Sie diese Methode neu, um Proxy-Auswahlen auf Quellauswahlen abzubilden.
Hinweis: Diese Funktion kann über das Metaobjektsystem und aus QML aufgerufen werden. Siehe Q_INVOKABLE.
[pure virtual invokable] QModelIndex QAbstractProxyModel::mapToSource(const QModelIndex &proxyIndex) const
Implementieren Sie diese Funktion neu, um den Modellindex im Quellmodell zurückzugeben, der dem „ proxyIndex “ im Proxy-Modell entspricht.
Hinweis: Diese Funktion kann über das Metaobjektsystem und aus QML aufgerufen werden. Siehe Q_INVOKABLE.
Siehe auch ` mapFromSource()`.
[override virtual] QMimeData *QAbstractProxyModel::mimeData(const QModelIndexList &indexes) const
Implementiert neu: ` QAbstractItemModel::mimeData(const QModelIndexList &indexes) const`.
[override virtual] QStringList QAbstractProxyModel::mimeTypes() const
Implementiert erneut: ` QAbstractItemModel::mimeTypes()` const.
[override virtual] void QAbstractProxyModel::revert()
Implementiert: QAbstractItemModel::revert().
[override virtual] QHash<int, QByteArray> QAbstractProxyModel::roleNames() const
Implementiert: ` QAbstractItemModel::roleNames()` const.
[override virtual] bool QAbstractProxyModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
Implementiert: ` QAbstractItemModel::setData` (const QModelIndex &index, const QVariant &value, int role).
Siehe auch data().
[override virtual] bool QAbstractProxyModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole)
Implementiert erneut: QAbstractItemModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role).
Siehe auch headerData().
[override virtual] bool QAbstractProxyModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)
Implementiert: ` QAbstractItemModel::setItemData` (const QModelIndex &index, const QMap<int, QVariant> &roles).
Siehe auch itemData().
[virtual] void QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
Legt fest, dass die angegebene ` sourceModel ` vom Proxy-Modell verarbeitet werden soll.
Unterklassen sollten zu Beginn der Methode ` beginResetModel()` aufrufen, die Verbindung zum alten Modell trennen, diese Methode aufrufen, eine Verbindung zum neuen Modell herstellen und ` endResetModel()` aufrufen.
Hinweis: Setter -Funktion für die Eigenschaft ` sourceModel`.
Siehe auch ` sourceModel()`.
[override virtual] QModelIndex QAbstractProxyModel::sibling(int row, int column, const QModelIndex &idx) const
Implementiert neu: ` QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const`.
[override virtual] void QAbstractProxyModel::sort(int column, Qt::SortOrder order = Qt::AscendingOrder)
Implementiert: QAbstractItemModel::sort(int column, Qt::SortOrder order).
QAbstractItemModel *QAbstractProxyModel::sourceModel() const
Gibt das Modell zurück, das die Daten enthält, die über das Proxy-Modell verfügbar sind.
Hinweis: Getter -Funktion für die Eigenschaft `sourceModel`.
Siehe auch „ setSourceModel()“.
[override virtual] QSize QAbstractProxyModel::span(const QModelIndex &index) const
Implementiert neu: ` QAbstractItemModel::span(const QModelIndex &index) const`.
[override virtual] bool QAbstractProxyModel::submit()
Implementiert: QAbstractItemModel::submit().
[override virtual] Qt::DropActions QAbstractProxyModel::supportedDragActions() const
Implementiert: ` QAbstractItemModel::supportedDragActions()` const.
[override virtual] Qt::DropActions QAbstractProxyModel::supportedDropActions() const
Implementiert erneut: ` QAbstractItemModel::supportedDropActions()` const.
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.