Commit eb69b550 authored by Alexander Semke's avatar Alexander Semke
Browse files

Moved the handling of the expression status changes to the base class Session.

parent f55ddcf6
Pipeline #161636 passed with stage
in 5 minutes and 25 seconds
......@@ -185,24 +185,6 @@ void MaximaSession::reportProcessError(QProcess::ProcessError e)
}
}
void MaximaSession::currentExpressionChangedStatus(Cantor::Expression::Status status)
{
auto* expression = expressionQueue().first();
qDebug() << "expression status changed: command = " << expression->command() << ", status = " << status;
switch (status)
{
case Cantor::Expression::Done:
case Cantor::Expression::Error:
qDebug()<<"################################## EXPRESSION END ###############################################";
disconnect(expression, &Cantor::Expression::statusChanged, this, &MaximaSession::currentExpressionChangedStatus);
finishFirstExpression();
break;
default:
break;
}
}
void MaximaSession::runFirstExpression()
{
qDebug()<<"running next expression";
......@@ -213,7 +195,7 @@ void MaximaSession::runFirstExpression()
{
auto* expr = expressionQueue().first();
const auto& command = expr->internalCommand();
connect(expr, &Cantor::Expression::statusChanged, this, &MaximaSession::currentExpressionChangedStatus);
connect(expr, &Cantor::Expression::statusChanged, this, &Session::currentExpressionStatusChanged);
expr->setStatus(Cantor::Expression::Computing);
if(command.isEmpty())
......
......@@ -48,7 +48,6 @@ class MaximaSession : public Cantor::Session
void readStdErr();
private Q_SLOTS:
void currentExpressionChangedStatus(Cantor::Expression::Status);
void restartMaxima();
void restartsCooledDown();
void reportProcessError(QProcess::ProcessError);
......
......@@ -236,6 +236,7 @@ void OctaveSession::processError()
Cantor::Expression* OctaveSession::evaluateExpression(const QString& cmd, Cantor::Expression::FinishingBehavior behavior, bool internal)
{
qDebug()<<"################################## EXPRESSION START ###############################################";
qDebug() << "evaluating: " << cmd;
auto* expression = new OctaveExpression(this, internal);
expression->setCommand(cmd);
......@@ -248,7 +249,7 @@ Cantor::Expression* OctaveSession::evaluateExpression(const QString& cmd, Cantor
void OctaveSession::runFirstExpression()
{
auto* expression = expressionQueue().first();
connect(expression, &Cantor::Expression::statusChanged, this, &OctaveSession::currentExpressionStatusChanged);
connect(expression, &Cantor::Expression::statusChanged, this, &Session::currentExpressionStatusChanged);
const auto& command = expression->internalCommand();
expression->setStatus(Cantor::Expression::Computing);
......@@ -279,7 +280,6 @@ void OctaveSession::readError()
void OctaveSession::readOutput()
{
qDebug() << "readOutput";
while (m_process->bytesAvailable() > 0)
{
QString line = QString::fromLocal8Bit(m_process->readLine());
......@@ -325,21 +325,6 @@ void OctaveSession::readOutput()
}
}
void OctaveSession::currentExpressionStatusChanged(Cantor::Expression::Status status)
{
qDebug() << "currentExpressionStatusChanged" << status << expressionQueue().first()->command();
switch (status)
{
case Cantor::Expression::Done:
case Cantor::Expression::Error:
finishFirstExpression();
break;
default:
break;
}
}
Cantor::CompletionObject* OctaveSession::completionFor(const QString& cmd, int index)
{
return new OctaveCompletionObject(cmd, index, this);
......
......@@ -67,7 +67,6 @@ class OctaveSession : public Cantor::Session
private Q_SLOTS:
void readOutput();
void readError();
void currentExpressionStatusChanged(Cantor::Expression::Status);
void processError();
void runSpecificCommands();
};
......
......@@ -333,6 +333,7 @@ QString QalculateSession::parseSaveCommand(QString& currentCmd)
return QLatin1String("");
}
//TODO: unify with the funcion in the base class
void QalculateSession::currentExpressionStatusChanged(Cantor::Expression::Status status)
{
// depending on the status of the expression change the status of the session;
......
......@@ -322,19 +322,6 @@ void SageSession::readStdErr()
}
}
void SageSession::currentExpressionChangedStatus(Cantor::Expression::Status status)
{
switch (status)
{
case Cantor::Expression::Done:
case Cantor::Expression::Error:
finishFirstExpression();
default:
break;
}
}
void SageSession::processFinished(int exitCode, QProcess::ExitStatus exitStatus)
{
Q_UNUSED(exitCode);
......@@ -379,7 +366,7 @@ void SageSession::runFirstExpression()
auto* expr = expressionQueue().first();
if (m_isInitialized)
{
connect(expr, SIGNAL(statusChanged(Cantor::Expression::Status)), this, SLOT(currentExpressionChangedStatus(Cantor::Expression::Status)));
connect(expr, &Cantor::Expression::statusChanged, this, &Session::currentExpressionStatusChanged);
QString command = expr->command();
if(command.endsWith(QLatin1Char('?')) && !command.endsWith(QLatin1String("??")))
......
......@@ -15,7 +15,6 @@
class SageExpression;
class KPtyProcess;
class SageSession : public Cantor::Session
{
Q_OBJECT
......@@ -45,8 +44,7 @@ class SageSession : public Cantor::Session
int m_minor;
};
explicit SageSession( Cantor::Backend* backend);
explicit SageSession(Cantor::Backend*);
~SageSession() override;
void login() override;
......@@ -60,19 +58,19 @@ class SageSession : public Cantor::Session
void sendInputToProcess(const QString& input);
void setTypesettingEnabled(bool enable) override;
void setWorksheetPath(const QString& path) override;
void setTypesettingEnabled(bool) override;
void setWorksheetPath(const QString&) override;
Cantor::CompletionObject* completionFor(const QString& command, int index=-1) override;
QSyntaxHighlighter* syntaxHighlighter(QObject* parent) override;
VersionInfo sageVersion();
public Q_SLOTS:
void readStdOut();
void readStdErr();
private Q_SLOTS:
void currentExpressionChangedStatus(Cantor::Expression::Status);
void processFinished(int exitCode, QProcess::ExitStatus);
void reportProcessError(QProcess::ProcessError);
void fileCreated(const QString& path);
......@@ -80,7 +78,7 @@ class SageSession : public Cantor::Session
private:
void defineCustomFunctions();
bool updateSageVersion();
private:
KPtyProcess* m_process;
bool m_isInitialized;
QString m_tmpPath;
......
......@@ -254,6 +254,7 @@ void ScilabSession::plotFileChanged(const QString& filename)
}
}
//TODO: unify with the funcion in the base class
void ScilabSession::currentExpressionStatusChanged(Cantor::Expression::Status status)
{
qDebug() << "currentExpressionStatusChanged: " << status;
......
......@@ -182,6 +182,24 @@ void Session::finishFirstExpression(bool setDoneAfterUpdate)
runFirstExpression();
}
void Session::currentExpressionStatusChanged(Cantor::Expression::Status status)
{
auto* expression = expressionQueue().first();
qDebug() << "expression status changed: command = " << expression->command() << ", status = " << status;
switch (status)
{
case Cantor::Expression::Done:
case Cantor::Expression::Error:
qDebug()<<"################################## EXPRESSION END ###############################################";
disconnect(expression, &Cantor::Expression::statusChanged, this, &Session::currentExpressionStatusChanged);
finishFirstExpression();
break;
default:
break;
}
}
Backend* Session::backend()
{
return d->backend;
......
......@@ -51,12 +51,12 @@ class CANTOR_EXPORT Session : public QObject
* thats job of the login() function
* @see login()
*/
explicit Session( Backend* backend);
explicit Session(Backend*);
/**
* Similar to Session::Session, but also specify variable model for automatically handles model's updates
*/
explicit Session( Backend* backend, DefaultVariableModel* model);
explicit Session(Backend*, DefaultVariableModel*);
/**
* Destructor
......@@ -159,7 +159,7 @@ class CANTOR_EXPORT Session : public QObject
* LaTeX typesetting (as indicated by the capabilities() flag.
* @param enable true to enable, false to disable typesetting
*/
virtual void setTypesettingEnabled(bool enable);
virtual void setTypesettingEnabled(bool);
/**
* Updates the worksheet path in the session.
......@@ -169,7 +169,7 @@ class CANTOR_EXPORT Session : public QObject
* to implement the proper logic if this feature is supported.
* @param path the new absolute path to the worksheet.
*/
virtual void setWorksheetPath(const QString& path);
virtual void setWorksheetPath(const QString&);
/**
* Returns the Backend, this Session is for
......@@ -202,13 +202,16 @@ class CANTOR_EXPORT Session : public QObject
*/
const QList<GraphicPackage>& enabledGraphicPackages() const;
public Q_SLOTS:
void currentExpressionStatusChanged(Cantor::Expression::Status);
protected:
/**
* Change the status of the Session. This will cause the
* stausChanged signal to be emitted
* @param newStatus the new status of the session
*/
void changeStatus(Cantor::Session::Status newStatus);
void changeStatus(Cantor::Session::Status);
/**
* Session can process one single expression at one time.
......@@ -242,7 +245,7 @@ class CANTOR_EXPORT Session : public QObject
/**
* Setting variable model, useful if model constructor requires functional session
*/
void setVariableModel(DefaultVariableModel* model);
void setVariableModel(DefaultVariableModel*);
/**
* Search file for session in AppDataLocation and in GenericDataLocation
......@@ -276,10 +279,10 @@ class CANTOR_EXPORT Session : public QObject
virtual QString graphicPackageErrorMessage(QString packageId) const;
Q_SIGNALS:
void statusChanged(Cantor::Session::Status newStatus);
void statusChanged(Cantor::Session::Status);
void loginStarted();
void loginDone();
void error(const QString& msg);
void error(const QString&);
private:
SessionPrivate* d;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment