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