blob: 83f9fc7e04234495ba84e82b087b79b9284d2765 [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);
swissChilia44bf722022-04-16 18:41:54 -070028 Q_INVOKABLE void runAll();
29 Q_INVOKABLE void reset();
swissChilid85daa92022-02-24 15:29:02 -080030
swissChilid2af6ad2022-04-16 14:42:17 -070031 Q_INVOKABLE void fromJson(QJsonDocument doc);
32 Q_INVOKABLE void open(QString path);
33
swissChili505de412022-03-24 12:35:08 -070034 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
swissChili25620b02022-02-23 17:15:16 -080042signals:
43 void cellModelChanged();
swissChili505de412022-03-24 12:35:08 -070044 void saveError(QString message);
45 void savePathChanged(QString savePath);
swissChilia44bf722022-04-16 18:41:54 -070046 void saved();
swissChili25620b02022-02-23 17:15:16 -080047
swissChilid85daa92022-02-24 15:29:02 -080048protected slots:
49 void cellFinishedRunning(Cell *cell, RuntimeResult result);
swissChiliece1ac82022-02-25 11:20:42 -080050 void cellFailedToParse(Cell *cell, ParseResult result, Parser parser);
swissChilid85daa92022-02-24 15:29:02 -080051 void cellWaiting(Cell *cell);
52 void cellRunning(Cell *cell);
53 void cellQuit(Cell *cell);
54
swissChili25620b02022-02-23 17:15:16 -080055protected:
56 friend class CellModel;
57
swissChilid85daa92022-02-24 15:29:02 -080058 QList<Cell *> _cells;
swissChili25620b02022-02-23 17:15:16 -080059 CellModel *_cellModel;
swissChili732628e2022-02-25 10:35:56 -080060 QThread *_rtThread;
swissChiliece1ac82022-02-25 11:20:42 -080061 NbRuntime *_rt;
swissChili505de412022-03-24 12:35:08 -070062 QString _savePath = "";
swissChilia44bf722022-04-16 18:41:54 -070063 bool _runningAll = false;
swissChili25620b02022-02-23 17:15:16 -080064};
65
66Q_DECLARE_METATYPE(Notebook)