From 7476b92e3aab063e893d7d095f456b4c3d3a4301 Mon Sep 17 00:00:00 2001 From: Barry Deeney Date: Mon, 6 May 2019 03:31:05 +0800 Subject: [PATCH] Optimized the logic for text area to not hang if there are many new log entries since the last time Debug Window was opened --- src/qt/rpcconsole.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 7f42956c1..f8ace0899 100755 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -321,8 +321,11 @@ RPCConsole::~RPCConsole() void RPCConsole::errorLogInitPos() { - // Get a QFile instance - errorLogFile = new QFile(QString::fromStdString(GetErrorLogPath().string())); + // Check if we already have the file + if (errorLogFile != NULL) { + // Get a QFile instance + errorLogFile = new QFile(QString::fromStdString(GetErrorLogPath().string())); + } // Try to open file if (!errorLogFile->open(QFile::ReadOnly | QFile::Text)) @@ -350,7 +353,10 @@ void RPCConsole::errorLogInitPos() // Move pos forward by 2 spaces errorLogFile->seek(errorLogFile->pos() + 2); - // Mark ini as done + // Clear the textarea + ui->errorLogTextBrowser->setText(""); + + // Mark init as done errorLogInitPosDone = true; } @@ -379,8 +385,12 @@ void RPCConsole::errorLogRefresh() // Check if we have lines if (logLines != "") { + // Add the new lines, purpose of duplicate moveCursor calls is + // to auto scroll to the end of the log instead of sticking to the + // top of the text area ui->errorLogTextBrowser->moveCursor(QTextCursor::End); ui->errorLogTextBrowser->textCursor().insertText(logLines); + ui->errorLogTextBrowser->moveCursor(QTextCursor::End); } // Count the lines in the UI textarea @@ -951,11 +961,13 @@ void RPCConsole::showEvent(QShowEvent *event) { QWidget::showEvent(event); + // Mark init as not done + errorLogInitPosDone = false; + // Load error log initial data errorLogRefresh(); // Start the error log timer - errorLogRefresh(); errorLogTimer->start(); if (!clientModel || !clientModel->getPeerTableModel())