Changeset View
Changeset View
Standalone View
Standalone View
src/lib/session.cpp
Show All 16 Lines | 1 | /* | |||
---|---|---|---|---|---|
17 | --- | 17 | --- | ||
18 | Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com> | 18 | Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com> | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "session.h" | 21 | #include "session.h" | ||
22 | using namespace Cantor; | 22 | using namespace Cantor; | ||
23 | 23 | | |||
24 | #include "backend.h" | 24 | #include "backend.h" | ||
25 | #include "defaultvariablemodel.h" | ||||
25 | 26 | | |||
26 | #include <QTimer> | 27 | #include <QTimer> | ||
27 | #include <QQueue> | 28 | #include <QQueue> | ||
28 | 29 | | |||
29 | class Cantor::SessionPrivate | 30 | class Cantor::SessionPrivate | ||
30 | { | 31 | { | ||
31 | public: | 32 | public: | ||
32 | SessionPrivate() : backend(nullptr), status(Session::Disable), typesettingEnabled(false), expressionCount(0) | 33 | SessionPrivate() : backend(nullptr), status(Session::Disable), typesettingEnabled(false), expressionCount(0), variableModel(nullptr), needUpdate(false) | ||
33 | { | 34 | { | ||
34 | } | 35 | } | ||
35 | 36 | | |||
36 | Backend* backend; | 37 | Backend* backend; | ||
37 | Session::Status status; | 38 | Session::Status status; | ||
38 | bool typesettingEnabled; | 39 | bool typesettingEnabled; | ||
39 | int expressionCount; | 40 | int expressionCount; | ||
40 | QList<Cantor::Expression*> expressionQueue; | 41 | QList<Cantor::Expression*> expressionQueue; | ||
42 | DefaultVariableModel* variableModel; | ||||
43 | bool needUpdate; | ||||
41 | }; | 44 | }; | ||
42 | 45 | | |||
43 | Session::Session( Backend* backend ) : QObject(backend), d(new SessionPrivate) | 46 | Session::Session( Backend* backend ) : QObject(backend), d(new SessionPrivate) | ||
44 | { | 47 | { | ||
45 | d->backend=backend; | 48 | d->backend=backend; | ||
46 | } | 49 | } | ||
47 | 50 | | |||
51 | Session::Session( Backend* backend, DefaultVariableModel* model) : QObject(backend), d(new SessionPrivate) | ||||
52 | { | ||||
53 | d->backend=backend; | ||||
54 | d->variableModel=model; | ||||
55 | } | ||||
asemke: whitespace? | |||||
56 | | ||||
asemke: whitespace? | |||||
48 | Session::~Session() | 57 | Session::~Session() | ||
49 | { | 58 | { | ||
50 | delete d; | 59 | delete d; | ||
51 | } | 60 | } | ||
52 | 61 | | |||
53 | QList<Expression*>& Cantor::Session::expressionQueue() const | 62 | QList<Expression*>& Cantor::Session::expressionQueue() const | ||
54 | { | 63 | { | ||
55 | return d->expressionQueue; | 64 | return d->expressionQueue; | ||
Show All 13 Lines | 77 | else | |||
69 | expr->setStatus(Cantor::Expression::Queued); | 78 | expr->setStatus(Cantor::Expression::Queued); | ||
70 | } | 79 | } | ||
71 | 80 | | |||
72 | void Session::runFirstExpression() | 81 | void Session::runFirstExpression() | ||
73 | { | 82 | { | ||
74 | 83 | | |||
75 | } | 84 | } | ||
76 | 85 | | |||
86 | void Session::finishFirstExpression() | ||||
87 | { | ||||
88 | d->needUpdate |= !d->expressionQueue.takeFirst()->isInternal(); | ||||
89 | if (d->expressionQueue.isEmpty()) | ||||
90 | if (d->variableModel && d->needUpdate) | ||||
91 | { | ||||
92 | d->variableModel->update(); | ||||
93 | d->needUpdate = false; | ||||
94 | } | ||||
95 | else | ||||
96 | changeStatus(Done); | ||||
97 | else | ||||
98 | runFirstExpression(); | ||||
99 | } | ||||
100 | | ||||
77 | Backend* Session::backend() | 101 | Backend* Session::backend() | ||
78 | { | 102 | { | ||
79 | return d->backend; | 103 | return d->backend; | ||
80 | } | 104 | } | ||
81 | 105 | | |||
82 | Cantor::Session::Status Session::status() | 106 | Cantor::Session::Status Session::status() | ||
83 | { | 107 | { | ||
84 | return d->status; | 108 | return d->status; | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | |||||
130 | QSyntaxHighlighter* Session::syntaxHighlighter(QObject* parent) | 154 | QSyntaxHighlighter* Session::syntaxHighlighter(QObject* parent) | ||
131 | { | 155 | { | ||
132 | Q_UNUSED(parent); | 156 | Q_UNUSED(parent); | ||
133 | return nullptr; | 157 | return nullptr; | ||
134 | } | 158 | } | ||
135 | 159 | | |||
136 | QAbstractItemModel* Session::variableModel() | 160 | QAbstractItemModel* Session::variableModel() | ||
137 | { | 161 | { | ||
138 | //Return 0 per default, so Backends not offering variable management don't | 162 | //Return deafult session model per default | ||
163 | //By default, variableModel is nullptr, so Backends not offering variable management don't | ||||
139 | //have to reimplement this. This method should only be called on backends with | 164 | //have to reimplement this. This method should only be called on backends with | ||
140 | //VariableManagement Capability flag | 165 | //VariableManagement Capability flag | ||
141 | return nullptr; | 166 | return d->variableModel; | ||
167 | } | ||||
168 | | ||||
169 | void Session::forceVariableUpdate() | ||||
170 | { | ||||
171 | if (d->variableModel) | ||||
172 | { | ||||
173 | d->variableModel->update(); | ||||
174 | d->needUpdate = false; | ||||
175 | } | ||||
142 | } | 176 | } | ||
143 | 177 | | |||
144 | int Session::nextExpressionId() | 178 | int Session::nextExpressionId() | ||
145 | { | 179 | { | ||
146 | return d->expressionCount++; | 180 | return d->expressionCount++; | ||
147 | } | 181 | } |
whitespace?