forked from qt-creator/qt-creator
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:
@@ -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())
|
||||||
|
@@ -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();
|
||||||
|
@@ -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:
|
||||||
|
@@ -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());
|
||||||
|
Reference in New Issue
Block a user