forked from qt-creator/qt-creator
Core: Use a fixed cursor in OutputWindow
Callgrind shows that movePosition is very expansive. Change-Id: I84fbb59eb10b97e8222b91604b29a420179cf3e2 Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
5044056296
commit
a70a886286
@@ -49,7 +49,7 @@ namespace Internal {
|
|||||||
class OutputWindowPrivate
|
class OutputWindowPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OutputWindowPrivate()
|
OutputWindowPrivate(QTextDocument *document)
|
||||||
: outputWindowContext(0)
|
: outputWindowContext(0)
|
||||||
, formatter(0)
|
, formatter(0)
|
||||||
, enforceNewline(false)
|
, enforceNewline(false)
|
||||||
@@ -57,6 +57,7 @@ public:
|
|||||||
, linksActive(true)
|
, linksActive(true)
|
||||||
, mousePressed(false)
|
, mousePressed(false)
|
||||||
, maxLineCount(100000)
|
, maxLineCount(100000)
|
||||||
|
, cursor(document)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +75,7 @@ public:
|
|||||||
bool linksActive;
|
bool linksActive;
|
||||||
bool mousePressed;
|
bool mousePressed;
|
||||||
int maxLineCount;
|
int maxLineCount;
|
||||||
|
QTextCursor cursor;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
@@ -82,7 +84,7 @@ public:
|
|||||||
|
|
||||||
OutputWindow::OutputWindow(Context context, QWidget *parent)
|
OutputWindow::OutputWindow(Context context, QWidget *parent)
|
||||||
: QPlainTextEdit(parent)
|
: QPlainTextEdit(parent)
|
||||||
, d(new Internal::OutputWindowPrivate)
|
, d(new Internal::OutputWindowPrivate(document()))
|
||||||
{
|
{
|
||||||
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||||
//setCenterOnScroll(false);
|
//setCenterOnScroll(false);
|
||||||
@@ -291,18 +293,18 @@ void OutputWindow::appendText(const QString &textIn, const QTextCharFormat &form
|
|||||||
if (d->maxLineCount > 0 && document()->blockCount() >= d->maxLineCount)
|
if (d->maxLineCount > 0 && document()->blockCount() >= d->maxLineCount)
|
||||||
return;
|
return;
|
||||||
const bool atBottom = isScrollbarAtBottom();
|
const bool atBottom = isScrollbarAtBottom();
|
||||||
QTextCursor cursor = QTextCursor(document());
|
if (!d->cursor.atEnd())
|
||||||
cursor.movePosition(QTextCursor::End);
|
d->cursor.movePosition(QTextCursor::End);
|
||||||
cursor.beginEditBlock();
|
d->cursor.beginEditBlock();
|
||||||
cursor.insertText(doNewlineEnforcement(text), format);
|
d->cursor.insertText(doNewlineEnforcement(text), format);
|
||||||
|
|
||||||
if (d->maxLineCount > 0 && document()->blockCount() >= d->maxLineCount) {
|
if (d->maxLineCount > 0 && document()->blockCount() >= d->maxLineCount) {
|
||||||
QTextCharFormat tmp;
|
QTextCharFormat tmp;
|
||||||
tmp.setFontWeight(QFont::Bold);
|
tmp.setFontWeight(QFont::Bold);
|
||||||
cursor.insertText(doNewlineEnforcement(tr("Additional output omitted") + QLatin1Char('\n')), tmp);
|
d->cursor.insertText(doNewlineEnforcement(tr("Additional output omitted") + QLatin1Char('\n')), tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.endEditBlock();
|
d->cursor.endEditBlock();
|
||||||
if (atBottom)
|
if (atBottom)
|
||||||
scrollToBottom();
|
scrollToBottom();
|
||||||
}
|
}
|
||||||
@@ -329,11 +331,11 @@ void OutputWindow::scrollToBottom()
|
|||||||
|
|
||||||
void OutputWindow::grayOutOldContent()
|
void OutputWindow::grayOutOldContent()
|
||||||
{
|
{
|
||||||
QTextCursor cursor = textCursor();
|
if (!d->cursor.atEnd())
|
||||||
cursor.movePosition(QTextCursor::End);
|
d->cursor.movePosition(QTextCursor::End);
|
||||||
QTextCharFormat endFormat = cursor.charFormat();
|
QTextCharFormat endFormat = d->cursor.charFormat();
|
||||||
|
|
||||||
cursor.select(QTextCursor::Document);
|
d->cursor.select(QTextCursor::Document);
|
||||||
|
|
||||||
QTextCharFormat format;
|
QTextCharFormat format;
|
||||||
const QColor bkgColor = palette().base().color();
|
const QColor bkgColor = palette().base().color();
|
||||||
@@ -343,11 +345,12 @@ void OutputWindow::grayOutOldContent()
|
|||||||
format.setForeground(QColor((bkgFactor * bkgColor.red() + fgdFactor * fgdColor.red()),
|
format.setForeground(QColor((bkgFactor * bkgColor.red() + fgdFactor * fgdColor.red()),
|
||||||
(bkgFactor * bkgColor.green() + fgdFactor * fgdColor.green()),
|
(bkgFactor * bkgColor.green() + fgdFactor * fgdColor.green()),
|
||||||
(bkgFactor * bkgColor.blue() + fgdFactor * fgdColor.blue()) ));
|
(bkgFactor * bkgColor.blue() + fgdFactor * fgdColor.blue()) ));
|
||||||
cursor.mergeCharFormat(format);
|
d->cursor.mergeCharFormat(format);
|
||||||
|
|
||||||
cursor.movePosition(QTextCursor::End);
|
if (!d->cursor.atEnd())
|
||||||
cursor.setCharFormat(endFormat);
|
d->cursor.movePosition(QTextCursor::End);
|
||||||
cursor.insertBlock(QTextBlockFormat());
|
d->cursor.setCharFormat(endFormat);
|
||||||
|
d->cursor.insertBlock(QTextBlockFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OutputWindow::enableUndoRedo()
|
void OutputWindow::enableUndoRedo()
|
||||||
|
Reference in New Issue
Block a user