KExtraColumnsProxyModel Class
This proxy appends extra columns (after all existing columns). More...
Header: | #include <KExtraColumnsProxyModel> |
CMake: | find_package(KF6 REQUIRED COMPONENTS ItemModels) target_link_libraries(mytarget PRIVATE KF6::ItemModels) |
Since: | KDE Frameworks 5.13 |
Inherits: | QIdentityProxyModel |
Public Functions
KExtraColumnsProxyModel(QObject *parent = nullptr) | |
virtual | ~KExtraColumnsProxyModel() override |
void | appendColumn(const QString &header = QString()) |
virtual QVariant | extraColumnData(const QModelIndex &parent, int row, int extraColumn, int role = Qt::DisplayRole) const = 0 |
void | extraColumnDataChanged(const QModelIndex &parent, int row, int extraColumn, const QList<int> &roles) |
int | extraColumnForProxyColumn(int proxyColumn) const |
int | proxyColumnForExtraColumn(int extraColumn) const |
(since 5.24) void | removeExtraColumn(int idx) |
virtual bool | setExtraColumnData(const QModelIndex &parent, int row, int extraColumn, const QVariant &data, int role = Qt::EditRole) |
Detailed Description
The proxy supports source models that have a tree structure. It also supports editing, and propagating changes from the source model. Row insertion/removal, column insertion/removal in the source model are supported.
Not supported: adding/removing extra columns at runtime; having a different number of columns in subtrees; drag-n-drop support in the extra columns; moving columns.
Derive from KExtraColumnsProxyModel, call appendColumn() (typically in the constructor) for each extra column, and reimplement extraColumnData() to allow KExtraColumnsProxyModel to retrieve the data to show in the extra columns.
If you want your new column(s) to be somewhere else than at the right of the existing columns, you can use a KRearrangeColumnsProxyModel on top.
Author: David Faure, KDAB
Member Function Documentation
[explicit]
KExtraColumnsProxyModel::KExtraColumnsProxyModel(QObject *parent = nullptr)
Base class constructor. Remember to call setSourceModel afterwards, and appendColumn.
[override virtual noexcept]
KExtraColumnsProxyModel::~KExtraColumnsProxyModel()
Destructor.
void KExtraColumnsProxyModel::appendColumn(const QString &header = QString())
Appends an extra column. header an optional text for the horizontal header This does not emit any signals - do it in the initial setup phase
[pure virtual]
QVariant KExtraColumnsProxyModel::extraColumnData(const QModelIndex &parent, int row, int extraColumn, int role = Qt::DisplayRole) const
This method is called by data() for extra columns. Reimplement this method to return the data for the extra columns.
parent the parent model index in the proxy model (only useful in tree models) row the row number for which the proxy model is querying for data (child of parent, if set) extraColumn the number of the extra column, starting at 0 (this doesn't require knowing how many columns the source model has) role the role being queried
Returns the data at row and extraColumn
See also setExtraColumnData().
void KExtraColumnsProxyModel::extraColumnDataChanged(const QModelIndex &parent, int row, int extraColumn, const QList<int> &roles)
This method can be called by your derived class when the data in an extra column has changed. The use case is data that changes "by itself", unrelated to setData().
int KExtraColumnsProxyModel::extraColumnForProxyColumn(int proxyColumn) const
Returns the extra column number (0, 1, ...) for a given column number of the proxymodel. This basically means subtracting the amount of columns in the source model.
int KExtraColumnsProxyModel::proxyColumnForExtraColumn(int extraColumn) const
Returns the proxy column number for a given extra column number (starting at 0). This basically means adding the amount of columns in the source model.
[since 5.24]
void KExtraColumnsProxyModel::removeExtraColumn(int idx)
Removes an extra column. idx index of the extra column (starting from 0). This does not emit any signals - do it in the initial setup phase
This function was introduced in KDE Frameworks 5.24.
[virtual]
bool KExtraColumnsProxyModel::setExtraColumnData(const QModelIndex &parent, int row, int extraColumn, const QVariant &data, int role = Qt::EditRole)
This method is called by setData() for extra columns. Reimplement this method to set the data for the extra columns, if editing is supported. Remember to call extraColumnDataChanged() after changing the data storage. The default implementation returns false.
See also extraColumnData().