QtOutputFormatter: Use cursor object from base class

There does not seem to be a reason for the duplication.

Change-Id: I7c9b016c76a9aa93ccd93af0aea931fa5b148300
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2020-03-12 17:45:26 +01:00
parent f6cfcc4411
commit ea8efe58c6
3 changed files with 16 additions and 17 deletions

View File

@@ -112,6 +112,11 @@ void OutputFormatter::append(const QString &text, const QTextCharFormat &format)
d->cursor.insertText(text.mid(startPos), format);
}
QTextCursor &OutputFormatter::cursor() const
{
return d->cursor;
}
QTextCharFormat OutputFormatter::linkFormat(const QTextCharFormat &inputFormat, const QString &href)
{
QTextCharFormat result = inputFormat;

View File

@@ -52,7 +52,7 @@ public:
~OutputFormatter() override;
QPlainTextEdit *plainTextEdit() const;
virtual void setPlainTextEdit(QPlainTextEdit *plainText);
void setPlainTextEdit(QPlainTextEdit *plainText);
void flush();
@@ -72,6 +72,7 @@ protected:
QTextCharFormat charFormat(OutputFormat format) const;
QList<FormattedText> parseAnsi(const QString &text, const QTextCharFormat &format);
void append(const QString &text, const QTextCharFormat &format);
QTextCursor &cursor() const;
private:
virtual void appendMessage(const QString &text, const QTextCharFormat &format);

View File

@@ -94,7 +94,6 @@ public:
void appendMessage(const QString &text, Utils::OutputFormat format) override;
void handleLink(const QString &href) override;
void setPlainTextEdit(QPlainTextEdit *plainText) override;
protected:
void clearLastLine() override;
@@ -188,7 +187,7 @@ void QtOutputFormatter::appendMessagePart(const QString &txt, const QTextCharFor
LinkResult lr = matchLine(line);
if (!lr.href.isEmpty()) {
// Found something && line continuation
d->cursor.insertText(deferredText, fmt);
cursor().insertText(deferredText, fmt);
deferredText.clear();
if (!d->lastLine.isEmpty())
clearLastLine();
@@ -207,20 +206,20 @@ void QtOutputFormatter::appendMessagePart(const QString &txt, const QTextCharFor
}
d->lastLine.clear(); // Handled line continuation
}
d->cursor.insertText(deferredText, fmt);
cursor().insertText(deferredText, fmt);
}
void QtOutputFormatter::appendMessage(const QString &txt, const QTextCharFormat &format)
{
if (!d->cursor.atEnd())
d->cursor.movePosition(QTextCursor::End);
d->cursor.beginEditBlock();
if (!cursor().atEnd())
cursor().movePosition(QTextCursor::End);
cursor().beginEditBlock();
const QList<FormattedText> ansiTextList = parseAnsi(txt, format);
for (const FormattedText &output : ansiTextList)
appendMessagePart(output.text, output.format);
d->cursor.endEditBlock();
cursor().endEditBlock();
emit contentChanged();
}
@@ -233,9 +232,9 @@ void QtOutputFormatter::appendLine(const LinkResult &lr, const QString &line, Ou
void QtOutputFormatter::appendLine(const LinkResult &lr, const QString &line,
const QTextCharFormat &format)
{
d->cursor.insertText(line.left(lr.start), format);
d->cursor.insertText(line.mid(lr.start, lr.end - lr.start), linkFormat(format, lr.href));
d->cursor.insertText(line.mid(lr.end), format);
cursor().insertText(line.left(lr.start), format);
cursor().insertText(line.mid(lr.start, lr.end - lr.start), linkFormat(format, lr.href));
cursor().insertText(line.mid(lr.end), format);
}
void QtOutputFormatter::handleLink(const QString &href)
@@ -304,12 +303,6 @@ void QtOutputFormatter::handleLink(const QString &href)
}
}
void QtOutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
{
OutputFormatter::setPlainTextEdit(plainText);
d->cursor = plainText ? plainText->textCursor() : QTextCursor();
}
void QtOutputFormatter::clearLastLine()
{
OutputFormatter::clearLastLine();