Commit 7d4bbbb9 authored by Alexander Semke's avatar Alexander Semke

Fixed missing latex typesetting.

Remove then branch of always false condition

Summary: The condition in `OctaveExpresssion::parseError` never comes `true`, so remove `then` branch.

Reviewers: #cantor, asemke

Reviewed By: #cantor, asemke

Subscribers: #kde_edu, #cantor

Tags: #cantor, #kde_edu

Differential Revision: https://phabricator.kde.org/D11965

Add amsmath package to LaTeX template

Summary: `amsmath` package widely spread and has useful funcitons, the existence of which user expects from LaTeX entry.

Reviewers: #cantor, asemke

Reviewed By: #cantor, asemke

Subscribers: #cantor, #kde_edu

Tags: #kde_edu, #cantor

Differential Revision: https://phabricator.kde.org/D11994

Added couple of missing variable initialisations and override keywords.

Add forgotten print command `plot3` to octavebackend print commands.

Summary: This command missing, so cantor don't show plot result of this command. This change fix it.

Reviewers: #cantor, asemke

Subscribers: #cantor, #kde_edu

Tags: #kde_edu, #cantor

Differential Revision: https://phabricator.kde.org/D12022

[Octave] add couple of more 3d plot commands.

[Octave] added couple of missing 2d plot commands.

Fix bad performance for `addRules` in `DefaultHighlighter` for big containers

Summary: Now, in `addRules` we call `addRule`, which emit `rulesChanged`, that leads to `rehighlight` all worksheet. This is useless work, because for each rule in rules container we reprocessing all worksheet. (instead better option to emit `rulesChanged` only one time after container processing). So, when container is big, performance falls quite strongly, for example highlighter of octave backend spends 2-4 seconds for adding new function. So this changes improve `emit` logic, calling only one event for rules container.

Test Plan:
1) Start octave backend, write octave function, check, that cantor is freezed for few seconds
2) Apply patch
3) Check, that octave backend don't freeze after entry with user function.

Reviewers: #cantor, asemke

Subscribers: #cantor, #kde_edu

Tags: #kde_edu, #cantor

Differential Revision: https://phabricator.kde.org/D11992

Show waiting cursor while openning a project.

Small improving of order of logic operators in evaluateNext

Reviewers: #cantor, asemke

Subscribers: #cantor, #kde_edu

Tags: #kde_edu, #cantor

Differential Revision: https://phabricator.kde.org/D12018

Add parsing errors in lua backend

Summary: Luabackend haven't parsed errors, so if entries cause errors, we just get empty output (but not empty error output, which don't check). This add error handling, so now we could see, if errors hapened.

Test Plan:
1) Start lua session, and check, that wrong lua expression don't produce any output.
2) Apply this patch
3) Check, that how wrong lua expression produce output and cause error entry status

Reviewers: #cantor, asemke

Subscribers: #cantor, #kde_edu

Tags: #kde_edu, #cantor

