File indexing completed on 2022-09-27 16:37:29

0001 // SPDX-FileCopyrightText: 2022 Felipe Kinoshita <kinofhek@gmail.com>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003 
0004 #pragma once
0005 
0006 #include <QAbstractListModel>
0007 #include <QJsonObject>
0008 
0009 #include "task.h"
0010 
0011 class TasksModel : public QAbstractListModel
0012 {
0013     Q_OBJECT
0014 
0015 public:
0016     enum Roles {
0017         TitleRole = Qt::UserRole + 1,
0018         CheckedRole
0019     };
0020 
0021     explicit TasksModel(QObject *parent = nullptr);
0022 
0023     QHash<int, QByteArray> roleNames() const override;
0024     QVariant data(const QModelIndex &index, int role) const override;
0025     int rowCount(const QModelIndex &parent) const final;
0026     bool setData(const QModelIndex &index, const QVariant &value, int role) override;
0027 
0028     Q_INVOKABLE void add(const QString &title);
0029     Q_INVOKABLE void remove(const int &index);
0030     Q_INVOKABLE void clear();
0031 
0032 protected:
0033     bool saveTasks() const;
0034     bool loadTasks();
0035 
0036 private:
0037     QList<Task> m_tasks;
0038 };