QIdentityProxyModel Class
Die Klasse „QIdentityProxyModel“ gibt ihr Quellmodell unverändert weiter. Mehr...
| Header: | #include <QIdentityProxyModel> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| Erbt: | QAbstractProxyModel |
Öffentliche Funktionen
| QIdentityProxyModel(QObject *parent = nullptr) | |
| virtual | ~QIdentityProxyModel() |
(since 6.8) bool | handleSourceDataChanges() const |
(since 6.8) bool | handleSourceLayoutChanges() const |
Neu implementierte öffentliche Funktionen
| virtual int | columnCount(const QModelIndex &parent = QModelIndex()) const override |
| virtual bool | dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override |
| virtual QVariant | headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override |
| virtual QModelIndex | index(int row, int column, const QModelIndex &parent = QModelIndex()) const override |
| virtual bool | insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override |
| virtual bool | insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override |
| virtual QModelIndex | mapFromSource(const QModelIndex &sourceIndex) const override |
| virtual QItemSelection | mapSelectionFromSource(const QItemSelection &selection) const override |
| virtual QItemSelection | mapSelectionToSource(const QItemSelection &selection) const override |
| virtual QModelIndex | mapToSource(const QModelIndex &proxyIndex) const override |
| virtual QModelIndexList | match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const override |
| virtual bool | moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild) override |
| virtual bool | moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override |
| virtual QModelIndex | parent(const QModelIndex &child) const override |
| virtual bool | removeColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override |
| virtual bool | removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override |
| virtual int | rowCount(const QModelIndex &parent = QModelIndex()) const override |
| virtual void | setSourceModel(QAbstractItemModel *newSourceModel) override |
| virtual QModelIndex | sibling(int row, int column, const QModelIndex &idx) const override |
Geschützte Funktionen
(since 6.8) void | setHandleSourceDataChanges(bool b) |
(since 6.8) void | setHandleSourceLayoutChanges(bool b) |
Ausführliche Beschreibung
QIdentityProxyModel kann verwendet werden, um die Struktur eines Quellmodells exakt weiterzugeben, ohne Sortierung, Filterung oder andere Transformationen. Dies ähnelt konzeptionell einer Identitätsmatrix, bei der A.I = A gilt.
Da diese Klasse weder sortiert noch filtert, eignet sie sich am besten für Proxy-Modelle, die die „ data()“-Funktion des Quellmodells transformieren. Beispielsweise könnte ein Proxy-Modell erstellt werden, um die verwendete Schriftart, die Hintergrundfarbe oder den Tooltip usw. zu definieren. Dadurch entfällt die Notwendigkeit, die gesamte Datenverarbeitung in derselben Klasse zu implementieren, die die Struktur des Modells erstellt, und es können zudem wiederverwendbare Komponenten erstellt werden.
Dies bietet zudem eine Möglichkeit, die Daten zu ändern, falls ein Quellmodell von einem Drittanbieter bereitgestellt wird, das nicht verändert werden darf.
class DateFormatProxyModel : public QIdentityProxyModel
{
// ...
void setDateFormatString(const QString &formatString)
{
m_formatString = formatString;
}
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override
{
if (role != Qt::DisplayRole)
return QIdentityProxyModel::data(index, role);
const QModelIndex sourceIndex = mapToSource(index);
const QDateTime dateTime = sourceModel()->data(sourceIndex, SourceClass::DateRole).toDateTime();
return dateTime.toString(m_formatString);
}
QMap<int, QVariant> itemData(const QModelIndex &proxyIndex) const override
{
QMap<int, QVariant> map = QIdentityProxyModel::itemData(proxyIndex);
map[Qt::DisplayRole] = data(proxyIndex);
return map;
}
private:
QString m_formatString;
};Siehe auch QAbstractProxyModel, Modell-/Ansichtsprogrammierung und QAbstractItemModel.
Dokumentation zu Mitgliedsfunktionen
[explicit] QIdentityProxyModel::QIdentityProxyModel(QObject *parent = nullptr)
Erstellt ein Identitätsmodell mit dem angegebenen „ parent “.
[virtual noexcept] QIdentityProxyModel::~QIdentityProxyModel()
Löscht dieses Identitätsmodell.
[override virtual] int QIdentityProxyModel::columnCount(const QModelIndex &parent = QModelIndex()) const
Implementiert neu: ` QAbstractItemModel::columnCount(const QModelIndex &parent) const`.
[override virtual] bool QIdentityProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Implementiert: ` QAbstractProxyModel::dropMimeData` (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent).
[since 6.8] bool QIdentityProxyModel::handleSourceDataChanges() const
Gibt „ true “ zurück, wenn dieses Proxy-Modell die Änderungen an den Daten des Quellmodells verarbeitet; andernfalls wird „ false “ zurückgegeben.
Diese Funktion wurde in Qt 6.8 eingeführt.
Siehe auch setHandleSourceDataChanges().
[since 6.8] bool QIdentityProxyModel::handleSourceLayoutChanges() const
Gibt „ true “ zurück, wenn dieses Proxy-Modell Änderungen am Layout des Quellmodells verarbeitet; andernfalls wird „ false “ zurückgegeben.
Diese Funktion wurde in Qt 6.8 eingeführt.
Siehe auch ` setHandleSourceLayoutChanges()`.
[override virtual] QVariant QIdentityProxyModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
Implementiert neu: ` QAbstractProxyModel::headerData(int section, Qt::Orientation orientation, int role) const`.
[override virtual] QModelIndex QIdentityProxyModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const
Implementiert: ` QAbstractItemModel::index` (int row, int column, const QModelIndex &parent) const.
[override virtual] bool QIdentityProxyModel::insertColumns(int column, int count, const QModelIndex &parent = QModelIndex())
Implementiert: ` QAbstractItemModel::insertColumns` (int column, int count, const QModelIndex &parent).
[override virtual] bool QIdentityProxyModel::insertRows(int row, int count, const QModelIndex &parent = QModelIndex())
Implementiert: ` QAbstractItemModel::insertRows` (int row, int count, const QModelIndex &parent).
[override virtual] QModelIndex QIdentityProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
Implementiert neu: ` QAbstractProxyModel::mapFromSource(const QModelIndex &sourceIndex) const`.
[override virtual] QItemSelection QIdentityProxyModel::mapSelectionFromSource(const QItemSelection &selection) const
Implementiert neu: ` QAbstractProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const`.
[override virtual] QItemSelection QIdentityProxyModel::mapSelectionToSource(const QItemSelection &selection) const
Implementiert neu: ` QAbstractProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const`.
[override virtual] QModelIndex QIdentityProxyModel::mapToSource(const QModelIndex &proxyIndex) const
Implementiert neu: ` QAbstractProxyModel::mapToSource(const QModelIndex &proxyIndex) const`.
[override virtual] QModelIndexList QIdentityProxyModel::match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const
Implementiert neu: ` QAbstractItemModel::match(const QModelIndex &start, int role, const QVariant &value, int hits, Qt::MatchFlags flags) const`.
[override virtual] bool QIdentityProxyModel::moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild)
Umsetzt: ` QAbstractItemModel::moveColumns` (const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &destinationParent, int destinationChild).
[override virtual] bool QIdentityProxyModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
Umsetzt: ` QAbstractItemModel::moveRows` (const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild).
[override virtual] QModelIndex QIdentityProxyModel::parent(const QModelIndex &child) const
Implementiert neu: ` QAbstractItemModel::parent(const QModelIndex &index) const`.
[override virtual] bool QIdentityProxyModel::removeColumns(int column, int count, const QModelIndex &parent = QModelIndex())
Implementiert: ` QAbstractItemModel::removeColumns` (int column, int count, const QModelIndex &parent).
[override virtual] bool QIdentityProxyModel::removeRows(int row, int count, const QModelIndex &parent = QModelIndex())
Implementiert: ` QAbstractItemModel::removeRows` (int row, int count, const QModelIndex &parent).
[override virtual] int QIdentityProxyModel::rowCount(const QModelIndex &parent = QModelIndex()) const
Implementiert: ` QAbstractItemModel::rowCount(const QModelIndex &parent) const`.
[protected, since 6.8] void QIdentityProxyModel::setHandleSourceDataChanges(bool b)
Wenn „ b “ auf „ true “ gesetzt ist, verarbeitet dieses Proxy-Modell die Datenänderungen des Quellmodells (durch die Verbindung zum Signal „ QAbstractItemModel::dataChanged “).
Standardmäßig verarbeitet dieses Proxy-Modell die Datenänderungen des Quellmodells.
In Unterklassen von ` QIdentityProxyModel` kann es sinnvoll sein, diesen Wert auf ` false ` zu setzen, wenn Sie die Datenänderungen des Quellmodells speziell verarbeiten müssen.
Hinweis: Der Aufruf dieser Methode wirkt sich erst nach dem Aufruf von ` setSourceModel()` aus.
Diese Funktion wurde in Qt 6.8 eingeführt.
Siehe auch ` handleSourceDataChanges()`.
[protected, since 6.8] void QIdentityProxyModel::setHandleSourceLayoutChanges(bool b)
Wenn „ b “ auf „ true “ gesetzt ist, übernimmt dieses Proxy-Modell die Layoutänderungen des Quellmodells (durch die Verknüpfung mit den Signalen „ QAbstractItemModel::layoutAboutToBeChanged “ und „ QAbstractItemModel::layoutChanged “).
Standardmäßig übernimmt dieses Proxy-Modell die Layoutänderungen des Quellmodells.
In Unterklassen von ` QIdentityProxyModel` kann es sinnvoll sein, diesen Wert auf ` false ` zu setzen, wenn Sie die Layoutänderungen des Quellmodells speziell behandeln müssen.
Hinweis: Der Aufruf dieser Methode wirkt sich erst nach dem Aufruf von ` setSourceModel()` aus.
Diese Funktion wurde in Qt 6.8 eingeführt.
Siehe auch ` handleSourceLayoutChanges()`.
[override virtual] void QIdentityProxyModel::setSourceModel(QAbstractItemModel *newSourceModel)
Implementiert: ` QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel)`.
[override virtual] QModelIndex QIdentityProxyModel::sibling(int row, int column, const QModelIndex &idx) const
Implementiert neu: ` QAbstractProxyModel::sibling(int row, int column, const QModelIndex &idx) 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.