Sur cette page

QIdentityProxyModel Class

La classe `QIdentityProxyModel` sert de proxy à son modèle source sans le modifier. En savoir plus...

En-tête : #include <QIdentityProxyModel>
CMake : find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake : QT += core
Hérite de : QAbstractProxyModel

Fonctions publiques

QIdentityProxyModel(QObject *parent = nullptr)
virtual ~QIdentityProxyModel()
(since 6.8) bool handleSourceDataChanges() const
(since 6.8) bool handleSourceLayoutChanges() const

Fonctions publiques réimplémentées

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

Fonctions protégées

(since 6.8) void setHandleSourceDataChanges(bool b)
(since 6.8) void setHandleSourceLayoutChanges(bool b)

Description détaillée

QIdentityProxyModel permet de restituer exactement la structure d'un modèle source, sans tri, filtrage ni autre transformation. Ce concept s'apparente à celui d'une matrice identité où A.I = A.

Comme elle n'effectue ni tri ni filtrage, cette classe est particulièrement adaptée aux modèles proxy qui transforment l'data() du modèle source. Par exemple, un modèle proxy pourrait être créé pour définir la police utilisée, la couleur d’arrière-plan, l’info-bulle, etc. Cela évite d’avoir à implémenter l’ensemble du traitement des données dans la même classe qui crée la structure du modèle, et permet également de créer des composants réutilisables.

Cela permet également de modifier les données dans le cas où un modèle source est fourni par un tiers et ne peut pas être modifié.

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;
};

Voir également QAbstractProxyModel, Programmation Modèle/Vue, et QAbstractItemModel.

Documentation sur les fonctions membres

[explicit] QIdentityProxyModel::QIdentityProxyModel(QObject *parent = nullptr)

Construit un modèle d’identité à partir de l’ parent ion fournie.

[virtual noexcept] QIdentityProxyModel::~QIdentityProxyModel()

Supprime ce modèle d'identité.

[override virtual] int QIdentityProxyModel::columnCount(const QModelIndex &parent = QModelIndex()) const

Réimplémente : QAbstractItemModel::columnCount(const QModelIndex &parent) const.

[override virtual] bool QIdentityProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)

Réimplémente : QAbstractProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent).

[since 6.8] bool QIdentityProxyModel::handleSourceDataChanges() const

Renvoie « true » si ce modèle proxy gère les modifications apportées aux données du modèle source ; sinon, renvoie « false ».

Cette fonction a été introduite dans Qt 6.8.

Voir également setHandleSourceDataChanges().

[since 6.8] bool QIdentityProxyModel::handleSourceLayoutChanges() const

Renvoie « true » si ce modèle proxy gère les modifications de mise en page du modèle source ; sinon, renvoie « false ».

Cette fonction a été introduite dans Qt 6.8.

Voir également setHandleSourceLayoutChanges().

[override virtual] QVariant QIdentityProxyModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const

Réimplémente : QAbstractProxyModel::headerData(int section, Qt::Orientation orientation, int role) const.

[override virtual] QModelIndex QIdentityProxyModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const

Réimplémente : QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const.

[override virtual] bool QIdentityProxyModel::insertColumns(int column, int count, const QModelIndex &parent = QModelIndex())

Réimplémente : QAbstractItemModel::insertColumns(int column, int count, const QModelIndex &parent).

[override virtual] bool QIdentityProxyModel::insertRows(int row, int count, const QModelIndex &parent = QModelIndex())

Réimplémente : QAbstractItemModel::insertRows(int row, int count, const QModelIndex &parent).

[override virtual] QModelIndex QIdentityProxyModel::mapFromSource(const QModelIndex &sourceIndex) const

Réimplémente : QAbstractProxyModel::mapFromSource(const QModelIndex &sourceIndex) const.

[override virtual] QItemSelection QIdentityProxyModel::mapSelectionFromSource(const QItemSelection &selection) const

Réimplémente : QAbstractProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const.

[override virtual] QItemSelection QIdentityProxyModel::mapSelectionToSource(const QItemSelection &selection) const

Réimplémente : ` QAbstractProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const`.

[override virtual] QModelIndex QIdentityProxyModel::mapToSource(const QModelIndex &proxyIndex) const

Réimplémente : 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

Réimplémente : 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)

Réimplémente : 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)

Réimplémente : QAbstractItemModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild).

[override virtual] QModelIndex QIdentityProxyModel::parent(const QModelIndex &child) const

Réimplémente : QAbstractItemModel::parent(const QModelIndex &index) const.

[override virtual] bool QIdentityProxyModel::removeColumns(int column, int count, const QModelIndex &parent = QModelIndex())

Réimplémente : QAbstractItemModel::removeColumns(int column, int count, const QModelIndex &parent).

[override virtual] bool QIdentityProxyModel::removeRows(int row, int count, const QModelIndex &parent = QModelIndex())

Réimplémente : QAbstractItemModel::removeRows(int row, int count, const QModelIndex &parent).

[override virtual] int QIdentityProxyModel::rowCount(const QModelIndex &parent = QModelIndex()) const

Réimplémente : ` QAbstractItemModel::rowCount(const QModelIndex &parent) const`.

[protected, since 6.8] void QIdentityProxyModel::setHandleSourceDataChanges(bool b)

Si b correspond à true, ce modèle proxy gérera les modifications apportées aux données du modèle source (en se connectant au signal QAbstractItemModel::dataChanged ).

Par défaut, ce modèle proxy gère les modifications apportées aux données du modèle source.

Dans les sous-classes de ` QIdentityProxyModel`, il peut être utile de définir cette valeur sur ` false ` si vous devez gérer de manière spécifique les modifications apportées aux données du modèle source.

Remarque : l’appel de cette méthode ne prendra effet qu’après l’appel de ` setSourceModel()`.

Cette fonction a été introduite dans Qt 6.8.

Voir également handleSourceDataChanges().

[protected, since 6.8] void QIdentityProxyModel::setHandleSourceLayoutChanges(bool b)

Si b est true, ce modèle proxy gérera les modifications de mise en page du modèle source (en se connectant aux signaux QAbstractItemModel::layoutAboutToBeChanged et QAbstractItemModel::layoutChanged ).

Par défaut, ce modèle proxy gère les modifications d’agencement du modèle source.

Dans les sous-classes de ` QIdentityProxyModel`, il peut être utile de définir cette propriété sur ` false ` si vous devez gérer de manière spécifique les modifications de mise en page du modèle source.

Remarque : l'appel de cette méthode ne prendra effet qu'après l'appel de ` setSourceModel()`

Cette fonction a été introduite dans Qt 6.8.

Voir également handleSourceLayoutChanges().

[override virtual] void QIdentityProxyModel::setSourceModel(QAbstractItemModel *newSourceModel)

Réimplémente : QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel).

[override virtual] QModelIndex QIdentityProxyModel::sibling(int row, int column, const QModelIndex &idx) const

Réimplémente : 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.