swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <QAbstractListModel> |
| 4 | #include <qqml.h> |
| 5 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 6 | #include "Notebook.h" |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 7 | #include "Cell.h" |
| 8 | |
| 9 | class CellModel : public QAbstractListModel |
| 10 | { |
| 11 | Q_OBJECT |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 12 | |
| 13 | public: |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 14 | explicit CellModel(Notebook *parent = nullptr); |
| 15 | CellModel(const CellModel &other); |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 16 | |
| 17 | enum CellRoles |
| 18 | { |
| 19 | CodeRole = Qt::UserRole + 1, |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame^] | 20 | ResultRole, |
| 21 | UuidRole, |
| 22 | StatusRole, |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 23 | }; |
| 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 | |
| 47 | private: |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 48 | Notebook *_notebook; |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame^] | 49 | void announceCellChange(Cell *cell, int role); |
swissChili | 4b3105a | 2022-02-22 16:34:39 -0800 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | Q_DECLARE_METATYPE(CellModel) |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 53 | Q_DECLARE_METATYPE(CellModel *) |