QIdentityProxyModel 类
The QIdentityProxyModel class proxies its source model unmodified. 更多...
头文件 | #include <QIdentityProxyModel> |
CMake | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake | QT += core |
继承 | QAbstractProxyModel |
公共函数
QIdentityProxyModel(QObject *parent = nullptr) | |
虚函数 | ~QIdentityProxyModel() |
重新 implemented 公共函数
虚函数 int | columnCount(const QModelIndex &parent = QModelIndex()) const override |
虚拟 bool | dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override |
虚拟 QVariant | headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override |
虚拟 QModelIndex | index(int row, int column, const QModelIndex &parent = QModelIndex()) const override |
虚拟 bool | insertColumns(int column, int count, const QModelIndex &parent = QModelIndex()) override |
虚拟 bool | insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override |
虚拟 QModelIndex | mapFromSource(const QModelIndex &sourceIndex) const override |
虚拟 QItemSelection | mapSelectionFromSource(const QItemSelection &selection) const override |
虚拟 QItemSelection | mapSelectionToSource(const QItemSelection &selection) const override |
虚拟 QModelIndex | mapToSource(const QModelIndex &proxyIndex) const override |
虚拟 QModelIndexList | match(const QModelIndex &start, int role, const QVariant &value, int hits = 1, Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap)) const override |
虚拟 bool | moveColumns(const QModelIndex &sourceParent, int sourceColumn, int count, const QModelIndex &.destinationParent, int destinationChild) override |
虚拟 bool | moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &.destinationParent, int destinationChild) override |
虚拟 QModelIndex | parent(const QModelIndex &child) const override |
虚拟 bool | removeColumns(int column, int count, const QModelIndex &.parent = QModelIndex()) override |
虚拟 bool | removeRows(int row, int count, const QModelIndex &.parent = QModelIndex()) override |
虚函数 int | rowCount(const QModelIndex &parent = QModelIndex()) const override |
虚拟函数 void | setSourceModel(QAbstractItemModel *newSourceModel) override |
虚拟 QModelIndex | sibling(int row, int column, const QModelIndex &idx) const override |
详细描述
QIdentityProxyModel 可以精确地转发源模型的结构,没有任何排序、筛选或其他转换。这在概念上类似于单位矩阵,其中 A.I = A。
因为它不进行排序或筛选,这个类最适合于转换源模型的数据的代理模型。例如,可以创建一个代理模型来定义字体、背景颜色或工具提示等。这样就不需要在创建模型结构的同一类中实现所有数据处理,还可以用来创建可重用组件。
这还提供了一种在源模型由无法修改的第三方提供的情况下更改数据的方法。
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); } 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。
成员函数文档
[显式]
QIdentityProxyModel::QIdentityProxyModel(QObject *parent = nullptr)
使用给定的 父对象 构造一个单位模型。
[虚拟 noexcept]
QIdentityProxyModel::~QIdentityProxyModel()
销毁此单位模型。
[覆盖虚拟]
int QIdentityProxyModel::columnCount(const QModelIndex &parent = QModelIndex()) const
重新实现: QAbstractItemModel::columnCount(const QModelIndex &parent) const.
[覆盖虚拟]
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).
[覆盖虚拟]
QVariant QIdentityProxyModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
重新实现: QAbstractProxyModel::headerData(int section, Qt::Orientation orientation, int role) const.
[覆盖虚拟]
QModelIndex QIdentityProxyModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const
重实:[含字符 & 和 ] QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const.
[重载虚函数]
bool QIdentityProxyModel::insertColumns(int column, int count, const QModelIndex &parent = QModelIndex())
重实:[含字符 & 和 ] QAbstractItemModel::insertColumns(int column, int count, const QModelIndex &parent).
[重载虚函数]
bool QIdentityProxyModel::insertRows(int row, int count, const QModelIndex &parent = QModelIndex())
重实:[含字符 & 和 ] QAbstractItemModel::insertRows(int row, int count, const QModelIndex &parent).
[重载虚函数]
QModelIndex QIdentityProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
重实:[含字符 & 和 ] QAbstractProxyModel::mapFromSource(const QModelIndex &sourceIndex) const.
[重载虚函数]
QItemSelection QIdentityProxyModel::mapSelectionFromSource(const QItemSelection &selection) const
重实:[含字符 & 和 ] QAbstractProxyModel::mapSelectionFromSource(const QItemSelection &sourceSelection) const.
[重载虚函数]
QItemSelection QIdentityProxyModel::mapSelectionToSource(const QItemSelection &selection) const
重实:[含字符 & 和 ] QAbstractProxyModel::mapSelectionToSource(const QItemSelection &proxySelection) const.
[重载虚函数]
QModelIndex QIdentityProxyModel::mapToSource(const QModelIndex &proxyIndex) const
重实:[含字符 & 和 ] QAbstractProxyModel::mapToSource(const QModelIndex &proxyIndex) const.
[重载虚函数]
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.
[重载虚函数]
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).
[覆写虚函数]
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).
[覆写虚函数]
QModelIndex QIdentityProxyModel::parent(const QModelIndex &child) const
重写: QAbstractItemModel::parent(const QModelIndex &index) const.
[覆写虚函数]
bool QIdentityProxyModel::removeColumns(int column, int count, const QModelIndex &parent = QModelIndex())
重写: QAbstractItemModel::removeColumns(int column, int count, const QModelIndex &parent).
[覆写虚函数]
bool QIdentityProxyModel::removeRows(int row, int count, const QModelIndex &parent = QModelIndex())
重写: QAbstractItemModel::removeRows(int row, int count, const QModelIndex &parent).
[覆写虚函数]
int QIdentityProxyModel::rowCount(const QModelIndex &parent = QModelIndex()) const
重写: QAbstractItemModel::rowCount(const QModelIndex &parent) const.
[覆写虚函数]
void QIdentityProxyModel::setSourceModel(QAbstractItemModel *newSourceModel)
重写: QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel).
[覆写虚函数]
QModelIndex QIdentityProxyModel::sibling(int row, int column, const QModelIndex &idx) const
重写: QAbstractProxyModel::sibling(int row, int column, const QModelIndex &idx) const.
© 2024 Qt公司有限公司。本文件中包含的文档贡献属于各自所有者的版权。提供的文档根据GNU自由文档许可协议版本1.3的条款进行许可,由自由软件基金会发布。Qt及其相关标志是芬兰和/或其他国家/地区Qt公司有限公司的商标。所有其他商标都是各自所有者的财产。