aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qtsupport/qtoutputformatter.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2020-03-18 12:56:35 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2020-03-19 09:31:02 +0000
commitef6af1b7df7374eab6bb85a2fa80dd3a5e12e2a2 (patch)
tree4c35e12818c55e44d5af23e3a99107bdc2156f68 /src/plugins/qtsupport/qtoutputformatter.cpp
parentc8a2ea54333b4d0582afb62b4120558f8c6945e7 (diff)
OutputFormatter: Do the newline handling centrally
All output formatters are line-based, and they all did their own line splitting and, if they didn't entirely ignore it, handling of partial lines. Instead, we now do all the book-keeping in the base class, and the subclasses always work with complete lines. Change-Id: I0b0df7951d0e4f6601f4d912230071784c87b3d3 Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/plugins/qtsupport/qtoutputformatter.cpp')
-rw-r--r--src/plugins/qtsupport/qtoutputformatter.cpp81
1 files changed, 14 insertions, 67 deletions
diff --git a/src/plugins/qtsupport/qtoutputformatter.cpp b/src/plugins/qtsupport/qtoutputformatter.cpp
index b2179f33f5..fdaef6004b 100644
--- a/src/plugins/qtsupport/qtoutputformatter.cpp
+++ b/src/plugins/qtsupport/qtoutputformatter.cpp
@@ -81,7 +81,6 @@ public:
const QRegularExpression qtTestFailUnix;
const QRegularExpression qtTestFailWin;
QPointer<Project> project;
- QList<FormattedText> lastLine;
FileInProjectFinder projectFinder;
QTextCursor cursor;
};
@@ -92,20 +91,18 @@ public:
explicit QtOutputFormatter(Target *target);
~QtOutputFormatter() override;
- void doAppendMessage(const QString &text, Utils::OutputFormat format) override;
- void handleLink(const QString &href) override;
-
protected:
- void clearLastLine() override;
virtual void openEditor(const QString &fileName, int line, int column = -1);
private:
+ void doAppendMessage(const QString &text, Utils::OutputFormat format) override;
+ void handleLink(const QString &href) override;
+
void updateProjectFileList();
LinkResult matchLine(const QString &line) const;
void appendMessagePart(const QString &txt, const QTextCharFormat &fmt);
- void appendLine(const LinkResult &lr, const QString &line, Utils::OutputFormat format);
void appendLine(const LinkResult &lr, const QString &line, const QTextCharFormat &format);
- void doAppendMessage(const QString &text, const QTextCharFormat &format) override;
+ void doAppendMessage(const QString &txt, const QTextCharFormat &format);
QtOutputFormatterPrivate *d;
friend class QtSupportPlugin; // for testing
@@ -163,68 +160,25 @@ LinkResult QtOutputFormatter::matchLine(const QString &line) const
return lr;
}
-void QtOutputFormatter::doAppendMessage(const QString &txt, OutputFormat format)
-{
- doAppendMessage(txt, charFormat(format));
-}
-
-void QtOutputFormatter::appendMessagePart(const QString &txt, const QTextCharFormat &fmt)
-{
- QString deferredText;
-
- const int length = txt.length();
- for (int start = 0, pos = -1; start < length; start = pos + 1) {
- bool linkHandled = false;
- pos = txt.indexOf('\n', start);
- const QString newPart = txt.mid(start, (pos == -1) ? -1 : pos - start + 1);
- QString line = newPart;
- QTextCharFormat format = fmt;
- if (!d->lastLine.isEmpty()) {
- line = d->lastLine.last().text + newPart;
- format = d->lastLine.last().format;
- }
-
- LinkResult lr = matchLine(line);
- if (!lr.href.isEmpty()) {
- // Found something && line continuation
- cursor().insertText(deferredText, fmt);
- deferredText.clear();
- if (!d->lastLine.isEmpty())
- clearLastLine();
- appendLine(lr, line, format);
- linkHandled = true;
- } else {
- // Found nothing, just emit the new part
- deferredText += newPart;
- }
-
- if (pos == -1) {
- d->lastLine.clear();
- if (!linkHandled)
- d->lastLine.append(FormattedText(line, format));
- break;
- }
- d->lastLine.clear(); // Handled line continuation
- }
- cursor().insertText(deferredText, fmt);
-}
-
void QtOutputFormatter::doAppendMessage(const QString &txt, const QTextCharFormat &format)
{
- 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);
+}
- cursor().endEditBlock();
+void QtOutputFormatter::doAppendMessage(const QString &txt, OutputFormat format)
+{
+ doAppendMessage(txt, charFormat(format));
}
-void QtOutputFormatter::appendLine(const LinkResult &lr, const QString &line, OutputFormat format)
+void QtOutputFormatter::appendMessagePart(const QString &txt, const QTextCharFormat &fmt)
{
- appendLine(lr, line, charFormat(format));
+ const LinkResult lr = matchLine(txt);
+ if (!lr.href.isEmpty())
+ appendLine(lr, txt, fmt);
+ else
+ cursor().insertText(txt, fmt);
}
void QtOutputFormatter::appendLine(const LinkResult &lr, const QString &line,
@@ -301,13 +255,6 @@ void QtOutputFormatter::handleLink(const QString &href)
}
}
-void QtOutputFormatter::clearLastLine()
-{
- OutputFormatter::clearLastLine();
- if (!d->lastLine.isEmpty())
- d->lastLine.removeLast();
-}
-
void QtOutputFormatter::openEditor(const QString &fileName, int line, int column)
{
Core::EditorManager::openEditorAt(fileName, line, column);