Core: improve logger performance

Messages can be rather huge. Limit the length to avoid costly
background painting of what is not visible at all.
Full message can still be seen in tool tips or when copying
or saving the logs.

Also postpone scrolling to bottom of the view since it triggers
layouting the text.

Change-Id: I13bf136a32f0f51f636c89cea85a5be23cd4fe9a
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Stenger
2022-01-17 08:07:08 +01:00
parent 479c393009
commit 64b6aca212

View File

@@ -385,7 +385,11 @@ static QVariant logEntryDataAccessor(const LogEntry &entry, int column, int role
case 0: return entry.timestamp;
case 1: return entry.category;
case 2: return entry.type;
case 3: return entry.message;
case 3: {
if (role == Qt::ToolTipRole)
return entry.message;
return entry.message.left(1000);
}
}
}
if (role == Qt::TextAlignmentRole)
@@ -458,10 +462,9 @@ LoggingViewManagerWidget::LoggingViewManagerWidget(QWidget *parent)
m_logModel->setDataAccessor(&logEntryDataAccessor);
m_logView->setModel(m_logModel);
horizontal->addWidget(m_logView);
m_logView->setUniformRowHeights(false);
m_logView->setUniformRowHeights(true);
m_logView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_logView->setFrameStyle(QFrame::Box);
m_logView->setTextElideMode(Qt::ElideNone);
m_logView->setAttribute(Qt::WA_MacShowFocusRect, false);
m_logView->setSelectionMode(QAbstractItemView::ExtendedSelection);
m_logView->setColumnHidden(2, true);
@@ -471,7 +474,6 @@ LoggingViewManagerWidget::LoggingViewManagerWidget(QWidget *parent)
m_categoryView->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
m_categoryView->setUniformRowHeights(true);
m_categoryView->setFrameStyle(QFrame::Box);
m_categoryView->setTextElideMode(Qt::ElideNone);
m_categoryView->setAttribute(Qt::WA_MacShowFocusRect, false);
m_categoryView->setSelectionMode(QAbstractItemView::SingleSelection);
m_categoryView->setContextMenuPolicy(Qt::CustomContextMenu);
@@ -491,11 +493,15 @@ LoggingViewManagerWidget::LoggingViewManagerWidget(QWidget *parent)
resize(800, 300);
connect(m_manager, &LoggingViewManager::receivedLog,
this, [this, autoScroll](const QString &timestamp, const QString &type,
const QString &category, const QString &msg) {
this, [this](const QString &timestamp,
const QString &type,
const QString &category,
const QString &msg) {
if (m_logModel->rowCount() >= 1000000) // limit log to 1000000 items
m_logModel->destroyItem(m_logModel->itemForIndex(m_logModel->index(0, 0)));
m_logModel->appendItem(LogEntry{timestamp, type, category, msg});
}, Qt::QueuedConnection);
connect(m_logModel, &QAbstractItemModel::rowsInserted, this, [this, autoScroll]() {
if (autoScroll->isChecked())
m_logView->scrollToBottom();
}, Qt::QueuedConnection);