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

Highlight the warning results differently to clearly separate them visually from the normal output.

parent 5e58ba8f
Pipeline #119165 passed with stage
in 19 minutes and 6 seconds
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009-2012 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2017-2021 by Alexander Semke (alexander.semke@web.de)
SPDX-FileCopyrightText: 2017-2022 by Alexander Semke (alexander.semke@web.de)
*/
#include "maximaexpression.h"
......@@ -228,7 +228,12 @@ bool MaximaExpression::parseOutput(QString& out)
//"\nrat: replaced 7.5 by 15/2 = 7.5\n<cantor-result><cantor-text>\n(%o2) 15/2\n</cantor-text></cantor-result>\n<cantor-prompt>(%i3) </cantor-prompt>\n".
//In such cases we just add a new text result with the warning.
qDebug() << "warning: " << errorContent;
addResult(new Cantor::TextResult(errorContent.trimmed()));
auto* result = new Cantor::TextResult(errorContent.trimmed());
//the output of tex() function is also placed outside of the result section, don't treat it as a warning
if (!command().remove(QLatin1Char(' ')).startsWith(QLatin1String("tex(")))
result->setIsWarning(true);
addResult(result);
}
}
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2018-2022 by Alexander Semke (alexander.semke@web.de)
*/
#include "testmaxima.h"
......@@ -107,7 +108,7 @@ void TestMaxima::testInvalidSyntax()
QVERIFY( e->status()==Cantor::Expression::Error );
}
void TestMaxima::testWarning()
void TestMaxima::testWarning01()
{
auto* e = evalExp( QLatin1String("rat(0.75*10)") );
......@@ -116,12 +117,33 @@ void TestMaxima::testWarning()
//the actual warning string "rat: replaced 7.5 by 15/2 = 7.5" which we don't checked since it's translated,
//we just check it's existance.
QVERIFY(e->results().at(0)->data().toString().isEmpty() == false);
auto* result = dynamic_cast<Cantor::TextResult*>(e->results().at(0));
QVERIFY(e != nullptr);
QVERIFY(result->data().toString().isEmpty() == false);
QVERIFY(result->isWarning() == true);
//the result of the calculation
QCOMPARE(e->results().at(1)->data().toString(), QLatin1String("15/2"));
}
/*!
* test the output of the tex() function which is similarly formatted as other functions producing warning
* but which shouldn't be treated as a warning.
* */
void TestMaxima::testWarning02()
{
auto* e = evalExp( QLatin1String("tex(\"sin(x)\")") );
QVERIFY(e != nullptr);
QVERIFY(e->results().size() == 2); //two results, the TeX output and an additional 'false'
//the actual TeX string is of no interest for us, we just check it's existance.
auto* result = dynamic_cast<Cantor::TextResult*>(e->results().at(0));
QVERIFY(e != nullptr);
QVERIFY(result->data().toString().isEmpty() == false);
QVERIFY(result->isWarning() == false);
}
void TestMaxima::testExprNumbering()
{
Cantor::Expression* e=evalExp( QLatin1String("kill(labels)") ); //first reset the labels
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2018-2022 by Alexander Semke (alexander.semke@web.de)
*/
#ifndef _TESTMAXIMA_H
......@@ -32,7 +33,8 @@ private Q_SLOTS:
//tests a syntax error (not closing bracket)
void testInvalidSyntax();
void testWarning();
void testWarning01();
void testWarning02();
//tests if the expression numbering works
void testExprNumbering();
void testInvalidAssignment();
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2022 Alexander Semke <alexander.semke@web.de>
*/
#include "textresult.h"
......@@ -26,15 +27,11 @@ QString rtrim(const QString& s)
class Cantor::TextResultPrivate
{
public:
TextResultPrivate()
{
format=TextResult::PlainTextFormat;
}
QString data;
QString plain;
TextResult::Format format;
TextResult::Format format{TextResult::PlainTextFormat};
bool isStderr{false};
bool isWarning{false};
};
TextResult::TextResult(const QString& data) : d(new TextResultPrivate)
......@@ -49,12 +46,21 @@ TextResult::TextResult(const QString& data, const QString& plain) : d(new TextRe
d->plain=rtrim(plain);
}
TextResult::~TextResult()
{
delete d;
}
void TextResult::setIsWarning(bool value)
{
d->isWarning = value;
}
bool TextResult::isWarning() const
{
return d->isWarning;
}
QString TextResult::toHtml()
{
QString s=d->data.toHtmlEscaped();
......
/*
SPDX-License-Identifier: GPL-2.0-or-later
SPDX-FileCopyrightText: 2009 Alexander Rieder <alexanderrieder@gmail.com>
SPDX-FileCopyrightText: 2022 Alexander Semke <alexander.semke@web.de>
*/
#ifndef _TEXTRESULT_H
......@@ -19,10 +20,14 @@ class CANTOR_EXPORT TextResult : public Result
public:
enum { Type=1 };
enum Format { PlainTextFormat, LatexFormat};
TextResult(const QString& text);
TextResult(const QString& text, const QString& plain);
~TextResult() override;
void setIsWarning(bool);
bool isWarning() const;
QString toHtml() override;
QVariant data() override;
......
......@@ -30,6 +30,10 @@ TextResultItem::TextResultItem(WorksheetEntry* parent, Cantor::Result* result)
setTextInteractionFlags(Qt::TextSelectableByMouse);
update();
auto* textResult = dynamic_cast<Cantor::TextResult*>(result);
if (textResult && textResult->isWarning())
setDefaultTextColor(qApp->palette().color(QPalette::Highlight));
// So useful behaviour:
// If we have HtmlResult, but after setting we have empty document
// So show Plain version - it more useful
......
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