From 3c4c830e202c70e714472ab6a705f63e450ce4a5 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 19 Apr 2021 20:14:08 +0200 Subject: [PATCH] Qt: Speed up Log Viewer --- rpcs3/rpcs3qt/log_viewer.cpp | 17 +++++++---------- rpcs3/rpcs3qt/log_viewer.h | 12 ++++++------ rpcs3/rpcs3qt/main_window.cpp | 1 + 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/rpcs3/rpcs3qt/log_viewer.cpp b/rpcs3/rpcs3qt/log_viewer.cpp index f07a163a0d..fdb7a9ad26 100644 --- a/rpcs3/rpcs3qt/log_viewer.cpp +++ b/rpcs3/rpcs3qt/log_viewer.cpp @@ -5,6 +5,7 @@ #include "syntax_highlighter.h" #include "find_dialog.h" +#include #include #include #include @@ -35,7 +36,7 @@ log_viewer::log_viewer(std::shared_ptr gui_settings) m_path_last = m_gui_settings->GetValue(gui::fd_log_viewer).toString(); - m_log_text = new QTextEdit(this); + m_log_text = new QPlainTextEdit(this); m_log_text->setReadOnly(true); m_log_text->setContextMenuPolicy(Qt::CustomContextMenu); m_log_text->setWordWrapMode(QTextOption::NoWrap); @@ -51,8 +52,6 @@ log_viewer::log_viewer(std::shared_ptr gui_settings) setLayout(layout); connect(m_log_text, &QWidget::customContextMenuRequested, this, &log_viewer::show_context_menu); - - show_log(); } void log_viewer::show_context_menu(const QPoint& pos) @@ -79,7 +78,7 @@ void log_viewer::show_context_menu(const QPoint& pos) show_log(); }); - const auto obj = qobject_cast(sender()); + const auto obj = qobject_cast(sender()); QPoint origin; @@ -103,6 +102,8 @@ void log_viewer::show_log() const } m_log_text->clear(); + m_log_text->setPlainText(tr("Loading file...")); + QApplication::processEvents(); if (QFile file(m_path_last); file.exists() && file.open(QIODevice::ReadOnly | QIODevice::Text)) @@ -110,17 +111,13 @@ void log_viewer::show_log() const m_gui_settings->SetValue(gui::fd_log_viewer, m_path_last); QTextStream stream(&file); - - while (!stream.atEnd()) - { - m_log_text->append(stream.readLine()); - } - + m_log_text->setPlainText(stream.readAll()); file.close(); } else { gui_log.error("log_viewer: Failed to open %s", sstr(m_path_last)); + m_log_text->setPlainText(tr("Failed to open '%0'").arg(m_path_last)); } } diff --git a/rpcs3/rpcs3qt/log_viewer.h b/rpcs3/rpcs3qt/log_viewer.h index 9b18cf6fe3..16cf768191 100644 --- a/rpcs3/rpcs3qt/log_viewer.h +++ b/rpcs3/rpcs3qt/log_viewer.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -13,22 +13,22 @@ class log_viewer : public QWidget { Q_OBJECT +public: + explicit log_viewer(std::shared_ptr gui_settings); + void show_log() const; + private Q_SLOTS: void show_context_menu(const QPoint& pos); private: - void show_log() const; bool is_valid_file(const QMimeData& md, bool save = false); std::shared_ptr m_gui_settings; QString m_path_last; - QTextEdit* m_log_text; + QPlainTextEdit* m_log_text; LogHighlighter* m_log_highlighter; std::unique_ptr m_find_dialog; -public: - explicit log_viewer(std::shared_ptr settings); - protected: void dropEvent(QDropEvent* ev) override; void dragEnterEvent(QDragEnterEvent* ev) override; diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 1cfca1dd59..1962aa4ec3 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -2113,6 +2113,7 @@ void main_window::CreateConnects() { log_viewer* viewer = new log_viewer(m_gui_settings); viewer->show(); + viewer->show_log(); }); connect(ui->toolskernel_explorerAct, &QAction::triggered, this, [this]