QConcatenateTablesProxyModel Class
The QConcatenateTablesProxyModel class proxies multiple source models, concatenating their rows. More...
Header: | #include <QConcatenateTablesProxyModel> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
Inherits: | QAbstractItemModel |
Public Functions
QConcatenateTablesProxyModel(QObject *parent = nullptr) | |
virtual | ~QConcatenateTablesProxyModel() |
void | addSourceModel(QAbstractItemModel *sourceModel) |
QModelIndex | mapFromSource(const QModelIndex &sourceIndex) const |
QModelIndex | mapToSource(const QModelIndex &proxyIndex) const |
void | removeSourceModel(QAbstractItemModel *sourceModel) |
QList<QAbstractItemModel *> | sourceModels() const |
Reimplemented Public Functions
virtual bool | canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override |
virtual int | columnCount(const QModelIndex &parent = QModelIndex()) const override |
virtual QVariant | data(const QModelIndex &index, int role = Qt::DisplayRole) const override |
virtual bool | dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override |
virtual Qt::ItemFlags | flags(const QModelIndex &index) const 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 QMap<int, QVariant> | itemData(const QModelIndex &proxyIndex) const override |
virtual QMimeData * | mimeData(const QModelIndexList &indexes) const override |
virtual QStringList | mimeTypes() const override |
virtual QModelIndex | parent(const QModelIndex &index) const override |
virtual int | rowCount(const QModelIndex &parent = QModelIndex()) const override |
virtual bool | setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override |
virtual bool | setItemData(const QModelIndex &proxyIndex, const QMap<int, QVariant> &roles) override |
virtual QSize | span(const QModelIndex &index) const override |
Detailed Description
QConcatenateTablesProxyModel takes multiple source models and concatenates their rows.
In other words, the proxy will have all rows of the first source model, followed by all rows of the second source model, and so on.
If the source models don't have the same number of columns, the proxy will only have as many columns as the source model with the smallest number of columns. Additional columns in other source models will simply be ignored.
Source models can be added and removed at runtime, and the column count is adjusted accordingly.
This proxy does not inherit from QAbstractProxyModel because it uses multiple source models, rather than a single one.
Only flat models (lists and tables) are supported, tree models are not.
See also QAbstractProxyModel, Model/View Programming, QIdentityProxyModel, and QAbstractItemModel.
Member Function Documentation
[explicit]
QConcatenateTablesProxyModel::QConcatenateTablesProxyModel(QObject *parent = nullptr)
Constructs a concatenate-rows proxy model with the given parent.
[virtual]
QConcatenateTablesProxyModel::~QConcatenateTablesProxyModel()
Destroys this proxy model.
void QConcatenateTablesProxyModel::addSourceModel(QAbstractItemModel *sourceModel)
Adds a source model sourceModel, below all previously added source models.
The ownership of sourceModel is not affected by this.
The same source model cannot be added more than once.
[override virtual]
bool QConcatenateTablesProxyModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
Reimplements: QAbstractItemModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const.
[override virtual]
int QConcatenateTablesProxyModel::columnCount(const QModelIndex &parent = QModelIndex()) const
Reimplements: QAbstractItemModel::columnCount(const QModelIndex &parent) const.
This method returns the column count of the source model with the smallest number of columns.
[override virtual]
QVariant QConcatenateTablesProxyModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const
Reimplements: QAbstractItemModel::data(const QModelIndex &index, int role) const.
See also setData().
[override virtual]
bool QConcatenateTablesProxyModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
Reimplements: QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent).
QConcatenateTablesProxyModel handles dropping onto an item, between items, and after the last item. In all cases the call is forwarded to the underlying source model. When dropping onto an item, the source model for this item is called. When dropping between items, the source model immediately below the drop position is called. When dropping after the last item, the last source model is called.
[override virtual]
Qt::ItemFlags QConcatenateTablesProxyModel::flags(const QModelIndex &index) const
Reimplements: QAbstractItemModel::flags(const QModelIndex &index) const.
Returns the flags for the given index. If the index is valid, the flags come from the source model for this index. If the index is invalid (as used to determine if dropping onto an empty area in the view is allowed, for instance), the flags from the first model are returned.
[override virtual]
QVariant QConcatenateTablesProxyModel::headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
Reimplements: QAbstractItemModel::headerData(int section, Qt::Orientation orientation, int role) const.
This method returns the horizontal header data for the first source model, and the vertical header data for the source model corresponding to each row.
[override virtual]
QModelIndex QConcatenateTablesProxyModel::index(int row, int column, const QModelIndex &parent = QModelIndex()) const
Reimplements: QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const.
[override virtual]
QMap<int, QVariant> QConcatenateTablesProxyModel::itemData(const QModelIndex &proxyIndex) const
Reimplements: QAbstractItemModel::itemData(const QModelIndex &index) const.
See also setItemData().
QModelIndex QConcatenateTablesProxyModel::mapFromSource(const QModelIndex &sourceIndex) const
Returns the proxy index for a given sourceIndex, which can be from any of the source models.
QModelIndex QConcatenateTablesProxyModel::mapToSource(const QModelIndex &proxyIndex) const
Returns the source index for a given proxyIndex.
[override virtual]
QMimeData *QConcatenateTablesProxyModel::mimeData(const QModelIndexList &indexes) const
Reimplements: QAbstractItemModel::mimeData(const QModelIndexList &indexes) const.
The call is forwarded to the source model of the first index in the list of indexes.
Important: please note that this proxy only supports dragging a single row. It will assert if called with indexes from multiple rows, because dragging rows that might come from different source models cannot be implemented generically by this proxy model. Each piece of data in the QMimeData needs to be merged, which is data-type-specific. Reimplement this method in a subclass if you want to support dragging multiple rows.
[override virtual]
QStringList QConcatenateTablesProxyModel::mimeTypes() const
Reimplements: QAbstractItemModel::mimeTypes() const.
This method returns the mime types for the first source model.
[override virtual]
QModelIndex QConcatenateTablesProxyModel::parent(const QModelIndex &index) const
Reimplements: QAbstractItemModel::parent(const QModelIndex &index) const.
void QConcatenateTablesProxyModel::removeSourceModel(QAbstractItemModel *sourceModel)
Removes the source model sourceModel, which was previously added to this proxy.
The ownership of sourceModel is not affected by this.
[override virtual]
int QConcatenateTablesProxyModel::rowCount(const QModelIndex &parent = QModelIndex()) const
Reimplements: QAbstractItemModel::rowCount(const QModelIndex &parent) const.
[override virtual]
bool QConcatenateTablesProxyModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
Reimplements: QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value, int role).
See also data().
[override virtual]
bool QConcatenateTablesProxyModel::setItemData(const QModelIndex &proxyIndex, const QMap<int, QVariant> &roles)
Reimplements: QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles).
See also itemData().
QList<QAbstractItemModel *> QConcatenateTablesProxyModel::sourceModels() const
Returns a list of models that were added as source models for this proxy model.
[override virtual]
QSize QConcatenateTablesProxyModel::span(const QModelIndex &index) const
Reimplements: QAbstractItemModel::span(const QModelIndex &index) const.
© 2024 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.