Changeset View
Changeset View
Standalone View
Standalone View
src/backends/octave/octavesession.cpp
Show All 34 Lines | |||||
35 | 35 | | |||
36 | #include <QTimer> | 36 | #include <QTimer> | ||
37 | #include <QFile> | 37 | #include <QFile> | ||
38 | 38 | | |||
39 | #ifndef Q_OS_WIN | 39 | #ifndef Q_OS_WIN | ||
40 | #include <signal.h> | 40 | #include <signal.h> | ||
41 | #endif | 41 | #endif | ||
42 | 42 | | |||
43 | #include <defaultvariablemodel.h> | 43 | #include "octavevariablemodel.h" | ||
44 | 44 | | |||
45 | const QRegExp OctaveSession::PROMPT_UNCHANGEABLE_COMMAND = QRegExp(QLatin1String("(,|;)+")); | 45 | const QRegExp OctaveSession::PROMPT_UNCHANGEABLE_COMMAND = QRegExp(QLatin1String("(,|;)+")); | ||
46 | 46 | | |||
47 | OctaveSession::OctaveSession ( Cantor::Backend* backend ) : Session ( backend ), | 47 | OctaveSession::OctaveSession ( Cantor::Backend* backend ) : Session ( backend), | ||
48 | m_process(nullptr), | 48 | m_process(nullptr), | ||
49 | m_prompt(QLatin1String("CANTOR_OCTAVE_BACKEND_PROMPT:([0-9]+)> ")), | 49 | m_prompt(QLatin1String("CANTOR_OCTAVE_BACKEND_PROMPT:([0-9]+)> ")), | ||
50 | m_subprompt(QLatin1String("CANTOR_OCTAVE_BACKEND_SUBPROMPT:([0-9]+)> ")), | 50 | m_subprompt(QLatin1String("CANTOR_OCTAVE_BACKEND_SUBPROMPT:([0-9]+)> ")), | ||
51 | m_previousPromptNumber(1), | 51 | m_previousPromptNumber(1), | ||
52 | m_watch(nullptr), | 52 | m_watch(nullptr), | ||
53 | m_syntaxError(false), | 53 | m_syntaxError(false) | ||
54 | m_variableModel(new Cantor::DefaultVariableModel(this)) | | |||
55 | { | 54 | { | ||
55 | setVariableModel(new OctaveVariableModel(this)); | ||||
56 | qDebug() << octaveScriptInstallDir; | 56 | qDebug() << octaveScriptInstallDir; | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | void OctaveSession::login() | 59 | void OctaveSession::login() | ||
60 | { | 60 | { | ||
61 | qDebug() << "login"; | 61 | qDebug() << "login"; | ||
62 | emit loginStarted(); | 62 | emit loginStarted(); | ||
63 | 63 | | |||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | |||||
137 | connect ( m_process, SIGNAL (readyReadStandardOutput()), SLOT (readOutput()) ); | 137 | connect ( m_process, SIGNAL (readyReadStandardOutput()), SLOT (readOutput()) ); | ||
138 | connect ( m_process, SIGNAL (readyReadStandardError()), SLOT (readError()) ); | 138 | connect ( m_process, SIGNAL (readyReadStandardError()), SLOT (readError()) ); | ||
139 | connect ( m_process, SIGNAL (error(QProcess::ProcessError)), SLOT (processError()) ); | 139 | connect ( m_process, SIGNAL (error(QProcess::ProcessError)), SLOT (processError()) ); | ||
140 | 140 | | |||
141 | if(!OctaveSettings::self()->autorunScripts().isEmpty()){ | 141 | if(!OctaveSettings::self()->autorunScripts().isEmpty()){ | ||
142 | QString autorunScripts = OctaveSettings::self()->autorunScripts().join(QLatin1String("\n")); | 142 | QString autorunScripts = OctaveSettings::self()->autorunScripts().join(QLatin1String("\n")); | ||
143 | 143 | | |||
144 | evaluateExpression(autorunScripts, OctaveExpression::DeleteOnFinish, true); | 144 | evaluateExpression(autorunScripts, OctaveExpression::DeleteOnFinish, true); | ||
145 | forceVariableUpdate(); | ||||
145 | } | 146 | } | ||
146 | 147 | | |||
147 | changeStatus(Cantor::Session::Done); | 148 | changeStatus(Cantor::Session::Done); | ||
148 | emit loginDone(); | 149 | emit loginDone(); | ||
149 | qDebug()<<"login done"; | 150 | qDebug()<<"login done"; | ||
150 | } | 151 | } | ||
151 | 152 | | |||
152 | void OctaveSession::logout() | 153 | void OctaveSession::logout() | ||
Show All 23 Lines | 154 | { | |||
176 | delete m_process; | 177 | delete m_process; | ||
177 | m_process = nullptr; | 178 | m_process = nullptr; | ||
178 | 179 | | |||
179 | 180 | | |||
180 | m_tempDir.clear(); | 181 | m_tempDir.clear(); | ||
181 | m_output.clear(); | 182 | m_output.clear(); | ||
182 | m_previousPromptNumber = 1; | 183 | m_previousPromptNumber = 1; | ||
183 | 184 | | |||
184 | m_variableModel->clearVariables(); | 185 | OctaveVariableModel* model = static_cast<OctaveVariableModel*>(variableModel()); | ||
186 | model->clearVariables(); | ||||
185 | 187 | | |||
186 | changeStatus(Status::Disable); | 188 | changeStatus(Status::Disable); | ||
187 | 189 | | |||
188 | qDebug()<<"logout done"; | 190 | qDebug()<<"logout done"; | ||
189 | } | 191 | } | ||
190 | 192 | | |||
191 | void OctaveSession::interrupt() | 193 | void OctaveSession::interrupt() | ||
192 | { | 194 | { | ||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Line(s) | 277 | { | |||
279 | { | 281 | { | ||
280 | const int promptNumber = m_prompt.cap(1).toInt(); | 282 | const int promptNumber = m_prompt.cap(1).toInt(); | ||
281 | if (!expressionQueue().isEmpty()) | 283 | if (!expressionQueue().isEmpty()) | ||
282 | { | 284 | { | ||
283 | const QString& command = expressionQueue().first()->command(); | 285 | const QString& command = expressionQueue().first()->command(); | ||
284 | if (m_previousPromptNumber + 1 == promptNumber || isSpecialOctaveCommand(command)) | 286 | if (m_previousPromptNumber + 1 == promptNumber || isSpecialOctaveCommand(command)) | ||
285 | { | 287 | { | ||
286 | if (!expressionQueue().isEmpty()) | 288 | if (!expressionQueue().isEmpty()) | ||
287 | { | | |||
288 | if (command.contains(QLatin1String(" = ")) || command.contains(QLatin1String("clear"))) | | |||
289 | { | | |||
290 | emit variablesChanged(); | | |||
291 | } | | |||
292 | static_cast<OctaveExpression*>(expressionQueue().first())->parseOutput(m_output); | 289 | static_cast<OctaveExpression*>(expressionQueue().first())->parseOutput(m_output); | ||
293 | } | 290 | } | ||
294 | } | | |||
295 | else | 291 | else | ||
296 | { | 292 | { | ||
297 | // Error command don't increase octave prompt number (usually, but not always) | 293 | // Error command don't increase octave prompt number (usually, but not always) | ||
298 | readError(); | 294 | readError(); | ||
299 | } | 295 | } | ||
300 | } | 296 | } | ||
301 | m_previousPromptNumber = promptNumber; | 297 | m_previousPromptNumber = promptNumber; | ||
302 | m_output.clear(); | 298 | m_output.clear(); | ||
Show All 14 Lines | |||||
317 | 313 | | |||
318 | void OctaveSession::currentExpressionStatusChanged(Cantor::Expression::Status status) | 314 | void OctaveSession::currentExpressionStatusChanged(Cantor::Expression::Status status) | ||
319 | { | 315 | { | ||
320 | qDebug() << "currentExpressionStatusChanged"; | 316 | qDebug() << "currentExpressionStatusChanged"; | ||
321 | switch (status) | 317 | switch (status) | ||
322 | { | 318 | { | ||
323 | case Cantor::Expression::Done: | 319 | case Cantor::Expression::Done: | ||
324 | case Cantor::Expression::Error: | 320 | case Cantor::Expression::Error: | ||
325 | expressionQueue().removeFirst(); | 321 | finishFirstExpression(); | ||
326 | if (expressionQueue().isEmpty()) | | |||
327 | changeStatus(Done); | | |||
328 | else | | |||
329 | runFirstExpression(); | | |||
330 | break; | 322 | break; | ||
323 | | ||||
331 | default: | 324 | default: | ||
332 | break; | 325 | break; | ||
333 | } | 326 | } | ||
334 | } | 327 | } | ||
335 | 328 | | |||
336 | void OctaveSession::plotFileChanged(const QString& filename) | 329 | void OctaveSession::plotFileChanged(const QString& filename) | ||
337 | { | 330 | { | ||
338 | if (!QFile::exists(filename) || !filename.split(QLatin1Char('/')).last().contains(QLatin1String("c-ob-"))) | 331 | if (!QFile::exists(filename) || !filename.split(QLatin1Char('/')).last().contains(QLatin1String("c-ob-"))) | ||
Show All 16 Lines | |||||
355 | { | 348 | { | ||
356 | return new OctaveSyntaxHelpObject ( cmd, this ); | 349 | return new OctaveSyntaxHelpObject ( cmd, this ); | ||
357 | } | 350 | } | ||
358 | 351 | | |||
359 | QSyntaxHighlighter* OctaveSession::syntaxHighlighter ( QObject* parent ) | 352 | QSyntaxHighlighter* OctaveSession::syntaxHighlighter ( QObject* parent ) | ||
360 | { | 353 | { | ||
361 | OctaveHighlighter* highlighter = new OctaveHighlighter ( parent, this ); | 354 | OctaveHighlighter* highlighter = new OctaveHighlighter ( parent, this ); | ||
362 | 355 | | |||
363 | connect ( this, SIGNAL(variablesChanged()), highlighter, SLOT(updateVariables()) ); | 356 | OctaveVariableModel* model = static_cast<OctaveVariableModel*>(variableModel()); | ||
364 | connect ( this, SIGNAL(statusChanged(Cantor::Session::Status)), highlighter, SLOT(sessionStatusChanged(Cantor::Session::Status)) ); | 357 | connect (model, &Cantor::DefaultVariableModel::variablesAdded, highlighter, &OctaveHighlighter::addUserVariable); | ||
358 | connect (model, &Cantor::DefaultVariableModel::variablesRemoved, highlighter, &OctaveHighlighter::removeUserVariable); | ||||
365 | 359 | | |||
366 | return highlighter; | 360 | return highlighter; | ||
367 | } | 361 | } | ||
368 | 362 | | |||
369 | QAbstractItemModel* OctaveSession::variableModel() | | |||
370 | { | | |||
371 | return m_variableModel; | | |||
372 | } | | |||
373 | | ||||
374 | | ||||
375 | void OctaveSession::runSpecificCommands() | 363 | void OctaveSession::runSpecificCommands() | ||
376 | { | 364 | { | ||
377 | m_process->write("figure(1,'visible','off')"); | 365 | m_process->write("figure(1,'visible','off')"); | ||
378 | } | 366 | } | ||
379 | 367 | | |||
380 | bool OctaveSession::isDoNothingCommand(const QString& command) | 368 | bool OctaveSession::isDoNothingCommand(const QString& command) | ||
381 | { | 369 | { | ||
382 | return PROMPT_UNCHANGEABLE_COMMAND.exactMatch(command) || command.isEmpty(); | 370 | return PROMPT_UNCHANGEABLE_COMMAND.exactMatch(command) || command.isEmpty(); | ||
383 | } | 371 | } | ||
384 | 372 | | |||
385 | bool OctaveSession::isSpecialOctaveCommand(const QString& command) | 373 | bool OctaveSession::isSpecialOctaveCommand(const QString& command) | ||
386 | { | 374 | { | ||
387 | return command.contains(QLatin1String("completion_matches")); | 375 | return command.contains(QLatin1String("completion_matches")); | ||
388 | } | 376 | } |