File indexing completed on 2024-12-22 05:15:23
0001 /* SPDX-FileCopyrightText: 2023 Noah Davis <noahadvs@gmail.com> 0002 * SPDX-FileCopyrightText: 2023 Tanbir Jishan <tantalising007@gmail.com> 0003 * SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #pragma once 0007 0008 #include <QAbstractListModel> 0009 0010 class SectionsModel : public QAbstractListModel 0011 { 0012 Q_OBJECT 0013 // Constant because we rely on sectionsChanged in AbstractModel 0014 Q_PROPERTY(int count READ rowCount CONSTANT FINAL) 0015 public: 0016 SectionsModel(QObject *parent = nullptr); 0017 0018 enum { 0019 FirstIndexRole = Qt::UserRole + 1, 0020 }; 0021 0022 QHash<int, QByteArray> roleNames() const override; 0023 QVariant data(const QModelIndex &index, int role) const override; 0024 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0025 0026 QString lastSection() const; 0027 // Not using standard QAbstractItemModel functions for these to keep them from being exposed to QML. 0028 void clear(); 0029 void append(const QString §ion, int firstIndex); 0030 0031 private: 0032 struct Item { 0033 QString section; 0034 int firstIndex; 0035 }; 0036 0037 QList<Item> m_data; 0038 QHash<int, QByteArray> m_roleNames; 0039 };