KItemModels

krearrangecolumnsproxymodel.h
1/*
2 SPDX-FileCopyrightText: 2015 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
3 SPDX-FileContributor: David Faure <david.faure@kdab.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef REARRANGECOLUMNSPROXYMODEL_H
9#define REARRANGECOLUMNSPROXYMODEL_H
10
11#include "kitemmodels_export.h"
12
13#include <QIdentityProxyModel>
14
15#include <memory>
16
17class KRearrangeColumnsProxyModelPrivate;
18
19/**
20 * @class KRearrangeColumnsProxyModel krearrangecolumnsproxymodel.h KRearrangeColumnsProxyModel
21 *
22 * This proxy shows specific columns from the source model, in any order.
23 * This allows to reorder columns, as well as not showing all of them.
24 *
25 * The proxy supports source models that have a tree structure.
26 * It also supports editing, and propagating changes from the source model.
27 *
28 * Showing the same source column more than once is not supported.
29 *
30 * Author: David Faure, KDAB
31 * @since 5.12
32 */
33class KITEMMODELS_EXPORT KRearrangeColumnsProxyModel : public QIdentityProxyModel
34{
35 Q_OBJECT
36public:
37 /**
38 * Creates a KRearrangeColumnsProxyModel proxy.
39 * Remember to call setSourceModel afterwards.
40 */
41 explicit KRearrangeColumnsProxyModel(QObject *parent = nullptr);
42 /**
43 * Destructor.
44 */
46
47 // API
48
49 /**
50 * Set the chosen source columns, in the desired order for the proxy columns
51 * columns[proxyColumn=0] is the source column to show in the first proxy column, etc.
52 *
53 * Example: QList<int>() << 2 << 1;
54 * This examples configures the proxy to hide column 0, show column 2 from the source model,
55 * then show column 1 from the source model.
56 */
57 void setSourceColumns(const QList<int> &columns);
58
59 // Implementation
60
61 /// @reimp
62 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
63 /// @reimp
64 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
65
66 /// @reimp
67 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
68 /// @reimp
69 QModelIndex parent(const QModelIndex &child) const override;
70
71 /// @reimp
72 QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
73 /// @reimp
74 QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
75
76 /// @reimp
77 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
78
79 /// @reimp
80 bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
81
82 /// @reimp
83 QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
84
85 /**
86 * Returns the proxy column for the given source column
87 * or -1 if the source column isn't shown in the proxy.
88 * @since 5.56
89 */
90 int proxyColumnForSourceColumn(int sourceColumn) const;
91
92 /**
93 * Returns the source column for the given proxy column.
94 * @since 5.56
95 */
96 int sourceColumnForProxyColumn(int proxyColumn) const;
97
98private:
99 std::unique_ptr<KRearrangeColumnsProxyModelPrivate> const d_ptr;
100};
101
102#endif
This proxy shows specific columns from the source model, in any order.
virtual bool hasChildren(const QModelIndex &parent) const const override
virtual int columnCount(const QModelIndex &parent) const const override
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const const override
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
virtual QModelIndex mapFromSource(const QModelIndex &sourceIndex) const const override
virtual QModelIndex mapToSource(const QModelIndex &proxyIndex) const const override
virtual int rowCount(const QModelIndex &parent) const const override
virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const const override
QObject * parent() const const
DisplayRole
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.