File indexing completed on 2024-12-29 05:06:04
0001 // SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org> 0002 // SPDX-License-Identifier: GPL-2.0-or-later 0003 0004 #pragma once 0005 0006 #include "pagemodel.h" 0007 0008 #include <QAbstractListModel> 0009 #include <QList> 0010 0011 #include <Plasma/Containment> 0012 0013 class PageListModel : public QAbstractListModel 0014 { 0015 Q_OBJECT 0016 Q_PROPERTY(int length READ length NOTIFY lengthChanged) 0017 0018 public: 0019 enum Roles { PageRole = Qt::UserRole + 1 }; 0020 0021 PageListModel(QObject *parent = nullptr); 0022 0023 static PageListModel *self(); 0024 0025 int rowCount(const QModelIndex &parent = QModelIndex()) const override; 0026 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 0027 QHash<int, QByteArray> roleNames() const override; 0028 0029 int length(); 0030 0031 PageModel *getPage(int index); 0032 void removePage(int index); 0033 Q_INVOKABLE void addPageAtEnd(); 0034 bool isLastPageEmpty(); 0035 0036 QJsonArray exportToJson(); 0037 void save(); 0038 Q_INVOKABLE void load(); 0039 void loadFromJson(QJsonArray arr); 0040 0041 void setContainment(Plasma::Containment *containment); 0042 0043 Q_SIGNALS: 0044 void lengthChanged(); 0045 0046 private: 0047 QList<PageModel *> m_pages; 0048 0049 Plasma::Containment *m_containment{nullptr}; 0050 };