File indexing completed on 2024-05-05 11:55:57
0001 /* 0002 SPDX-FileCopyrightText: 2009 Milian Wolff <mail@milianw.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef QALCULATE_SESSION_H 0008 #define QALCULATE_SESSION_H 0009 0010 #include "session.h" 0011 #include "qalculateexpression.h" 0012 0013 #include <QSharedPointer> 0014 #include <QQueue> 0015 #include <QMap> 0016 0017 #include <libqalculate/Variable.h> 0018 #include <libqalculate/MathStructure.h> 0019 0020 namespace Cantor { 0021 class DefaultVariableModel; 0022 } 0023 0024 class QalculateEngine; 0025 class QProcess; 0026 0027 0028 class QalculateSession : public Cantor::Session 0029 { 0030 Q_OBJECT 0031 0032 private: 0033 Cantor::DefaultVariableModel* m_variableModel; 0034 QProcess* m_process; 0035 QalculateExpression* m_currentExpression; 0036 QString m_output; 0037 QString m_finalOutput; 0038 QString m_currentCommand; 0039 QString m_saveError; 0040 QQueue<QalculateExpression*> m_expressionQueue; 0041 QQueue<QString> m_commandQueue; 0042 bool m_isSaveCommand; 0043 0044 0045 private: 0046 void runExpressionQueue(); 0047 void runCommandQueue(); 0048 QString parseSaveCommand(QString& currentCmd); 0049 void storeVariables(QString& currentCmd, QString output); 0050 0051 public: 0052 explicit QalculateSession( Cantor::Backend* backend); 0053 ~QalculateSession() override; 0054 0055 void login() override; 0056 void logout() override; 0057 0058 void interrupt() override; 0059 0060 Cantor::Expression* evaluateExpression(const QString& command, Cantor::Expression::FinishingBehavior behave = Cantor::Expression::FinishingBehavior::DoNotDelete, bool internal = false) override; 0061 Cantor::CompletionObject* completionFor(const QString& cmd, int index=-1) override; 0062 Cantor::SyntaxHelpObject* syntaxHelpFor(const QString& cmd) override; 0063 QSyntaxHighlighter* syntaxHighlighter(QObject* parent) override; 0064 0065 void runExpression(); 0066 Cantor::DefaultVariableModel* variableModel() const override; 0067 0068 public: 0069 QMap<QString,QString> variables; 0070 0071 public Q_SLOTS: 0072 void readOutput(); 0073 void readError(); 0074 void processStarted(); 0075 void currentExpressionStatusChanged(Cantor::Expression::Status status); 0076 }; 0077 0078 #endif