File indexing completed on 2024-05-19 16:17:12
0001 // SPDX-FileCopyrightText: 2023 Mathis BrĂ¼chert <mbb@kaidan.im> 0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0003 0004 #ifndef NOTESMODEL_H 0005 #define NOTESMODEL_H 0006 0007 #include <QAbstractListModel> 0008 #include <QDir> 0009 class NotesModel : public QAbstractListModel 0010 { 0011 Q_OBJECT 0012 0013 Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged REQUIRED) 0014 0015 public: 0016 enum Role { Path = Qt::UserRole + 1, Date, Name }; 0017 Q_ENUM(Role) 0018 0019 explicit NotesModel(QObject *parent = nullptr); 0020 0021 int rowCount(const QModelIndex &index) const override; 0022 0023 QVariant data(const QModelIndex &index, int role) const override; 0024 0025 QHash<int, QByteArray> roleNames() const override; 0026 0027 Q_INVOKABLE void addNote(const QString &name); 0028 0029 Q_INVOKABLE void deleteNote(const QUrl &path); 0030 0031 Q_INVOKABLE void renameNote(const QUrl &path, const QString &name); 0032 0033 Q_SIGNAL void pathChanged(); 0034 0035 QString path() const; 0036 void setPath(const QString &newPath); 0037 0038 private: 0039 QDir directory; 0040 QString m_path; 0041 }; 0042 0043 #endif // NOTESMODEL_H