Класс QIdentityProxyModel
Класс QIdentityProxyModel проксирует свой исходный модель без изменений. Подробнее...
| Заголовок: | #include <QIdentityProxyModel> |
| qmake: | QT += core |
| С момента: | Qt 4.8 |
| Наследуется от: | QAbstractProxyModel |
Этот класс был представлен в Qt 4.8.
Публичные функции
| QIdentityProxyModel(QObject *parent = nullptr) | |
| virtual | ~QIdentityProxyModel() |
Переопределенные публичные функции
| виртуальный 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 |
| виртуальный 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);
}
private:
QString m_formatString;
}; См. также QAbstractProxyModel, Программирование модели/представления и QAbstractItemModel.
Документация по функциям-членам
QIdentityProxyModel::QIdentityProxyModel(QObject *parent = nullptr)
Создаёт модель тождества с заданным parent.
[virtual] 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).
[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.
END_OF_DOCUMENT_MARKER
[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] 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.
© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-5.13/qidentityproxymodel.html