Commit 84a0d9b2 authored by Stefan Brüns's avatar Stefan Brüns
Browse files

Do not mangle angle brackets in value widgets

Summary:
When some value contains a opening angle bracket "<", any enclosed
text up to the closing ">" is removed from the value.

The mangling only happened for files which are readonly, making the
behavior even more awkward.

As any text properties a always plain text, remove the stripping
also for readonly files.

Depends on D25238

The stripping in the ValueWidget sizeHint is broken as well,
in case the value is PlainText, it would strip regular text from
the size calculation (creating a too narrow widget), for RichText
the sizeHint without stripping is too wide, but the layout
engine wraps the content correctly (it's a hint, after all).

As there are no users for the plainText function left, remove it.

Test Plan:
To expose the broken behavior:
# Create a document (.odt, html) with a '<' in e.g. the Title
# Make the file readonly -> everything after '<' vanishes

With the fix, the content is fully kept.

Reviewers: #baloo, ngraham, astippich

Reviewed By: #baloo, ngraham

Tags: #baloo

Differential Revision: https://phabricator.kde.org/D25239
parent 0dacef04
......@@ -39,28 +39,6 @@
#include <KLocalizedString>
#include <KStringHandler>
namespace {
static QString plainText(const QString& richText)
{
QString plainText;
plainText.reserve(richText.length());
bool skip = false;
for (int i = 0; i < richText.length(); ++i) {
const QChar c = richText.at(i);
if (c == QLatin1Char('<')) {
skip = true;
} else if (c == QLatin1Char('>')) {
skip = false;
} else if (!skip) {
plainText.append(c);
}
}
return plainText;
}
}
using namespace Baloo;
WidgetFactory::WidgetFactory(QObject* parent)
......@@ -236,10 +214,8 @@ QSize ValueWidget::sizeHint() const
{
QFontMetrics metrics(font());
// TODO: QLabel internally provides already a method sizeForWidth(),
// that would be sufficient. However this method is not accessible, so
// as workaround the tags from a richtext are removed manually here to
// have a proper size hint.
return metrics.size(Qt::TextSingleLine, plainText(text()));
// that would be sufficient. However this method is not accessible.
return metrics.size(Qt::TextSingleLine, text());
}
QWidget* WidgetFactory::createValueWidget(const QString& value, QWidget* parent)
......@@ -248,7 +224,7 @@ QWidget* WidgetFactory::createValueWidget(const QString& value, QWidget* parent)
valueWidget->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
valueWidget->setWordWrap(true);
valueWidget->setAlignment(Qt::AlignTop | Qt::AlignLeft);
valueWidget->setText(m_readOnly ? plainText(value) : value);
valueWidget->setText(value);
connect(valueWidget, &ValueWidget::linkActivated, this, &WidgetFactory::slotLinkActivated);
return valueWidget;
......
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