このページでは

QIdentityProxyModel Class

QIdentityProxyModel クラスは、ソースモデルをそのままプロキシします。詳細...

ヘッダー: #include <QIdentityProxyModel>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
継承元: QAbstractProxyModel

パブリック関数

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

再実装されたパブリック関数

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

プロテクトされた関数

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

詳細な説明

QIdentityProxyModel を使用すると、ソート、フィルタリング、その他の変換を行うことなく、ソースモデルの構造を正確に転送することができます。これは、A.I = A.となる単位行列の概念に似ています。

ソートやフィルタリングを行わないため、このクラスは、ソースモデルの `data()` を変換するプロキシモデルに最も適しています。 たとえば、使用するフォント、背景色、ツールチップなどを定義するためのプロキシモデルを作成することができます。これにより、モデルの構造を作成する同じクラスですべてのデータ処理を実装する必要がなくなり、再利用可能なコンポーネントを作成するためにも使用できます。

また、変更できないサードパーティ製のソースモデルが提供されている場合にも、データを変更する方法を提供します。

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

「 QAbstractProxyModel 」、「Model/View Programming」、および「QAbstractItemModel 」も参照してください 。

メンバ関数のドキュメント

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

指定されたparent を用いて、アイデンティティモデルを構築します。

[virtual noexcept] QIdentityProxyModel::~QIdentityProxyModel()

このIDモデルを破棄します。

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

QAbstractItemModel::columnCount(const QModelIndex &parent) const を再実装します。

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

QAbstractProxyModel::dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)を再実装します。

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

このプロキシモデルがソースモデルのデータ変更を処理する場合は `true ` を返し、そうでない場合は `false` を返します。

この関数は Qt 6.8 で導入されました。

setHandleSourceDataChanges()も参照してください 。

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

このプロキシモデルがソースモデルのレイアウト変更を処理する場合は `true ` を返し、そうでない場合は `false` を返します。

この関数は Qt 6.8 で導入されました。

setHandleSourceLayoutChanges()も参照してください 。

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

QAbstractProxyModel::headerData(int section, Qt::Orientation orientation, int role) const を再実装します。

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

QAbstractItemModel::index (int row, int column, const QModelIndex &parent)const を再実装します。

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

QAbstractItemModel::insertColumns (int column, int count, const QModelIndex &parent)を再実装します。

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

QAbstractItemModel::insertRows (int row, int count, const QModelIndex &parent)を再実装します。

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

QAbstractProxyModel::mapFromSource(const QModelIndex &sourceIndex) const を再実装します。

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

QAbstractProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const を再実装します。

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

QAbstractProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const を再実装します。

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

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

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)

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)

QAbstractItemModel::moveRows (const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)を再実装します。

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

QAbstractItemModel::parent(const QModelIndex &index) const を再実装します。

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

QAbstractItemModel::removeColumns (int column, int count, const QModelIndex &parent)を再実装します。

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

QAbstractItemModel::removeRows (int row, int count, const QModelIndex &parent)を再実装します。

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

QAbstractItemModel::rowCount(const QModelIndex &parent) const を再実装します。

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

b がtrue の場合、このプロキシモデルはソースモデルのデータ変更を処理します(QAbstractItemModel::dataChanged 信号に接続することで)。

デフォルトでは、このプロキシモデルがソースモデルのデータ変更を処理するように設定されています。

QIdentityProxyModel のサブクラスでは、ソースモデルのデータ変更を特別に処理する必要がある場合、これをfalse に設定すると便利です。

注: このメソッドの呼び出しは 、setSourceModel() を呼び出した後にのみ効果を発揮します。

この関数は Qt 6.8 で導入されました。

handleSourceDataChanges()も参照してください 。

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

b がtrue の場合、このプロキシモデルはソースモデルのレイアウト変更を処理します(QAbstractItemModel::layoutAboutToBeChanged およびQAbstractItemModel::layoutChanged 信号に接続することで)。

デフォルトでは、このプロキシモデルがソースモデルのレイアウト変更を処理するようになっています。

QIdentityProxyModel のサブクラスでは、ソースモデルのレイアウト変更を特別に処理する必要がある場合、これをfalse に設定すると便利です。

注: このメソッドの呼び出しは 、setSourceModel() を呼び出した後にのみ効果を発揮します。

この関数は Qt 6.8 で導入されました。

handleSourceLayoutChanges()も参照してください 。

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

QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel) を再実装します。

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

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.