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 | if (!d->expressionQueue.isEmpty()) | ||||
89 | d->needUpdate |= !d->expressionQueue.takeFirst()->isInternal(); | ||||
90 | | ||||
91 | if (d->expressionQueue.isEmpty()) | ||||
92 | if (d->variableModel && d->needUpdate) | ||||
93 | { | ||||
94 | d->variableModel->update(); | ||||
95 | d->needUpdate = false; | ||||
96 | } | ||||
97 | else | ||||
98 | changeStatus(Done); | ||||
99 | else | ||||
100 | runFirstExpression(); | ||||
101 | } | ||||
102 | | ||||
77 | Backend* Session::backend() | 103 | Backend* Session::backend() | ||
78 | { | 104 | { | ||
79 | return d->backend; | 105 | return d->backend; | ||
80 | } | 106 | } | ||
81 | 107 | | |||
82 | Cantor::Session::Status Session::status() | 108 | Cantor::Session::Status Session::status() | ||
83 | { | 109 | { | ||
84 | return d->status; | 110 | return d->status; | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
128 | } | 154 | } | ||
129 | 155 | | |||
130 | QSyntaxHighlighter* Session::syntaxHighlighter(QObject* parent) | 156 | QSyntaxHighlighter* Session::syntaxHighlighter(QObject* parent) | ||
131 | { | 157 | { | ||
132 | Q_UNUSED(parent); | 158 | Q_UNUSED(parent); | ||
133 | return nullptr; | 159 | return nullptr; | ||
134 | } | 160 | } | ||
135 | 161 | | |||
136 | QAbstractItemModel* Session::variableModel() | 162 | DefaultVariableModel* Session::variableModel() const | ||
137 | { | 163 | { | ||
138 | //Return 0 per default, so Backends not offering variable management don't | 164 | //Return deafult session model per default | ||
165 | //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 | 166 | //have to reimplement this. This method should only be called on backends with | ||
140 | //VariableManagement Capability flag | 167 | //VariableManagement Capability flag | ||
141 | return nullptr; | 168 | return d->variableModel; | ||
169 | } | ||||
170 | | ||||
171 | QAbstractItemModel* Session::variableDataModel() const | ||||
172 | { | ||||
173 | return variableModel(); | ||||
174 | } | ||||
175 | | ||||
176 | void Session::updateVariables() | ||||
177 | { | ||||
178 | if (d->variableModel) | ||||
179 | { | ||||
180 | d->variableModel->update(); | ||||
181 | d->needUpdate = false; | ||||
182 | } | ||||
183 | } | ||||
184 | | ||||
185 | void Cantor::Session::setVariableModel(Cantor::DefaultVariableModel* model) | ||||
186 | { | ||||
187 | d->variableModel = model; | ||||
142 | } | 188 | } | ||
143 | 189 | | |||
144 | int Session::nextExpressionId() | 190 | int Session::nextExpressionId() | ||
145 | { | 191 | { | ||
146 | return d->expressionCount++; | 192 | return d->expressionCount++; | ||
147 | } | 193 | } |
whitespace?