blob: 6a6541d289c4a41c24ef834afd6b9b50f9ac6fe1 [file] [log] [blame]
swissChili25620b02022-02-23 17:15:16 -08001#pragma once
2
3#include <QObject>
swissChili505de412022-03-24 12:35:08 -07004#include <QJsonDocument>
5#include <QFile>
swissChili25620b02022-02-23 17:15:16 -08006
7#include "Cell.h"
swissChilid85daa92022-02-24 15:29:02 -08008#include "NbRuntime.h"
swissChilie386bc72022-02-24 21:31:31 -08009#include "CellModel.h"
swissChili25620b02022-02-23 17:15:16 -080010
11class Notebook : public QObject
12{
13 Q_OBJECT
14 QML_ELEMENT
15
16 Q_PROPERTY(CellModel *cellModel READ cellModel NOTIFY cellModelChanged)
swissChili505de412022-03-24 12:35:08 -070017 Q_PROPERTY(QString savePath READ savePath WRITE setSavePath NOTIFY savePathChanged)
swissChili25620b02022-02-23 17:15:16 -080018
19public:
swissChili732628e2022-02-25 10:35:56 -080020 ~Notebook();
swissChili25620b02022-02-23 17:15:16 -080021 explicit Notebook(QObject *parent = nullptr);
22 Notebook(const Notebook &other, QObject *parent = nullptr);
23
24 CellModel *cellModel();
25
swissChilid85daa92022-02-24 15:29:02 -080026 Q_INVOKABLE void runCell(QUuid uuid);
27 Q_INVOKABLE void quitCell(QUuid uuid);
28
swissChilid2af6ad2022-04-16 14:42:17 -070029 Q_INVOKABLE void fromJson(QJsonDocument doc);
30 Q_INVOKABLE void open(QString path);
31
swissChili505de412022-03-24 12:35:08 -070032 Q_INVOKABLE QJsonDocument toJson() const;
33 Q_INVOKABLE void save();
34
35 Q_INVOKABLE bool savePathSet();
36
37 QString savePath();
38 void setSavePath(QString savePath);
39
swissChili25620b02022-02-23 17:15:16 -080040signals:
41 void cellModelChanged();
swissChili505de412022-03-24 12:35:08 -070042 void saveError(QString message);
43 void savePathChanged(QString savePath);
swissChili25620b02022-02-23 17:15:16 -080044
swissChilid85daa92022-02-24 15:29:02 -080045protected slots:
46 void cellFinishedRunning(Cell *cell, RuntimeResult result);
swissChiliece1ac82022-02-25 11:20:42 -080047 void cellFailedToParse(Cell *cell, ParseResult result, Parser parser);
swissChilid85daa92022-02-24 15:29:02 -080048 void cellWaiting(Cell *cell);
49 void cellRunning(Cell *cell);
50 void cellQuit(Cell *cell);
51
swissChili25620b02022-02-23 17:15:16 -080052protected:
53 friend class CellModel;
54
swissChilid85daa92022-02-24 15:29:02 -080055 QList<Cell *> _cells;
swissChili25620b02022-02-23 17:15:16 -080056 CellModel *_cellModel;
swissChili732628e2022-02-25 10:35:56 -080057 QThread *_rtThread;
swissChiliece1ac82022-02-25 11:20:42 -080058 NbRuntime *_rt;
swissChili505de412022-03-24 12:35:08 -070059 QString _savePath = "";
swissChili25620b02022-02-23 17:15:16 -080060};
61
62Q_DECLARE_METATYPE(Notebook)