From 1da46d81ee5bf4432f476134122aff7e68fd1037 Mon Sep 17 00:00:00 2001 From: dt Date: Wed, 22 Sep 2010 11:54:04 +0200 Subject: Application Output Window: Reduce the number of QPE::insertText calls By making the QtOutputFormatter smarter. If we have nothing to format as a link we do the minimal amount of insertText calls now. Task-Nr: QTCREATORBUG-2367 --- .../qt4projectmanager/qtoutputformatter.cpp | 43 +++++++++++++++------- 1 file changed, 30 insertions(+), 13 deletions(-) (limited to 'src/plugins/qt4projectmanager/qtoutputformatter.cpp') diff --git a/src/plugins/qt4projectmanager/qtoutputformatter.cpp b/src/plugins/qt4projectmanager/qtoutputformatter.cpp index 7e17e575e3..bffae06e0b 100644 --- a/src/plugins/qt4projectmanager/qtoutputformatter.cpp +++ b/src/plugins/qt4projectmanager/qtoutputformatter.cpp @@ -54,6 +54,7 @@ LinkResult QtOutputFormatter::matchLine(const QString &line) const LinkResult lr; lr.start = -1; lr.end = -1; + if (m_qmlError.indexIn(line) != -1) { lr.href = m_qmlError.cap(1); lr.start = m_qmlError.pos(1); @@ -84,9 +85,15 @@ void QtOutputFormatter::appendApplicationOutput(const QString &txt, bool onStdEr m_linkFormat.setAnchor(true); } + QTextCursor cursor(plainTextEdit()->document()); + cursor.movePosition(QTextCursor::End); + cursor.beginEditBlock(); + QString text = txt; text.remove(QLatin1Char('\r')); + QString deferedText; + int start = 0; int pos = txt.indexOf(QLatin1Char('\n')); while (pos != -1) { @@ -98,11 +105,13 @@ void QtOutputFormatter::appendApplicationOutput(const QString &txt, bool onStdEr LinkResult lr = matchLine(line); if (!lr.href.isEmpty()) { // Found something && line continuation + cursor.insertText(deferedText, format(onStdErr ? StdErrFormat : StdOutFormat)); + deferedText.clear(); clearLastLine(); - appendLine(lr, line, onStdErr); + appendLine(cursor, lr, line, onStdErr); } else { // Found nothing, just emit the new part - append(newPart, onStdErr ? StdErrFormat : StdOutFormat); + deferedText += newPart; } // Handled line continuation m_lastLine.clear(); @@ -110,11 +119,12 @@ void QtOutputFormatter::appendApplicationOutput(const QString &txt, bool onStdEr const QString line = txt.mid(start, pos - start + 1); LinkResult lr = matchLine(line); if (!lr.href.isEmpty()) { - appendLine(lr, line, onStdErr); + cursor.insertText(deferedText, format(onStdErr ? StdErrFormat : StdOutFormat)); + deferedText.clear(); + appendLine(cursor, lr, line, onStdErr); } else { - append(line, onStdErr ? StdErrFormat : StdOutFormat); + deferedText += line; } - } start = pos + 1; pos = txt.indexOf(QLatin1Char('\n'), start); @@ -129,30 +139,37 @@ void QtOutputFormatter::appendApplicationOutput(const QString &txt, bool onStdEr LinkResult lr = matchLine(m_lastLine); if (!lr.href.isEmpty()) { // Found something && line continuation + cursor.insertText(deferedText, format(onStdErr ? StdErrFormat : StdOutFormat)); + deferedText.clear(); clearLastLine(); - appendLine(lr, m_lastLine, onStdErr); + appendLine(cursor, lr, m_lastLine, onStdErr); } else { // Found nothing, just emit the new part - append(newPart, onStdErr ? StdErrFormat : StdOutFormat); + deferedText += newPart; } } else { m_lastLine = txt.mid(start); LinkResult lr = matchLine(m_lastLine); if (!lr.href.isEmpty()) { - appendLine(lr, m_lastLine, onStdErr); + cursor.insertText(deferedText, format(onStdErr ? StdErrFormat : StdOutFormat)); + deferedText.clear(); + appendLine(cursor, lr, m_lastLine, onStdErr); } else { - append(m_lastLine, onStdErr ? StdErrFormat : StdOutFormat); + deferedText += m_lastLine; } } } + cursor.insertText(deferedText, format(onStdErr ? StdErrFormat : StdOutFormat)); + // deferedText.clear(); + cursor.endEditBlock(); } -void QtOutputFormatter::appendLine(LinkResult lr, const QString &line, bool onStdErr) +void QtOutputFormatter::appendLine(QTextCursor &cursor, LinkResult lr, const QString &line, bool onStdErr) { - append(line.left(lr.start), onStdErr ? StdErrFormat : StdOutFormat); + cursor.insertText(line.left(lr.start), format(onStdErr ? StdErrFormat : StdOutFormat)); m_linkFormat.setAnchorHref(lr.href); - append(line.mid(lr.start, lr.end - lr.start), m_linkFormat); - append(line.mid(lr.end), onStdErr ? StdErrFormat : StdOutFormat); + cursor.insertText(line.mid(lr.start, lr.end - lr.start), m_linkFormat); + cursor.insertText(line.mid(lr.end), format(onStdErr ? StdErrFormat : StdOutFormat)); } void QtOutputFormatter::handleLink(const QString &href) -- cgit v1.2.1