File indexing completed on 2024-10-06 03:31:32

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: GPL-2.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <KNSCore/Entry>
0007 #include <QAbstractListModel>
0008 #include <keduvocdocument.h>
0009 
0010 /// @author Carl Schwan <carl@carlschwan.eu>
0011 class KWQDocumentModel : public QAbstractListModel
0012 {
0013     Q_OBJECT
0014 
0015 public:
0016     enum ExtraRoles {
0017         TitleRole = Qt::UserRole + 1,
0018         UrlRole,
0019         DocumentRole,
0020     };
0021 
0022     explicit KWQDocumentModel(QObject *parent = nullptr);
0023     ~KWQDocumentModel();
0024 
0025     int rowCount(const QModelIndex &parent = {}) const override;
0026     QVariant data(const QModelIndex &index, int role) const override;
0027     QHash<int, QByteArray> roleNames() const override;
0028 
0029     void load();
0030     void save() const;
0031 
0032     Q_INVOKABLE int add(const QUrl &url);
0033     Q_INVOKABLE void add(KEduVocDocument *document);
0034     Q_INVOKABLE void remove(const int row);
0035 
0036     Q_INVOKABLE void entryChanged(const KNSCore::Entry &wrapper);
0037 
0038 private:
0039     std::vector<std::unique_ptr<KEduVocDocument>> m_documents;
0040 };