IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QConcatenateTablesProxyModel Class

The QConcatenateTablesProxyModel class proxies multiple source models, concatenating their rows.

This class was introduced in Qt 5.13.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QConcatenateTablesProxyModel Class

  • Header: QConcatenateTablesProxyModel

  • Since: Qt 5.13

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Core)

    target_link_libraries(mytarget PRIVATE Qt6::Core)

  • qmake: QT += core

  • Inherits: QAbstractItemModel

  • Group: QConcatenateTablesProxyModel is part of model-view

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

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

[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

[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

[override virtual] QMap<int, QVariant> QConcatenateTablesProxyModel::itemData(const QModelIndex &proxyIndex) const

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

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

[override virtual] bool QConcatenateTablesProxyModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)

[override virtual] bool QConcatenateTablesProxyModel::setItemData(const QModelIndex &proxyIndex, const QMap<int, QVariant> &roles)

[since 5.15] QList<QAbstractItemModel *> QConcatenateTablesProxyModel::sourceModels() const

Returns a list of models that were added as source models for this proxy model.

This function was introduced in Qt 5.15.

[override virtual] QSize QConcatenateTablesProxyModel::span(const QModelIndex &index) const

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+