swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <QObject> |
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame] | 4 | #include <QJsonDocument> |
| 5 | #include <QFile> |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 6 | |
| 7 | #include "Cell.h" |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 8 | #include "NbRuntime.h" |
swissChili | e386bc7 | 2022-02-24 21:31:31 -0800 | [diff] [blame] | 9 | #include "CellModel.h" |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 10 | |
| 11 | class Notebook : public QObject |
| 12 | { |
| 13 | Q_OBJECT |
| 14 | QML_ELEMENT |
| 15 | |
| 16 | Q_PROPERTY(CellModel *cellModel READ cellModel NOTIFY cellModelChanged) |
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame] | 17 | Q_PROPERTY(QString savePath READ savePath WRITE setSavePath NOTIFY savePathChanged) |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 18 | |
| 19 | public: |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 20 | ~Notebook(); |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 21 | explicit Notebook(QObject *parent = nullptr); |
| 22 | Notebook(const Notebook &other, QObject *parent = nullptr); |
| 23 | |
| 24 | CellModel *cellModel(); |
| 25 | |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 26 | Q_INVOKABLE void runCell(QUuid uuid); |
| 27 | Q_INVOKABLE void quitCell(QUuid uuid); |
swissChili | a44bf72 | 2022-04-16 18:41:54 -0700 | [diff] [blame] | 28 | Q_INVOKABLE void runAll(); |
| 29 | Q_INVOKABLE void reset(); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 30 | |
swissChili | d2af6ad | 2022-04-16 14:42:17 -0700 | [diff] [blame] | 31 | Q_INVOKABLE void fromJson(QJsonDocument doc); |
| 32 | Q_INVOKABLE void open(QString path); |
| 33 | |
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame] | 34 | Q_INVOKABLE QJsonDocument toJson() const; |
| 35 | Q_INVOKABLE void save(); |
| 36 | |
| 37 | Q_INVOKABLE bool savePathSet(); |
| 38 | |
| 39 | QString savePath(); |
| 40 | void setSavePath(QString savePath); |
| 41 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 42 | signals: |
| 43 | void cellModelChanged(); |
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame] | 44 | void saveError(QString message); |
| 45 | void savePathChanged(QString savePath); |
swissChili | a44bf72 | 2022-04-16 18:41:54 -0700 | [diff] [blame] | 46 | void saved(); |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 47 | |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 48 | protected slots: |
| 49 | void cellFinishedRunning(Cell *cell, RuntimeResult result); |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 50 | void cellFailedToParse(Cell *cell, ParseResult result, Parser parser); |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 51 | void cellWaiting(Cell *cell); |
| 52 | void cellRunning(Cell *cell); |
| 53 | void cellQuit(Cell *cell); |
| 54 | |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 55 | protected: |
| 56 | friend class CellModel; |
| 57 | |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame] | 58 | QList<Cell *> _cells; |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 59 | CellModel *_cellModel; |
swissChili | 732628e | 2022-02-25 10:35:56 -0800 | [diff] [blame] | 60 | QThread *_rtThread; |
swissChili | ece1ac8 | 2022-02-25 11:20:42 -0800 | [diff] [blame] | 61 | NbRuntime *_rt; |
swissChili | 505de41 | 2022-03-24 12:35:08 -0700 | [diff] [blame] | 62 | QString _savePath = ""; |
swissChili | a44bf72 | 2022-04-16 18:41:54 -0700 | [diff] [blame] | 63 | bool _runningAll = false; |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | Q_DECLARE_METATYPE(Notebook) |