Commit 1da46d81 authored by dt's avatar dt
Browse files

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
parent 00caec3e
......@@ -63,24 +63,21 @@ void OutputFormatter::setPlainTextEdit(QPlainTextEdit *plainText)
void OutputFormatter::appendApplicationOutput(const QString &text, bool onStdErr)
{
append(text, onStdErr ? StdErrFormat : StdOutFormat);
QTextCursor cursor(m_plainTextEdit->document());
cursor.movePosition(QTextCursor::End);
cursor.insertText(text, format(onStdErr ? StdErrFormat : StdOutFormat));
}
void OutputFormatter::appendMessage(const QString &text, bool isError)
{
append(text, isError ? ErrorMessageFormat : NormalMessageFormat);
}
void OutputFormatter::append(const QString &text, Format format)
{
append(text, m_formats[format]);
QTextCursor cursor(m_plainTextEdit->document());
cursor.movePosition(QTextCursor::End);
cursor.insertText(text, format(isError ? ErrorMessageFormat : NormalMessageFormat));
}
void OutputFormatter::append(const QString &text, const QTextCharFormat &format)
QTextCharFormat OutputFormatter::format(Format format)
{
QTextCursor cursor(m_plainTextEdit->document());
cursor.movePosition(QTextCursor::End);
cursor.insertText(text, format);
return m_formats[format];
}
void OutputFormatter::clearLastLine()
......
......@@ -68,9 +68,8 @@ protected:
};
void initFormats();
void append(const QString &text, Format format);
void append(const QString &text, const QTextCharFormat &format);
void clearLastLine();
QTextCharFormat format(Format format);
private:
QPlainTextEdit *m_plainTextEdit;
......
......@@ -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)
......
......@@ -57,7 +57,7 @@ public:
private:
LinkResult matchLine(const QString &line) const;
void appendLine(LinkResult lr, const QString &line, bool onStdError);
void appendLine(QTextCursor & cursor, LinkResult lr, const QString &line, bool onStdError);
QRegExp m_qmlError;
QRegExp m_qtError;
......@@ -66,6 +66,7 @@ private:
QWeakPointer<Qt4Project> m_project;
QTextCharFormat m_linkFormat;
QString m_lastLine;
QString m_deferedText;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment