File indexing completed on 2024-05-12 15:42:57

0001 /*
0002     SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KCOLUMNHEADERSMODEL_H
0008 #define KCOLUMNHEADERSMODEL_H
0009 
0010 #include "kitemmodels_export.h"
0011 
0012 #include <QAbstractListModel>
0013 
0014 #include <memory>
0015 
0016 class KColumnHeadersModelPrivate;
0017 
0018 /**
0019  * A model that converts a model's headers into a list model.
0020  *
0021  * This model will expose the source model's headers as a simple list. This is
0022  * mostly useful as a helper for QML applications that want to display a model's
0023  * headers.
0024  *
0025  * Each columns's header will be presented as a row in this model. Roles are
0026  * forwarded directly to the source model's headerData() method.
0027  *
0028  * @since 5.66
0029  */
0030 class KITEMMODELS_EXPORT KColumnHeadersModel : public QAbstractListModel
0031 {
0032     Q_OBJECT
0033     Q_PROPERTY(QAbstractItemModel *sourceModel READ sourceModel WRITE setSourceModel NOTIFY sourceModelChanged)
0034 
0035 public:
0036     explicit KColumnHeadersModel(QObject *parent = nullptr);
0037     ~KColumnHeadersModel() override;
0038 
0039     int rowCount(const QModelIndex &parent = QModelIndex()) const override;
0040     QVariant data(const QModelIndex &index, int role) const override;
0041     QHash<int, QByteArray> roleNames() const override;
0042 
0043     QAbstractItemModel *sourceModel() const;
0044     void setSourceModel(QAbstractItemModel *newSourceModel);
0045 
0046 Q_SIGNALS:
0047     void sourceModelChanged();
0048 
0049 private:
0050     const std::unique_ptr<KColumnHeadersModelPrivate> d;
0051 };
0052 
0053 #endif