blob: 345454a00d6d175c24fee0bed4ace4570f1e88ed [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,
swissChiliece1ac82022-02-25 11:20:42 -080024 ResultTypeRole,
swissChili4b3105a2022-02-22 16:34:39 -080025 };
26
27 // Basic functionality:
28 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
29
30 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
31
32 // Editable:
33 Q_INVOKABLE bool setData(const QModelIndex &index, const QVariant &value,
34 int role = Qt::EditRole) override;
35
36 Qt::ItemFlags flags(const QModelIndex& index) const override;
37
38 // Add data:
39 Q_INVOKABLE bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
40
41 // Remove data:
42 Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
43
44 QHash<int, QByteArray> roleNames() const override;
45
46 Q_INVOKABLE void addCell(const Cell &cell);
47 Q_INVOKABLE void addCell(QString code, QString result);
48
swissChili5d3e5562022-02-24 16:49:19 -080049 Q_INVOKABLE void insertCellBefore(int index);
swissChili06cec4e2022-02-24 19:04:32 -080050 Q_INVOKABLE void deleteCellAt(int index);
swissChili5d3e5562022-02-24 16:49:19 -080051
swissChili4b3105a2022-02-22 16:34:39 -080052private:
swissChili25620b02022-02-23 17:15:16 -080053 Notebook *_notebook;
swissChilid85daa92022-02-24 15:29:02 -080054 void announceCellChange(Cell *cell, int role);
swissChili4b3105a2022-02-22 16:34:39 -080055};
56
57Q_DECLARE_METATYPE(CellModel)
swissChili25620b02022-02-23 17:15:16 -080058Q_DECLARE_METATYPE(CellModel *)