Skip to content

Commit

Permalink
Optimized the logic for text area to not hang if there are many new l…
Browse files Browse the repository at this point in the history
…og entries since the last time Debug Window was opened
  • Loading branch information
mxaddict committed May 5, 2019
1 parent cf3da37 commit 3b7406f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 3b7406f

Please sign in to comment.