QAbstractProxyModel Class
Die Klasse QAbstractProxyModel bietet eine Basisklasse für Proxy-Elementmodelle, die Sortier-, Filter- oder andere Datenverarbeitungsaufgaben übernehmen können. Mehr...
Kopfzeile: | #include <QAbstractProxyModel> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
Vererbt: | QAbstractItemModel |
Vererbt von: | QIdentityProxyModel, QSortFilterProxyModel, und 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 |
Reimplementierte ö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 soll nicht direkt instanziiert werden.
Alle Standard-Proxy-Modelle sind von der Klasse QAbstractProxyModel abgeleitet. Wenn Sie eine neue Proxy Model Klasse erstellen müssen, ist es in der Regel besser, eine bestehende Klasse zu subklassifizieren, die das Verhalten bietet, das dem gewünschten am nächsten kommt.
Proxy-Modelle, die Datenelemente aus einem Quellmodell filtern oder sortieren, sollten durch Verwendung oder Unterklassifizierung von QSortFilterProxyModel erstellt werden.
Um QAbstractProxyModel zu subclassen, müssen Sie mapFromSource() und mapToSource() implementieren. Die Funktionen mapSelectionFromSource() und mapSelectionToSource() müssen nur dann neu implementiert werden, wenn Sie ein anderes Verhalten als das Standardverhalten 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 Programming.
Dokumentation der Eigenschaft
[bindable]
sourceModel : QAbstractItemModel*
Hinweis: Diese Eigenschaft unterstützt QProperty Bindungen.
Diese Eigenschaft enthält das Quellmodell dieses Proxy-Modells.
Dokumentation der Mitgliedsfunktionen
[explicit]
QAbstractProxyModel::QAbstractProxyModel(QObject *parent = nullptr)
Konstruiert 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
Reimplements: 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
Reimplements: 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
Reimplements: QAbstractItemModel::canFetchMore(const QModelIndex &parent) const.
[override virtual, since 6.0]
bool QAbstractProxyModel::clearItemData(const QModelIndex &index)
Reimplements: 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
Äquivalent zum Aufruf von createIndex im Quellmodell.
Diese Methode ist nützlich, wenn Ihr Proxy-Modell die Eltern-Kind-Beziehung von Elementen im Quellmodell beibehalten will. Wenn Sie mapToSource() reimplementieren, können Sie diese Methode aufrufen, um einen Index für die Zeile row und die Spalte col des Quellmodells zu erstellen.
Eine typische Anwendung wäre, den internen Zeiger aus dem Quellmodell im Proxy-Index zu speichern, wenn mapFromSource() neu implementiert wird, und denselben internen Zeiger wie internalPtr zu verwenden, um den ursprünglichen Quellindex wiederherzustellen, wenn mapToSource() neu implementiert wird.
Diese Funktion wurde in Qt 6.2 eingeführt.
[override virtual]
QVariant QAbstractProxyModel::data(const QModelIndex &proxyIndex, int role = Qt::DisplayRole) const
Reimplements: 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)
Reimplements: QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent).
[override virtual]
void QAbstractProxyModel::fetchMore(const QModelIndex &parent)
Reimplements: QAbstractItemModel::fetchMore(const QModelIndex &parent).
[override virtual]
Qt::ItemFlags QAbstractProxyModel::flags(const QModelIndex &index) const
Reimplements: QAbstractItemModel::flags(const QModelIndex &index) const.
[override virtual]
bool QAbstractProxyModel::hasChildren(const QModelIndex &parent = QModelIndex()) const
Reimplements: QAbstractItemModel::hasChildren(const QModelIndex &parent) const.
[override virtual]
QVariant QAbstractProxyModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
Reimplements: QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role) const.
Siehe auch setHeaderData().
[override virtual]
QMap<int, QVariant> QAbstractProxyModel::itemData(const QModelIndex &proxyIndex) const
Reimplements: QAbstractItemModel::itemData(const QModelIndex &index) const.
Siehe auch setItemData().
[pure virtual invokable]
QModelIndex QAbstractProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
Reimplementieren Sie diese Funktion, um den Modellindex im Proxymodell zurückzugeben, der dem sourceIndex aus dem Quellmodell entspricht.
Hinweis: Diese Funktion kann über das Meta-Objektsystem und von QML aus aufgerufen werden. Siehe Q_INVOKABLE.
Siehe auch mapToSource().
[virtual invokable]
QItemSelection QAbstractProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const
Gibt eine Proxy-Auswahl zurück, die von der angegebenen sourceSelection zugeordnet wurde.
Reimplementieren Sie diese Methode, um Quellselektionen auf Proxyselektionen abzubilden.
Hinweis: Diese Funktion kann über das Meta-Objektsystem und von QML aus aufgerufen werden. Siehe Q_INVOKABLE.
[virtual invokable]
QItemSelection QAbstractProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const
Gibt eine Quellauswahl zurück, die von der angegebenen proxySelection zugeordnet wurde.
Reimplementieren Sie diese Methode, um Proxy-Auswahlen auf Quell-Auswahlen abzubilden.
Hinweis: Diese Funktion kann über das Meta-Objektsystem und von QML aus aufgerufen werden. Siehe Q_INVOKABLE.
[pure virtual invokable]
QModelIndex QAbstractProxyModel::mapToSource(const QModelIndex &proxyIndex) const
Reimplementieren Sie diese Funktion, um den Modellindex im Quellmodell zurückzugeben, der dem proxyIndex im Proxy-Modell entspricht.
Hinweis: Diese Funktion kann über das Meta-Objektsystem und von QML aus aufgerufen werden. Siehe Q_INVOKABLE.
Siehe auch mapFromSource().
[override virtual]
QMimeData *QAbstractProxyModel::mimeData(const QModelIndexList &indexes) const
Reimplements: QAbstractItemModel::mimeData(const QModelIndexList &indexes) const.
[override virtual]
QStringList QAbstractProxyModel::mimeTypes() const
Reimplements: QAbstractItemModel::mimeTypes() const.
[override virtual]
void QAbstractProxyModel::revert()
Reimplements: QAbstractItemModel::revert().
[override virtual]
QHash<int, QByteArray> QAbstractProxyModel::roleNames() const
Reimplements: QAbstractItemModel::roleNames() const.
[override virtual]
bool QAbstractProxyModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
Reimplements: 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)
Reimplements: 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)
Reimplements: QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles).
Siehe auch itemData().
[virtual]
void QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
Setzt die angegebene sourceModel zur Verarbeitung durch das Proxy-Modell.
Unterklassen sollten zu Beginn der Methode beginResetModel() aufrufen, die Verbindung zum alten Modell trennen, diese Methode aufrufen, sich mit dem neuen Modell verbinden 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
Reimplements: QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const.
[override virtual]
void QAbstractProxyModel::sort(int column, Qt::SortOrder order = Qt::AscendingOrder)
Reimplements: 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
Reimplements: QAbstractItemModel::span(const QModelIndex &index) const.
[override virtual]
bool QAbstractProxyModel::submit()
Reimplements: QAbstractItemModel::submit().
[override virtual]
Qt::DropActions QAbstractProxyModel::supportedDragActions() const
Reimplements: QAbstractItemModel::supportedDragActions() const.
[override virtual]
Qt::DropActions QAbstractProxyModel::supportedDropActions() const
Reimplements: QAbstractItemModel::supportedDropActions() const.
© 2025 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.