blob: 46f3628412b4271fb4232ad633112dc755ecfc34 [file] [log] [blame]
swissChili4b3105a2022-02-22 16:34:39 -08001#pragma once
2
3#include <QAbstractListModel>
4#include <qqml.h>
5
6#include "Cell.h"
7
swissChilie386bc72022-02-24 21:31:31 -08008class Notebook;
9
swissChili4b3105a2022-02-22 16:34:39 -080010class CellModel : public QAbstractListModel
11{
12 Q_OBJECT
swissChili4b3105a2022-02-22 16:34:39 -080013
14public:
swissChili25620b02022-02-23 17:15:16 -080015 explicit CellModel(Notebook *parent = nullptr);
16 CellModel(const CellModel &other);
swissChili4b3105a2022-02-22 16:34:39 -080017
18 enum CellRoles
19 {
20 CodeRole = Qt::UserRole + 1,
swissChilid85daa92022-02-24 15:29:02 -080021 ResultRole,
22 UuidRole,
23 StatusRole,
swissChili4b3105a2022-02-22 16:34:39 -080024 };
25
26 // Basic functionality:
27 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
28
29 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
30
31 // Editable:
32 Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value,
33 int role = Qt::EditRole) override;
34
35 Qt::ItemFlags flags(const QModelIndex& index) const override;
36
37 // Add data:
38 Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
39
40 // Remove data:
41 Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
42
43 QHash<int, QByteArray> roleNames() const override;
44
45 Q_INVOKABLE void addCell(const Cell &cell);
46 Q_INVOKABLE void addCell(QString code, QString result);
47
swissChili5d3e5562022-02-24 16:49:19 -080048 Q_INVOKABLE void insertCellBefore(int index);
swissChili06cec4e2022-02-24 19:04:32 -080049 Q_INVOKABLE void deleteCellAt(int index);
swissChili5d3e5562022-02-24 16:49:19 -080050
swissChili4b3105a2022-02-22 16:34:39 -080051private:
swissChili25620b02022-02-23 17:15:16 -080052 Notebook *_notebook;
swissChilid85daa92022-02-24 15:29:02 -080053 void announceCellChange(Cell *cell, int role);
swissChili4b3105a2022-02-22 16:34:39 -080054};
55
56Q_DECLARE_METATYPE(CellModel)
swissChili25620b02022-02-23 17:15:16 -080057Q_DECLARE_METATYPE(CellModel *)