Commit 879f412c authored by Nikita Sirgienko's avatar Nikita Sirgienko

Remove inheritance HelpResult from TextResult and add support to create...

Remove inheritance HelpResult from TextResult and add support to create HelpResult from html directly.
It's fix unreadable help result for Sage

Also increase soversion, because the change breaks ABI.

BUG: 401134
FIXED-IN: 18.12
parent ffea8c36
......@@ -181,8 +181,6 @@ void SageExpression::evalFinished()
if (!m_outputCache.isEmpty())
{
Cantor::TextResult* result=nullptr;
QString stripped=m_outputCache;
const bool isHtml=stripped.contains(QLatin1String("<html>"));
const bool isLatex=m_outputCache.contains(QLatin1String("\\newcommand{\\Bold}")); //Check if it's latex stuff
......@@ -197,28 +195,27 @@ void SageExpression::evalFinished()
{
stripped.remove( QRegExp( QLatin1String("<[a-zA-Z\\/][^>]*>") ) );
}
if (stripped.endsWith(QLatin1Char('\n')))
stripped.chop(1);
if (m_isHelpRequest)
{
//Escape whitespace
stripped.replace( QLatin1Char(' '), QLatin1String("&nbsp;"));
stripped = stripped.toHtmlEscaped();
stripped.replace(QLatin1Char('\n'), QLatin1String("<br/>\n"));
//make things quoted in `` `` bold
stripped.replace(QRegExp(QLatin1String("``([^`]*)``")), QLatin1String("<b>\\1</b>"));
result=new Cantor::HelpResult(stripped);
addResult(new Cantor::HelpResult(stripped, true));
}
else
{
result=new Cantor::TextResult(stripped);
Cantor::TextResult* result=new Cantor::TextResult(stripped);
if(isLatex)
result->setFormat(Cantor::TextResult::LatexFormat);
addResult(result);
}
if(isLatex)
result->setFormat(Cantor::TextResult::LatexFormat);
addResult(result);
}
if (hasImage)
......
......@@ -74,9 +74,7 @@ target_link_libraries( cantorlibs
Qt5::Xml
)
set_target_properties( cantorlibs
PROPERTIES VERSION ${KDE_APPLICATIONS_VERSION} SOVERSION 19
)
set_target_properties( cantorlibs PROPERTIES VERSION ${KDE_APPLICATIONS_VERSION} SOVERSION 20)
install( TARGETS cantorlibs ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} )
......
......@@ -21,10 +21,27 @@
#include "helpresult.h"
using namespace Cantor;
class Cantor::HelpResultPrivate
{
public:
HelpResultPrivate() = default;
~HelpResultPrivate() = default;
QString html;
};
HelpResult::HelpResult(const QString& text) : TextResult(text)
HelpResult::HelpResult(const QString& text, bool isHtml) : d(new HelpResultPrivate)
{
QString html;
if (!isHtml)
{
html = text.toHtmlEscaped();
html.replace(QLatin1Char('\n'), QLatin1String("<br/>\n"));
}
else
html = text;
d->html = html;
}
int HelpResult::type()
......@@ -34,11 +51,29 @@ int HelpResult::type()
QDomElement HelpResult::toXml(QDomDocument& doc)
{
//No need to save results of a help request
QDomElement e=doc.createElement(QLatin1String("Result"));
e.setAttribute(QLatin1String("type"), QLatin1String("help"));
//No need to save results of a help request
QDomText txt=doc.createTextNode(QString());
e.appendChild(txt);
return e;
}
QString HelpResult::toHtml()
{
return d->html;
}
QVariant HelpResult::data()
{
return QVariant(d->html);
}
QString HelpResult::mimeType()
{
return QLatin1String("text/html");
}
void HelpResult::save(const QString& filename)
{
//No need to save results of a help request
Q_UNUSED(filename);
}
......@@ -30,16 +30,25 @@ namespace Cantor
so that the application can show it in another way than the
normal results
**/
class CANTOR_EXPORT HelpResult : public TextResult
class HelpResultPrivate;
class CANTOR_EXPORT HelpResult: public Result
{
public:
enum {Type=3};
explicit HelpResult( const QString& text);
explicit HelpResult( const QString& text, bool isHtml=false);
~HelpResult() override = default;
QVariant data() override;
QString toHtml() override;
int type() override;
QString mimeType() override;
QDomElement toXml(QDomDocument& doc) override;
void save(const QString& filename) override;
private:
HelpResultPrivate* d;
};
}
......
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