1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

Qt: Speed up Log Viewer

This commit is contained in:
Megamouse 2021-04-19 20:14:08 +02:00
parent 0c9c481cee
commit 3c4c830e20
3 changed files with 14 additions and 16 deletions

View File

@ -5,6 +5,7 @@
#include "syntax_highlighter.h"
#include "find_dialog.h"
#include <QApplication>
#include <QMenu>
#include <QFile>
#include <QFileDialog>
@ -35,7 +36,7 @@ log_viewer::log_viewer(std::shared_ptr<gui_settings> 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> 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<QTextEdit*>(sender());
const auto obj = qobject_cast<QPlainTextEdit*>(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));
}
}

View File

@ -1,6 +1,6 @@
#pragma once
#include <QTextEdit>
#include <QPlainTextEdit>
#include <QDropEvent>
#include <memory>
@ -13,22 +13,22 @@ class log_viewer : public QWidget
{
Q_OBJECT
public:
explicit log_viewer(std::shared_ptr<gui_settings> 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<gui_settings> m_gui_settings;
QString m_path_last;
QTextEdit* m_log_text;
QPlainTextEdit* m_log_text;
LogHighlighter* m_log_highlighter;
std::unique_ptr<find_dialog> m_find_dialog;
public:
explicit log_viewer(std::shared_ptr<gui_settings> settings);
protected:
void dropEvent(QDropEvent* ev) override;
void dragEnterEvent(QDragEnterEvent* ev) override;

View File

@ -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]