#include <QObject>
#define QT_USE_FAST_OPERATOR_PLUS
#include <QStringBuilder>
+#include <QTextDocument>
const char * const styleSheet =
".call {\n"
return QLatin1String("NULL");
}
-QString apiVariantToString(const QVariant &variant)
+// Qt::convertFromPlainText doesn't do precisely what we want
+static QString
+plainTextToHTML(const QString & plain, bool multiLine)
+{
+ int col = 0;
+ bool quote = false;
+ QString rich;
+ for (int i = 0; i < plain.length(); ++i) {
+ if (plain[i] == QLatin1Char('\n')){
+ if (multiLine) {
+ rich += QLatin1String("<br>\n");
+ } else {
+ rich += QLatin1String("\\n");
+ }
+ col = 0;
+ quote = true;
+ } else {
+ if (plain[i] == QLatin1Char('\t')){
+ if (multiLine) {
+ rich += QChar(0x00a0U);
+ ++col;
+ while (col % 8) {
+ rich += QChar(0x00a0U);
+ ++col;
+ }
+ } else {
+ rich += QLatin1String("\\t");
+ }
+ quote = true;
+ } else if (plain[i].isSpace()) {
+ rich += QChar(0x00a0U);
+ quote = true;
+ } else if (plain[i] == QLatin1Char('<')) {
+ rich += QLatin1String("<");
+ } else if (plain[i] == QLatin1Char('>')) {
+ rich += QLatin1String(">");
+ } else if (plain[i] == QLatin1Char('&')) {
+ rich += QLatin1String("&");
+ } else {
+ rich += plain[i];
+ }
+ ++col;
+ }
+ }
+
+ if (quote) {
+ return QLatin1Literal("\"") + rich + QLatin1Literal("\"");
+ }
+
+ return rich;
+}
+
+QString apiVariantToString(const QVariant &variant, bool multiLine)
{
if (variant.userType() == QVariant::Double) {
return QString::number(variant.toFloat());
}
}
+ if (variant.userType() == QVariant::String) {
+ return plainTextToHTML(variant.toString(), multiLine);
+ }
+
if (variant.userType() < QVariant::UserType) {
return variant.toString();
}
QLatin1String("</span>") +
QLatin1Literal(" = ") +
QLatin1Literal("<span class=\"arg-value\">") +
- apiVariantToString(argValues[i]) +
+ apiVariantToString(argValues[i], true) +
QLatin1Literal("</span>");
if (i < m_argNames.count() - 1)
m_richText += QLatin1String(", ");
m_richText +=
QLatin1String(" = ") +
QLatin1String("<span style=\"color:#0000ff\">") +
- apiVariantToString(m_returnValue) +
+ apiVariantToString(m_returnValue, true) +
QLatin1String("</span>");
}
m_richText += QLatin1String("</div>");