Changeset View
Changeset View
Standalone View
Standalone View
src/backends/R/rexpression.cpp
Context not available. | |||||
34 | #include <QFile> | 34 | #include <QFile> | ||
---|---|---|---|---|---|
35 | #include <QStringList> | 35 | #include <QStringList> | ||
36 | #include <QTextDocument> | 36 | #include <QTextDocument> | ||
37 | #include <QRegExp> | ||||
37 | 38 | | |||
38 | RExpression::RExpression( Cantor::Session* session ) : Cantor::Expression(session) | 39 | RExpression::RExpression( Cantor::Session* session ) : Cantor::Expression(session) | ||
39 | { | 40 | { | ||
Context not available. | |||||
51 | { | 52 | { | ||
52 | qDebug()<<"evaluating "<<command(); | 53 | qDebug()<<"evaluating "<<command(); | ||
53 | setStatus(Cantor::Expression::Computing); | 54 | setStatus(Cantor::Expression::Computing); | ||
54 | if(command().startsWith(QLatin1Char('?'))) | 55 | if(command().trimmed().startsWith(QLatin1Char('?')) || command().trimmed().startsWith(QLatin1String("help"))) | ||
55 | m_isHelpRequest=true; | 56 | m_isHelpRequest=true; | ||
56 | else | 57 | else | ||
57 | m_isHelpRequest=false; | 58 | m_isHelpRequest=false; | ||
58 | 59 | | |||
59 | static_cast<RSession*>(session())->queueExpression(this); | 60 | | ||
61 | RSession* session = dynamic_cast<RSession*>(this->session()); | ||||
62 | | ||||
63 | /* check if the command is a quit command. following are quit commands supported by R | ||||
64 | * quit(save = "default", status = 0, runLast = TRUE) | ||||
65 | * q(save = "default", status = 0, runLast = TRUE) | ||||
66 | */ | ||||
67 | QRegExp regexp; | ||||
68 | regexp.setCaseSensitivity(Qt::CaseSensitive); | ||||
69 | regexp.setPattern(QLatin1String("\\s*q\\s*\\([\\w\\W]*\\)\\s*$|\\s*quit\\s*\\([\\w\\W]*\\)\\s*$")); | ||||
70 | if(regexp.exactMatch(command().trimmed())) { | ||||
71 | // since it's a quit command, logout from the session | ||||
72 | setStatus(Cantor::Expression::Done); | ||||
73 | session->logout(); | ||||
74 | return; | ||||
75 | } | ||||
76 | | ||||
77 | // done evaluation, finally running the command | ||||
78 | session->runExpression(this); | ||||
79 | | ||||
80 | | ||||
60 | } | 81 | } | ||
61 | 82 | | |||
62 | void RExpression::interrupt() | 83 | void RExpression::parseOutput(QString output) | ||
63 | { | 84 | { | ||
64 | qDebug()<<"interrupting command"; | 85 | // remove garabage from output | ||
65 | if(status()==Cantor::Expression::Computing) | 86 | | ||
66 | session()->interrupt(); | 87 | output.replace(command(), QLatin1String("")); | ||
67 | setStatus(Cantor::Expression::Interrupted); | 88 | output.replace(QLatin1String(">"), QLatin1String("")); | ||
89 | output = output.trimmed(); | ||||
90 | | ||||
91 | qDebug() << " final output of the command " << command() << output << endl; | ||||
92 | | ||||
93 | if(m_isHelpRequest) | ||||
94 | setResult(new Cantor::HelpResult(output)); | ||||
95 | else | ||||
96 | setResult(new Cantor::TextResult(output)); | ||||
97 | | ||||
98 | setStatus(Cantor::Expression::Done); | ||||
68 | } | 99 | } | ||
69 | 100 | | |||
70 | void RExpression::finished(int returnCode, const QString& text) | 101 | void RExpression::parseError(QString error) | ||
71 | { | 102 | { | ||
72 | if(returnCode==RExpression::SuccessCode) | 103 | error.replace(command(), QLatin1String("")); | ||
73 | { | 104 | error.replace(QLatin1String(">"), QLatin1String("")); | ||
74 | setResult(new Cantor::TextResult(Qt::convertFromPlainText(text))); | 105 | error = error.trimmed(); | ||
75 | setStatus(Cantor::Expression::Done); | 106 | | ||
76 | }else if (returnCode==RExpression::ErrorCode) | 107 | setResult(new Cantor::TextResult(error)); | ||
77 | { | 108 | | ||
78 | setResult(new Cantor::TextResult(Qt::convertFromPlainText(text))); | 109 | setStatus(Cantor::Expression::Error); | ||
79 | setStatus(Cantor::Expression::Error); | 110 | setErrorMessage(error); | ||
80 | setErrorMessage(Qt::convertFromPlainText(text)); | | |||
81 | } | | |||
82 | } | 111 | } | ||
83 | 112 | | |||
84 | void RExpression::evaluationStarted() | 113 | void RExpression::interrupt() | ||
85 | { | 114 | { | ||
86 | setStatus(Cantor::Expression::Computing); | 115 | qDebug()<<"interrupting command"; | ||
116 | if(status()==Cantor::Expression::Computing) | ||||
117 | session()->interrupt(); | ||||
118 | setStatus(Cantor::Expression::Interrupted); | ||||
87 | } | 119 | } | ||
88 | 120 | | |||
89 | void RExpression::addInformation(const QString& information) | 121 | void RExpression::addInformation(const QString& information) | ||
90 | { | 122 | { | ||
91 | static_cast<RSession*>(session())->sendInputToServer(information); | 123 | /* not using this anymore since it was making use of rserver | ||
124 | * | ||||
125 | */ | ||||
126 | // static_cast<RSession*>(session())->sendInputToServer(information); | ||||
92 | } | 127 | } | ||
93 | 128 | | |||
94 | void RExpression::showFilesAsResult(const QStringList& files) | 129 | void RExpression::showFilesAsResult(const QStringList& files) | ||
Context not available. |