Sur cette page

QIdentityProxyModel Class

La classe QIdentityProxyModel propose son modèle source sans le modifier. Plus d'informations...

En-tête : #include <QIdentityProxyModel>
CMake : find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake : QT += core
Héritages : 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 peut être utilisé pour transmettre exactement la structure d'un modèle source, sans tri, filtrage ou autre transformation. Le concept est similaire à celui d'une matrice d'identité où A.I = A.

Parce qu'elle n'effectue aucun tri ou filtrage, cette classe convient mieux aux modèles mandataires qui transforment le data() du modèle source. Par exemple, un modèle proxy pourrait être créé pour définir la police utilisée, ou la couleur de fond, ou l'info-bulle, etc. Il n'est donc plus nécessaire d'implémenter toutes les manipulations de données dans la même classe que celle qui crée la structure du modèle, et cette méthode peut également être utilisée pour 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 ê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, Model/View Programming, et QAbstractItemModel.

Documentation sur les fonctions membres

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

Construit un modèle d'identité avec l'adresse parent.

[virtual noexcept] QIdentityProxyModel::~QIdentityProxyModel()

Détruit 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

Retourne true si ce modèle proxy gère les changements de données du modèle source, sinon retourne false.

Cette fonction a été introduite dans Qt 6.8.

Voir aussi setHandleSourceDataChanges().

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

Renvoie true si ce modèle proxy gère les changements de disposition du modèle source, sinon renvoie false.

Cette fonction a été introduite dans Qt 6.8.

Voir aussi 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 est true, ce modèle mandataire gérera les modifications des données du modèle source (en se connectant au signal QAbstractItemModel::dataChanged ).

Par défaut, ce modèle mandataire gère les changements de données du modèle source.

Dans les sous-classes de QIdentityProxyModel, il peut être utile d'attribuer la valeur false si vous devez gérer spécialement les modifications des données du modèle source.

Remarque : l'appel à cette méthode n'aura d'effet qu'après l'appel à setSourceModel().

Cette fonction a été introduite dans Qt 6.8.

Voir aussi handleSourceDataChanges().

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

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

Par défaut, ce modèle mandataire gère les modifications de la présentation du modèle source.

Dans les sous-classes de QIdentityProxyModel, il peut être utile d'attribuer la valeur false si vous devez gérer spécialement les modifications de la présentation du modèle source.

Remarque : l'appel à cette méthode n'aura d'effet qu'après l'appel à setSourceModel().

Cette fonction a été introduite dans Qt 6.8.

Voir aussi 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.