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) 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 、模型/视图编程和QAbstractItemModel 。
成员函数文档
[explicit]
QIdentityProxyModel::QIdentityProxyModel(QObject *parent = nullptr)
用给定的parent 构建身份模型。
[virtual noexcept]
QIdentityProxyModel::~QIdentityProxyModel()
摧毁这种身份模式。
[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.
© 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.