QIdentityProxyModel Class

The QIdentityProxyModel class proxies its source model unmodified. 更多...

头: #include <QIdentityProxyModel>
CMake: find_package(Qt6 COMPONENTS Core REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
继承: QAbstractProxyModel

公共函数

  QIdentityProxyModel (QObject * parent = nullptr)
virtual ~QIdentityProxyModel ()

重实现公共函数

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

详细描述

QIdentityProxyModel can be used to forward the structure of a source model exactly, with no sorting, filtering or other transformation. This is similar in concept to an identity matrix where A.I = A.

Because it does no sorting or filtering, this class is most suitable to proxy models which transform the data () of the source model. For example, a proxy model could be created to define the font used, or the background colour, or the tooltip etc. This removes the need to implement all data handling in the same class that creates the structure of the model, and can also be used to create re-usable components.

This also provides a way to change the data in the case where a source model is supplied by a third party which cannot be modified.

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 QDateTime dateTime = sourceModel()->data(SourceClass::DateRole).toDateTime();
    return dateTime.toString(m_formatString);
  }
private:
  QString m_formatString;
};
					

另请参阅 QAbstractProxyModel , 模型/视图编程 ,和 QAbstractItemModel .

成员函数文档编制

QIdentityProxyModel:: QIdentityProxyModel ( QObject * parent = nullptr)

Constructs an identity model with the given parent .

[虚拟] QIdentityProxyModel:: ~QIdentityProxyModel ()

Destroys this identity model.

[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).

[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, since 5.15] 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).

该函数在 Qt 5.15 引入。

[override virtual, since 5.15] 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).

该函数在 Qt 5.15 引入。

[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.

[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.