KItemModels

kcolumnheadersmodel.h
1/*
2 SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KCOLUMNHEADERSMODEL_H
8#define KCOLUMNHEADERSMODEL_H
9
10#include "kitemmodels_export.h"
11
12#include <QAbstractListModel>
13
14#include <memory>
15
16class KColumnHeadersModelPrivate;
17
18/**
19 * A model that converts a model's headers into a list model.
20 *
21 * This model will expose the source model's headers as a simple list. This is
22 * mostly useful as a helper for QML applications that want to display a model's
23 * headers.
24 *
25 * Each columns's header will be presented as a row in this model. Roles are
26 * forwarded directly to the source model's headerData() method.
27 *
28 * @since 5.66
29 */
30class KITEMMODELS_EXPORT KColumnHeadersModel : public QAbstractListModel
31{
32 Q_OBJECT
33 Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
34 Q_PROPERTY(int sortColumn READ sortColumn WRITE setSortColumn NOTIFY sortColumnChanged)
35 Q_PROPERTY(Qt::SortOrder sortOrder READ sortOrder WRITE setSortOrder NOTIFY sortOrderChanged)
36
37public:
38 enum ExtraRoles { SortRole = 0x011D910E };
39 Q_ENUM(ExtraRoles)
40
41 explicit KColumnHeadersModel(QObject *parent = nullptr);
42 ~KColumnHeadersModel() override;
43
44 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
45 QVariant data(const QModelIndex &index, int role) const override;
46 QHash<int, QByteArray> roleNames() const override;
47
48 QAbstractItemModel *sourceModel() const;
49 void setSourceModel(QAbstractItemModel *newSourceModel);
50
51 int sortColumn() const;
52 void setSortColumn(int newSortColumn);
53
54 Qt::SortOrder sortOrder() const;
55 void setSortOrder(Qt::SortOrder newSortOrder);
56
58 void sourceModelChanged();
59 void sortColumnChanged();
60 void sortOrderChanged();
61
62private:
63 void onLayoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
64 void onLayoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint);
65
66 const std::unique_ptr<KColumnHeadersModelPrivate> d;
67};
68
69#endif
A model that converts a model's headers into a list model.
virtual QVariant data(const QModelIndex &index, int role) const const=0
virtual QHash< int, QByteArray > roleNames() const const
virtual int rowCount(const QModelIndex &parent) const const=0
Q_ENUM(...)
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
SortOrder
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:18:35 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.