blob: 1f5605683e39bc1fadb26759b244cb9bdb4499cb [file] [log] [blame]
swissChili4b3105a2022-02-22 16:34:39 -08001#pragma once
2
3#include <QAbstractListModel>
4#include <qqml.h>
5
swissChili25620b02022-02-23 17:15:16 -08006#include "Notebook.h"
swissChili4b3105a2022-02-22 16:34:39 -08007#include "Cell.h"
8
9class CellModel : public QAbstractListModel
10{
11 Q_OBJECT
swissChili4b3105a2022-02-22 16:34:39 -080012
13public:
swissChili25620b02022-02-23 17:15:16 -080014 explicit CellModel(Notebook *parent = nullptr);
15 CellModel(const CellModel &other);
swissChili4b3105a2022-02-22 16:34:39 -080016
17 enum CellRoles
18 {
19 CodeRole = Qt::UserRole + 1,
swissChilid85daa92022-02-24 15:29:02 -080020 ResultRole,
21 UuidRole,
22 StatusRole,
swissChili4b3105a2022-02-22 16:34:39 -080023 };
24
25 // Basic functionality:
26 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
27
28 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
29
30 // Editable:
31 Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value,
32 int role = Qt::EditRole) override;
33
34 Qt::ItemFlags flags(const QModelIndex& index) const override;
35
36 // Add data:
37 Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
38
39 // Remove data:
40 Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
41
42 QHash<int, QByteArray> roleNames() const override;
43
44 Q_INVOKABLE void addCell(const Cell &cell);
45 Q_INVOKABLE void addCell(QString code, QString result);
46
47private:
swissChili25620b02022-02-23 17:15:16 -080048 Notebook *_notebook;
swissChilid85daa92022-02-24 15:29:02 -080049 void announceCellChange(Cell *cell, int role);
swissChili4b3105a2022-02-22 16:34:39 -080050};
51
52Q_DECLARE_METATYPE(CellModel)
swissChili25620b02022-02-23 17:15:16 -080053Q_DECLARE_METATYPE(CellModel *)