Remove duplicated code

Merge QtOutputFormatter::linkFormat and
PythonOutputFormatter::linkFormat to OutputFormatter::linkFormat because
these two functions were identical.

Fixes: QTCREATORBUG-23562
Change-Id: I1337b2fd66fc7d7b6742eb5e9c1a2caf1dc6b5bd
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Miklós Márton
2020-02-04 21:34:45 +01:00
parent 76d31dd93d
commit aeb7ef6b37
4 changed files with 13 additions and 23 deletions

View File

@@ -112,6 +112,16 @@ void OutputFormatter::append(const QString &text, const QTextCharFormat &format)
d->cursor.insertText(text.mid(startPos), format); d->cursor.insertText(text.mid(startPos), format);
} }
QTextCharFormat OutputFormatter::linkFormat(const QTextCharFormat &inputFormat, const QString &href)
{
QTextCharFormat result = inputFormat;
result.setForeground(creatorTheme()->color(Theme::TextColorLink));
result.setUnderlineStyle(QTextCharFormat::SingleUnderline);
result.setAnchor(true);
result.setAnchorHref(href);
return result;
}
void OutputFormatter::clearLastLine() void OutputFormatter::clearLastLine()
{ {
if (!d->cursor.atEnd()) if (!d->cursor.atEnd())

View File

@@ -61,6 +61,7 @@ public:
virtual QList<QWidget *> toolbarWidgets() const { return {}; } virtual QList<QWidget *> toolbarWidgets() const { return {}; }
virtual void clear() {} virtual void clear() {}
void setBoldFontEnabled(bool enabled); void setBoldFontEnabled(bool enabled);
static QTextCharFormat linkFormat(const QTextCharFormat &inputFormat, const QString &href);
signals: signals:
void contentChanged(); void contentChanged();

View File

@@ -60,16 +60,6 @@ using namespace Utils;
namespace Python { namespace Python {
namespace Internal { namespace Internal {
static QTextCharFormat linkFormat(const QTextCharFormat &inputFormat, const QString &href)
{
QTextCharFormat result = inputFormat;
result.setForeground(creatorTheme()->color(Theme::TextColorLink));
result.setUnderlineStyle(QTextCharFormat::SingleUnderline);
result.setAnchor(true);
result.setAnchorHref(href);
return result;
}
class PythonOutputFormatter : public OutputFormatter class PythonOutputFormatter : public OutputFormatter
{ {
public: public:

View File

@@ -230,17 +230,6 @@ void QtOutputFormatter::appendLine(const LinkResult &lr, const QString &line, Ou
appendLine(lr, line, charFormat(format)); appendLine(lr, line, charFormat(format));
} }
static QTextCharFormat linkFormat(const QTextCharFormat &inputFormat, const QString &href)
{
QTextCharFormat result = inputFormat;
result.setForeground(creatorTheme()->color(Theme::TextColorLink));
result.setUnderlineStyle(QTextCharFormat::SingleUnderline);
result.setAnchor(true);
result.setAnchorHref(href);
return result;
}
void QtOutputFormatter::appendLine(const LinkResult &lr, const QString &line, void QtOutputFormatter::appendLine(const LinkResult &lr, const QString &line,
const QTextCharFormat &format) const QTextCharFormat &format)
{ {
@@ -554,7 +543,7 @@ void QtSupportPlugin::testQtOutputFormatter_appendMessage_data()
<< "Object::Test in test.cpp:123" << "Object::Test in test.cpp:123"
<< "Object::Test in test.cpp:123" << "Object::Test in test.cpp:123"
<< QTextCharFormat() << QTextCharFormat()
<< linkFormat(QTextCharFormat(), "test.cpp:123"); << OutputFormatter::linkFormat(QTextCharFormat(), "test.cpp:123");
QTest::newRow("colored") QTest::newRow("colored")
<< "blue da ba dee" << "blue da ba dee"
<< "blue da ba dee" << "blue da ba dee"
@@ -608,7 +597,7 @@ void QtSupportPlugin::testQtOutputFormatter_appendMixedAssertAndAnsi()
edit.moveCursor(QTextCursor::WordRight); edit.moveCursor(QTextCursor::WordRight);
edit.moveCursor(QTextCursor::Right); edit.moveCursor(QTextCursor::Right);
QCOMPARE(edit.currentCharFormat(), linkFormat(QTextCharFormat(), "file://test.cpp:123")); QCOMPARE(edit.currentCharFormat(), OutputFormatter::linkFormat(QTextCharFormat(), "file://test.cpp:123"));
edit.moveCursor(QTextCursor::End); edit.moveCursor(QTextCursor::End);
QCOMPARE(edit.currentCharFormat(), blueFormat()); QCOMPARE(edit.currentCharFormat(), blueFormat());