mirror of https://github.com/mgba-emu/mgba.git
Qt: Optimize log viewer to not mess with text rendering if hidden
This commit is contained in:
parent
63e1875f6b
commit
ad9ea7125f
|
@ -69,7 +69,12 @@ LogView::LogView(LogController* log, QWidget* parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogView::postLog(int level, const QString& log) {
|
void LogView::postLog(int level, const QString& log) {
|
||||||
m_ui.view->appendPlainText(QString("%1:\t%2").arg(LogController::toString(level)).arg(log));
|
QString line = QString("%1:\t%2").arg(LogController::toString(level)).arg(log);
|
||||||
|
if (isVisible()) {
|
||||||
|
m_ui.view->appendPlainText(line);
|
||||||
|
} else {
|
||||||
|
m_pendingLines.enqueue(line);
|
||||||
|
}
|
||||||
++m_lines;
|
++m_lines;
|
||||||
if (m_lines > m_lineLimit) {
|
if (m_lines > m_lineLimit) {
|
||||||
clearLine();
|
clearLine();
|
||||||
|
@ -140,11 +145,21 @@ void LogView::setMaxLines(int limit) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LogView::showEvent(QShowEvent*) {
|
||||||
|
while (!m_pendingLines.isEmpty()) {
|
||||||
|
m_ui.view->appendPlainText(m_pendingLines.dequeue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LogView::clearLine() {
|
void LogView::clearLine() {
|
||||||
|
if (m_ui.view->document()->isEmpty()) {
|
||||||
|
m_pendingLines.dequeue();
|
||||||
|
} else {
|
||||||
QTextCursor cursor(m_ui.view->document());
|
QTextCursor cursor(m_ui.view->document());
|
||||||
cursor.setPosition(0);
|
cursor.setPosition(0);
|
||||||
cursor.select(QTextCursor::BlockUnderCursor);
|
cursor.select(QTextCursor::BlockUnderCursor);
|
||||||
cursor.removeSelectedText();
|
cursor.removeSelectedText();
|
||||||
cursor.deleteChar();
|
cursor.deleteChar();
|
||||||
|
}
|
||||||
--m_lines;
|
--m_lines;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#ifndef QGBA_LOG_VIEW
|
#ifndef QGBA_LOG_VIEW
|
||||||
#define QGBA_LOG_VIEW
|
#define QGBA_LOG_VIEW
|
||||||
|
|
||||||
|
#include <QQueue>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "ui_LogView.h"
|
#include "ui_LogView.h"
|
||||||
|
@ -36,12 +37,16 @@ public slots:
|
||||||
private slots:
|
private slots:
|
||||||
void setMaxLines(int);
|
void setMaxLines(int);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void showEvent(QShowEvent*) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int DEFAULT_LINE_LIMIT = 1000;
|
static const int DEFAULT_LINE_LIMIT = 1000;
|
||||||
|
|
||||||
Ui::LogView m_ui;
|
Ui::LogView m_ui;
|
||||||
int m_lines;
|
int m_lines;
|
||||||
int m_lineLimit;
|
int m_lineLimit;
|
||||||
|
QQueue<QString> m_pendingLines;
|
||||||
|
|
||||||
void setLevel(int level, bool);
|
void setLevel(int level, bool);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue