swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 1 | #include "Notebook.h" |
| 2 | #include "CellModel.h" |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame^] | 3 | #include "../PPrint.h" |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 4 | |
| 5 | Notebook::Notebook(QObject *parent) |
| 6 | : QObject(parent) |
| 7 | , _cellModel(new CellModel(this)) |
| 8 | { |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame^] | 9 | connect(&_rt, &NbRuntime::cellFailedToParse, this, &Notebook::cellFailedToParse); |
| 10 | connect(&_rt, &NbRuntime::cellFinishedRunning, this, &Notebook::cellFinishedRunning); |
| 11 | connect(&_rt, &NbRuntime::cellQuit, this, &Notebook::cellQuit); |
| 12 | connect(&_rt, &NbRuntime::cellRunning, this, &Notebook::cellRunning); |
| 13 | connect(&_rt, &NbRuntime::cellWaiting, this, &Notebook::cellWaiting); |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 14 | |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame^] | 15 | _rt.start(); |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 16 | } |
| 17 | |
| 18 | Notebook::Notebook(const Notebook &other, QObject *parent) |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame^] | 19 | : Notebook(parent) |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 20 | { |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame^] | 21 | for (const Cell *cell : other._cells) |
| 22 | { |
| 23 | _cells.append(new Cell(*cell, this)); |
| 24 | } |
swissChili | 25620b0 | 2022-02-23 17:15:16 -0800 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | CellModel *Notebook::cellModel() |
| 28 | { |
| 29 | return _cellModel; |
| 30 | } |
swissChili | d85daa9 | 2022-02-24 15:29:02 -0800 | [diff] [blame^] | 31 | |
| 32 | void Notebook::runCell(QUuid uuid) |
| 33 | { |
| 34 | qInfo() << "Running cell" << uuid; |
| 35 | _rt.queueCell(Cell::cellFromUuid(uuid)); |
| 36 | } |
| 37 | |
| 38 | void Notebook::quitCell(QUuid uuid) |
| 39 | { |
| 40 | _rt.unqueueCell(Cell::cellFromUuid(uuid)); |
| 41 | } |
| 42 | |
| 43 | void Notebook::cellFinishedRunning(Cell *cell, RuntimeResult result) |
| 44 | { |
| 45 | qInfo() << "cellFinishedRunning" << cell->uuid() << pprint(result); |
| 46 | cell->setResult(pprint(result)); |
| 47 | cell->setStatus(Cell::IDLE); |
| 48 | } |
| 49 | |
| 50 | void Notebook::cellFailedToParse(Cell *cell, ParseResult result) |
| 51 | { |
| 52 | qInfo() << "cellFailedToParse" << cell->uuid() << pprint(result); |
| 53 | cell->setResult(pprint(result)); |
| 54 | cell->setStatus(Cell::IDLE); |
| 55 | } |
| 56 | |
| 57 | void Notebook::cellWaiting(Cell *cell) |
| 58 | { |
| 59 | qInfo() << "cellWaiting" << cell->uuid(); |
| 60 | cell->setStatus(Cell::WAITING); |
| 61 | } |
| 62 | |
| 63 | void Notebook::cellRunning(Cell *cell) |
| 64 | { |
| 65 | qInfo() << "cellRunning" << cell->uuid(); |
| 66 | cell->setStatus(Cell::RUNNING); |
| 67 | } |
| 68 | |
| 69 | void Notebook::cellQuit(Cell *cell) |
| 70 | { |
| 71 | qInfo() << "cellQuit" << cell->uuid(); |
| 72 | cell->setResult(""); |
| 73 | cell->setStatus(Cell::IDLE); |
| 74 | } |