Differential Revision: https://phabricator.kde.org/D11963
parent ec3d7fee
......@@ -60,11 +60,11 @@ if(NOT WIN32)
PURPOSE "Support for rendering EPS files in Cantor")
find_package(LibSpectre)
if(LibSpectre_FOUND)
if(LIBSPECTRE_FOUND)
set(WITH_EPS On)
else(LibSpectre_FOUND)
else(LIBSPECTRE_FOUND)
set(WITH_EPS Off)
endif(LibSpectre_FOUND)
endif(LIBSPECTRE_FOUND)
else(NOT WIN32)
set(WITH_EPS Off)
......
......@@ -33,7 +33,7 @@ class RCompletionObject : public Cantor::CompletionObject
~RCompletionObject();
protected Q_SLOTS:
void fetchCompletions();
void fetchCompletions() override;
void receiveCompletions(const QString& token,const QStringList& options);
Q_SIGNALS:
......
......@@ -28,17 +28,19 @@ class RExpression : public Cantor::Expression
Q_OBJECT
public:
enum ServerReturnCode{SuccessCode=0, ErrorCode, InterruptedCode};
RExpression( Cantor::Session* session);
RExpression( Cantor::Session*);
~RExpression();
void evaluate();
void interrupt();
void evaluate() override;
void interrupt() override;
void addInformation(const QString&) override;
void addInformation(const QString& information);
public Q_SLOTS:
void finished(int returnCode, const QString& text);
void evaluationStarted();
void showFilesAsResult(const QStringList& files);
private:
bool m_isHelpRequest;
};
......
......@@ -30,9 +30,9 @@ class RScriptExtension : public Cantor::ScriptExtension
RScriptExtension(QObject* parent);
~RScriptExtension();
public Q_SLOTS:
virtual QString runExternalScript(const QString& path);
virtual QString scriptFileFilter();
virtual QString highlightingMode();
QString runExternalScript(const QString& path) override;
QString scriptFileFilter() override;
QString highlightingMode() override;
};
class RPlotExtension : public Cantor::AdvancedPlotExtension,
......@@ -43,11 +43,12 @@ class RPlotExtension : public Cantor::AdvancedPlotExtension,
public:
RPlotExtension(QObject* parent);
~RPlotExtension() {}
QString accept(const Cantor::PlotTitleDirective& directive) const;
QString accept(const Cantor::OrdinateScaleDirective& directive) const;
QString accept(const Cantor::AbscissScaleDirective& directive) const;
QString accept(const Cantor::PlotTitleDirective&) const override;
QString accept(const Cantor::OrdinateScaleDirective&) const override;
QString accept(const Cantor::AbscissScaleDirective&) const override;
protected:
QString plotCommand() const { return QLatin1String("plot"); }
QString plotCommand() const override { return QLatin1String("plot"); }
};
#endif /* _REXTENSIONS_H */
......@@ -32,7 +32,7 @@ class RHighlighter : public Cantor::DefaultHighlighter
~RHighlighter();
protected:
void highlightBlock(const QString &text);
void highlightBlock(const QString &text) override;
public Q_SLOTS:
void refreshSyntaxRegExps();
......
......@@ -37,14 +37,14 @@ class RSession : public Cantor::Session
RSession( Cantor::Backend* backend);
~RSession();
void login();
void logout();
void login() override;
void logout() override;
void interrupt();
void interrupt() override;
Cantor::Expression* evaluateExpression(const QString& command, Cantor::Expression::FinishingBehavior behave);
Cantor::CompletionObject* completionFor(const QString& command, int index=-1);
QSyntaxHighlighter* syntaxHighlighter(QObject* parent);
Cantor::Expression* evaluateExpression(const QString& command, Cantor::Expression::FinishingBehavior behave) override;
Cantor::CompletionObject* completionFor(const QString& command, int index=-1) override;
QSyntaxHighlighter* syntaxHighlighter(QObject* parent) override;
void queueExpression(RExpression* expr);
void sendInputToServer(const QString& input);
......
......@@ -29,7 +29,7 @@ class RSettingsWidget : public QWidget,public Ui::RSettingsBase
public:
RSettingsWidget(QWidget *parent = 0);
bool eventFilter(QObject *obj, QEvent *event);
bool eventFilter(QObject*, QEvent*) override;
public Q_SLOTS:
void displayFileSelectionDialog();
......
......@@ -47,8 +47,8 @@ protected:
/**
* @see Cantor::CompletionObject::mayIdentifierContain
*/
virtual bool mayIdentifierContain(QChar c) const;
virtual bool mayIdentifierBeginWith(QChar c) const;
bool mayIdentifierContain(QChar c) const override;
bool mayIdentifierBeginWith(QChar c) const override;
/**
* @see Cantor::CompletionObject::mayIdentifierBeginWith
......@@ -58,5 +58,5 @@ protected Q_SLOTS:
/**
* @see Cantor::CompletionObject::fetchCompletions
*/
void fetchCompletions();
void fetchCompletions() override;
};
......@@ -58,6 +58,13 @@ void LuaExpression::evaluate()
currentSession->runExpression(this);
}
void LuaExpression::parseError(QString &error)
{
qDebug() << error;
setErrorMessage(error);
setStatus(Error);
}
void LuaExpression::parseOutput(QString &output)
{
output.replace(command(), QLatin1String(""));
......
......@@ -36,6 +36,7 @@ public:
void evaluate();
void interrupt();
void parseOutput(QString& output);
void parseError(QString& error);
};
......
......@@ -108,7 +108,13 @@ void LuaSession::readOutput()
void LuaSession::readError()
{
qDebug() << m_process->readAllStandardError() << endl;
qDebug() << "readError";
QString error = QString::fromLocal8Bit(m_process->readAllStandardError());
if (!m_currentExpression || error.isEmpty())
{
return;
}
m_currentExpression->parseError(error);
}
void LuaSession::processStarted()
......
......@@ -27,8 +27,6 @@
#include <QFile>
#include <helpresult.h>
#include <config-cantorlib.h>
static const char* printCommand = "cantor_print();";
......@@ -38,9 +36,19 @@ OctaveExpression::OctaveExpression(Cantor::Session* session): Expression(session
m_error(false)
{
m_plotCommands << QLatin1String("plot") << QLatin1String("semilogx") << QLatin1String("semilogy") << QLatin1String("loglog")
<< QLatin1String("polar") << QLatin1String("mesh") << QLatin1String("contour") << QLatin1String("bar")
<< QLatin1String("stairs") << QLatin1String("errorbar") << QLatin1String("surf") << QLatin1String("sombrero")
<< QLatin1String("hist") << QLatin1String("fplot") << QLatin1String("imshow");
<< QLatin1String("polar") << QLatin1String("contour") << QLatin1String("bar")
<< QLatin1String("stairs") << QLatin1String("errorbar") << QLatin1String("sombrero")
<< QLatin1String("hist") << QLatin1String("fplot") << QLatin1String("imshow")
<< QLatin1String("stem") << QLatin1String("stem3") << QLatin1String("scatter") << QLatin1String("pareto") << QLatin1String("rose")
<< QLatin1String("pie") << QLatin1String("quiver") << QLatin1String("compass") << QLatin1String("feather")
<< QLatin1String("pcolor") << QLatin1String("area") << QLatin1String("fill") << QLatin1String("comet")
/* 3d-plots */
<< QLatin1String("plot3")
<< QLatin1String("mesh") << QLatin1String("meshc") << QLatin1String("meshz")
<< QLatin1String("surf") << QLatin1String("surfc") << QLatin1String("surfl") << QLatin1String("surfnorm")
<< QLatin1String("isosurface")<< QLatin1String("isonormals") << QLatin1String("isocaps")
/* 3d-plots defined by a function */
<< QLatin1String("ezplot3") << QLatin1String("ezmesh") << QLatin1String("ezmeshc") << QLatin1String("ezsurf") << QLatin1String("ezsurfc");
m_plotCommands << QLatin1String("cantor_plot2d") << QLatin1String("cantor_plot3d");
}
......@@ -107,16 +115,9 @@ void OctaveExpression::parseOutput ( QString output )
void OctaveExpression::parseError(QString error)
{
qDebug() << error;
if (false && error.contains(QLatin1String("warning")))
{
parseOutput(error);
}
else
{
m_error = true;
setErrorMessage(error);
setStatus(Error);
}
m_error = true;
setErrorMessage(error);
setStatus(Error);
}
void OctaveExpression::parsePlotFile(QString file)
......
......@@ -20,6 +20,8 @@
#ifndef OCTAVEEXPRESSION_H
#define OCTAVEEXPRESSION_H
#include <config-cantorlib.h>
#include <expression.h>
#include <QStringList>
......
......@@ -424,7 +424,9 @@ bool CantorPart::openFile()
return false;
}
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
m_worksheet->load(localFilePath());
QApplication::restoreOverrideCursor();
// just for fun, set the status bar
//setStatusMessage( m_url.prettyUrl() );
......
......@@ -251,7 +251,8 @@ void ImageEntry::updateEntry()
QSizeF ImageEntry::imageSize(const ImageSize& imgSize)
{
const QSize& srcSize = m_imageItem->imageSize();
qreal w, h;
qreal w = 0.0;
qreal h = 0.0;
if (imgSize.heightUnit == ImageSize::Percent)
h = srcSize.height() * imgSize.height / 100;
else if (imgSize.heightUnit == ImageSize::Pixel)
......
......@@ -287,7 +287,7 @@ WorksheetCursor LatexEntry::search(QString pattern, unsigned flags,
return WorksheetCursor();
QTextCursor textCursor = m_textItem->search(pattern, qt_flags, pos);
int position;
int position = 0;
QString latex;
const QString repl = QString(QChar::ObjectReplacementCharacter);
QTextCursor latexCursor = m_textItem->search(repl, qt_flags, pos);
......
......@@ -72,6 +72,7 @@ class Cantor::DefaultHighlighterPrivate
int lastBlockNumber;
int lastPosition;
bool suppressRuleChangedSignal;
// each two consecutive items build a pair
QList<QChar> pairs;
......@@ -86,6 +87,7 @@ DefaultHighlighter::DefaultHighlighter(QObject* parent)
d->cursor = QTextCursor();
d->lastBlockNumber=-1;
d->lastPosition=-1;
d->suppressRuleChangedSignal = false;
addPair(QLatin1Char('('), QLatin1Char(')'));
addPair(QLatin1Char('['), QLatin1Char(']'));
......@@ -381,7 +383,8 @@ void DefaultHighlighter::positionChanged(QTextCursor cursor)
void DefaultHighlighter::addRule(const QString& word, const QTextCharFormat& format)
{
d->wordRules[word] = format;
emit rulesChanged();
if (!d->suppressRuleChangedSignal)
emit rulesChanged();
}
void DefaultHighlighter::addRule(const QRegExp& regexp, const QTextCharFormat& format)
......@@ -389,22 +392,63 @@ void DefaultHighlighter::addRule(const QRegExp& regexp, const QTextCharFormat& f
HighlightingRule rule = { regexp, format };
d->regExpRules.removeAll(rule);
d->regExpRules.append(rule);
emit rulesChanged();
if (!d->suppressRuleChangedSignal)
emit rulesChanged();
}
void DefaultHighlighter::removeRule(const QString& word)
{
d->wordRules.remove(word);
emit rulesChanged();
if (!d->suppressRuleChangedSignal)
emit rulesChanged();
}
void DefaultHighlighter::removeRule(const QRegExp& regexp)
{
HighlightingRule rule = { regexp, QTextCharFormat() };
d->regExpRules.removeAll(rule);
if (!d->suppressRuleChangedSignal)
emit rulesChanged();
}
void DefaultHighlighter::addRules(const QStringList& conditions, const QTextCharFormat& format)
{
typename QStringList::const_iterator i = conditions.constBegin();
typename QStringList::const_iterator end = conditions.constEnd();
d->suppressRuleChangedSignal = true;
for (;i != end; ++i)
{
addRule(*i, format);
}
d->suppressRuleChangedSignal = true;
emit rulesChanged();
}
void DefaultHighlighter::addFunctions(const QStringList& functions)
{
addRules(functions, functionFormat());
}
void DefaultHighlighter::addKeywords(const QStringList& keywords)
{
addRules(keywords, keywordFormat());
}
void DefaultHighlighter::addVariables(const QStringList& variables)
{
addRules(variables, variableFormat());
}
void DefaultHighlighter::removeRules(const QStringList& conditions)
{
typename QStringList::const_iterator i = conditions.constBegin();
typename QStringList::const_iterator end = conditions.constEnd();
d->suppressRuleChangedSignal = true;
for (;i != end; ++i)
{
removeRule(*i);
}
d->suppressRuleChangedSignal = false;
emit rulesChanged();
}
......
......@@ -119,19 +119,19 @@ class CANTOR_EXPORT DefaultHighlighter : public QSyntaxHighlighter
* @endcode
* @param conditions any Qt container of QRegExp or QString.
*/
template <class Container> void addRules(const Container& conditions, const QTextCharFormat& format);
void addRules(const QStringList& conditions, const QTextCharFormat& format);
/**
* Convenience method, equivalent to @code addRules(functions, functionFormat()) @endcode
*/
template <class Container> void addFunctions(const Container& functions);
void addFunctions(const QStringList& functions);
/**
* Convenience method, equivalent to @code addRules(variables, variableFormat()) @endcode
*/
template <class Container> void addVariables(const Container& variables);
void addVariables(const QStringList& variables);
/**
* Convenience method, equivalent to @code addRules(keywords, keywordFormat()) @endcode
*/
template <class Container> void addKeywords(const Container& keywords);
void addKeywords(const QStringList& keywords);
/**
* Removes any rules previously added for the word @p word
......@@ -145,7 +145,7 @@ class CANTOR_EXPORT DefaultHighlighter : public QSyntaxHighlighter
* Convenience method, removes all rules with conditions from @p conditions
* @sa removeRule, addRules
*/
template <class Container> void removeRules(const Container& conditions);
void removeRules(const QStringList& conditions);
/**
* Highlight pairs added with addPair()
......@@ -178,48 +178,6 @@ class CANTOR_EXPORT DefaultHighlighter : public QSyntaxHighlighter
private:
DefaultHighlighterPrivate* d;
};
template <class Container>
void DefaultHighlighter::addRules(const Container& conditions, const QTextCharFormat& format)
{
typename Container::const_iterator i = conditions.constBegin();
typename Container::const_iterator end = conditions.constEnd();
for (;i != end; ++i)
{
addRule(*i, format);
}
}
template <class Container>
void DefaultHighlighter::addFunctions(const Container& functions)
{
addRules(functions, functionFormat());
}
template <class Container>
void DefaultHighlighter::addKeywords(const Container& keywords)
{
addRules(keywords, keywordFormat());
}
template <class Container>
void DefaultHighlighter::addVariables(const Container& variables)
{
addRules(variables, variableFormat());
}
template <class Container>
void DefaultHighlighter::removeRules(const Container& conditions)
{
typename Container::const_iterator i = conditions.constBegin();
typename Container::const_iterator end = conditions.constEnd();
for (;i != end; ++i)
{
removeRule(*i);
}
}
}
#endif
......@@ -46,6 +46,7 @@ class Cantor::LatexRendererPrivate
static const QLatin1String tex("\\documentclass[12pt,fleqn]{article} \n "\
"\\usepackage{latexsym,amsfonts,amssymb,ulem} \n "\
"\\usepackage{amsmath} \n "\
"\\usepackage[dvips]{graphicx} \n "\
"\\usepackage[utf8]{inputenc} \n "\
"\\usepackage{xcolor} \n "\
......
......@@ -308,7 +308,7 @@ WorksheetCursor TextEntry::search(QString pattern, unsigned flags,
return WorksheetCursor();
QTextCursor textCursor = m_textItem->search(pattern, qt_flags, pos);
int position;
int position = 0;
QTextCursor latexCursor;
QString latex;
if (flags & WorksheetEntry::SearchLaTeX) {
......
......@@ -46,6 +46,8 @@
#include "lib/session.h"
#include "lib/defaulthighlighter.h"
#include <config-cantorlib.h>
const double Worksheet::LeftMargin = 4;
const double Worksheet::RightMargin = 4;
const double Worksheet::TopMargin = 4;
......
......@@ -336,7 +336,7 @@ void WorksheetEntry::evaluateNext(EvaluationOption opt)
worksheet()->setModified();
}
} else if (opt != DoNothing) {
if (!isEmpty() && !worksheet()->isLoadingFromFile() || type() != CommandEntry::Type)
if (!worksheet()->isLoadingFromFile() && (!isEmpty() || type() != CommandEntry::Type))
worksheet()->appendCommandEntry();
else
focusEntry();
......
Markdown is supported
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