QIdentityProxyModel Class
Die Klasse QIdentityProxyModel stellt ihr Quellmodell unverändert zur Verfügung. Mehr...
Kopfzeile: | #include <QIdentityProxyModel> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
Vererbt: | QAbstractProxyModel |
Öffentliche Funktionen
QIdentityProxyModel(QObject *parent = nullptr) | |
virtual | ~QIdentityProxyModel() |
(since 6.8) bool | handleSourceDataChanges() const |
(since 6.8) bool | handleSourceLayoutChanges() const |
Reimplementierte ö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) |
Detaillierte Beschreibung
QIdentityProxyModel kann verwendet werden, um die Struktur eines Quellmodells exakt weiterzuleiten, ohne Sortierung, Filterung oder andere Transformation. Dies ist vom Konzept her ähnlich wie eine Identitätsmatrix, bei der A.I = A ist.
Da sie keine Sortierung oder Filterung vornimmt, ist diese Klasse am besten für Proxy-Modelle geeignet, die die data() des Quellmodells umwandeln. 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 auch wiederverwendbare Komponenten erstellt werden.
Dies bietet auch eine Möglichkeit, die Daten zu ändern, wenn ein Quellmodell von einer dritten Partei geliefert wird, das nicht geändert werden kann.
class DateFormatProxyModel : public QIdentityProxyModel { // ... void setDateFormatString(const QString &formatString) { m_formatString = formatString; } QVariant data(const QModelIndex &index, int role) 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, Model/View Programming, und QAbstractItemModel.
Dokumentation der Mitgliedsfunktionen
[explicit]
QIdentityProxyModel::QIdentityProxyModel(QObject *parent = nullptr)
Konstruiert ein Identitätsmodell mit der angegebenen parent.
[virtual noexcept]
QIdentityProxyModel::~QIdentityProxyModel()
Zerstört dieses Identitätsmodell.
[override virtual]
int QIdentityProxyModel::columnCount(const QModelIndex &parent = QModelIndex()) const
Reimplements: QAbstractItemModel::columnCount(const QModelIndex &parent) const.
[override virtual]
bool QIdentityProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Reimplements: 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 Datenänderungen des Quellmodells verarbeitet, andernfalls false
.
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 die Layout-Änderungen des Quellmodells verarbeitet, andernfalls false
.
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
Reimplements: QAbstractProxyModel::headerData(int section, Qt::Orientation orientation, int role) const.
[override virtual]
QModelIndex QIdentityProxyModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const
Reimplements: QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const.
[override virtual]
bool QIdentityProxyModel::insertColumns(int column, int count, const QModelIndex &parent = QModelIndex())
Reimplements: QAbstractItemModel::insertColumns(int column, int count, const QModelIndex &parent).
[override virtual]
bool QIdentityProxyModel::insertRows(int row, int count, const QModelIndex &parent = QModelIndex())
Reimplements: QAbstractItemModel::insertRows(int row, int count, const QModelIndex &parent).
[override virtual]
QModelIndex QIdentityProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
Reimplements: QAbstractProxyModel::mapFromSource(const QModelIndex &sourceIndex) const.
[override virtual]
QItemSelection QIdentityProxyModel::mapSelectionFromSource(const QItemSelection &selection) const
Reimplements: QAbstractProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const.
[override virtual]
QItemSelection QIdentityProxyModel::mapSelectionToSource(const QItemSelection &selection) const
Reimplements: QAbstractProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const.
[override virtual]
QModelIndex QIdentityProxyModel::mapToSource(const QModelIndex &proxyIndex) const
Reimplements: 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
Reimplements: 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)
Reimplements: 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)
Reimplements: QAbstractItemModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild).
[override virtual]
QModelIndex QIdentityProxyModel::parent(const QModelIndex &child) const
Reimplements: QAbstractItemModel::parent(const QModelIndex &index) const.
[override virtual]
bool QIdentityProxyModel::removeColumns(int column, int count, const QModelIndex &parent = QModelIndex())
Reimplements: QAbstractItemModel::removeColumns(int column, int count, const QModelIndex &parent).
[override virtual]
bool QIdentityProxyModel::removeRows(int row, int count, const QModelIndex &parent = QModelIndex())
Reimplements: QAbstractItemModel::removeRows(int row, int count, const QModelIndex &parent).
[override virtual]
int QIdentityProxyModel::rowCount(const QModelIndex &parent = QModelIndex()) const
Reimplements: QAbstractItemModel::rowCount(const QModelIndex &parent) const.
[protected, since 6.8]
void QIdentityProxyModel::setHandleSourceDataChanges(bool b)
Wenn b true
ist, wird dieses Proxy-Modell die Änderungen der Quellmodelldaten verarbeiten (durch Verbindung mit dem Signal QAbstractItemModel::dataChanged
).
Die Vorgabe ist, dass dieses Proxy-Modell die Datenänderungen des Quellmodells verarbeitet.
In Unterklassen von QIdentityProxyModel kann es nützlich sein, dies auf false
zu setzen, wenn Sie die Änderungen der Quellmodelldaten besonders behandeln müssen.
Hinweis: Der Aufruf dieser Methode hat nur einen Effekt nach dem Aufruf von setSourceModel().
Diese Funktion wurde in Qt 6.8 eingeführt.
Siehe auch handleSourceDataChanges().
[protected, since 6.8]
void QIdentityProxyModel::setHandleSourceLayoutChanges(bool b)
Wenn b true
ist, wird dieses Proxy-Modell die Layout-Änderungen des Quellmodells verarbeiten (durch Verbindung mit den Signalen QAbstractItemModel::layoutAboutToBeChanged
und QAbstractItemModel::layoutChanged
).
Die Standardeinstellung ist, dass dieses Proxy-Modell die Layout-Änderungen des Quellmodells übernimmt.
In Unterklassen von QIdentityProxyModel kann es nützlich sein, dies auf false
zu setzen, wenn Sie die Layoutänderungen des Quellmodells speziell behandeln müssen.
Hinweis: Der Aufruf dieser Methode hat nur einen Effekt nach dem Aufruf von setSourceModel().
Diese Funktion wurde in Qt 6.8 eingeführt.
Siehe auch handleSourceLayoutChanges().
[override virtual]
void QIdentityProxyModel::setSourceModel(QAbstractItemModel *newSourceModel)
Reimplements: QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel).
[override virtual]
QModelIndex QIdentityProxyModel::sibling(int row, int column, const QModelIndex &idx) const
Reimplements: QAbstractProxyModel::sibling(int row, int column, const QModelIndex &idx) 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.