Merge pull request #2112 from TheKodeToad/log-performance
This commit is contained in:
commit
e738b78044
@ -36,6 +36,7 @@
|
|||||||
#include "LogView.h"
|
#include "LogView.h"
|
||||||
#include <QScrollBar>
|
#include <QScrollBar>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
|
#include <QTextDocumentFragment>
|
||||||
|
|
||||||
LogView::LogView(QWidget* parent) : QPlainTextEdit(parent)
|
LogView::LogView(QWidget* parent) : QPlainTextEdit(parent)
|
||||||
{
|
{
|
||||||
@ -117,6 +118,9 @@ void LogView::rowsAboutToBeInserted(const QModelIndex& parent, int first, int la
|
|||||||
|
|
||||||
void LogView::rowsInserted(const QModelIndex& parent, int first, int last)
|
void LogView::rowsInserted(const QModelIndex& parent, int first, int last)
|
||||||
{
|
{
|
||||||
|
QTextDocument document;
|
||||||
|
QTextCursor cursor(&document);
|
||||||
|
|
||||||
for (int i = first; i <= last; i++) {
|
for (int i = first; i <= last; i++) {
|
||||||
auto idx = m_model->index(i, 0, parent);
|
auto idx = m_model->index(i, 0, parent);
|
||||||
auto text = m_model->data(idx, Qt::DisplayRole).toString();
|
auto text = m_model->data(idx, Qt::DisplayRole).toString();
|
||||||
@ -133,11 +137,16 @@ void LogView::rowsInserted(const QModelIndex& parent, int first, int last)
|
|||||||
if (bg.isValid()) {
|
if (bg.isValid()) {
|
||||||
format.setBackground(bg.value<QColor>());
|
format.setBackground(bg.value<QColor>());
|
||||||
}
|
}
|
||||||
auto workCursor = textCursor();
|
cursor.movePosition(QTextCursor::End);
|
||||||
workCursor.movePosition(QTextCursor::End);
|
cursor.insertText(text, format);
|
||||||
workCursor.insertText(text, format);
|
cursor.insertBlock();
|
||||||
workCursor.insertBlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QTextDocumentFragment fragment(&document);
|
||||||
|
QTextCursor workCursor = textCursor();
|
||||||
|
workCursor.movePosition(QTextCursor::End);
|
||||||
|
workCursor.insertFragment(fragment);
|
||||||
|
|
||||||
if (m_scroll && !m_scrolling) {
|
if (m_scroll && !m_scrolling) {
|
||||||
m_scrolling = true;
|
m_scrolling = true;
|
||||||
QMetaObject::invokeMethod(this, "scrollToBottom", Qt::QueuedConnection);
|
QMetaObject::invokeMethod(this, "scrollToBottom", Qt::QueuedConnection);
|
||||||
|
Loading…
Reference in New Issue
Block a user