all repos — mgba @ ad9ea7125fbfd5e482c677768be209f30ddf6ac7

mGBA Game Boy Advance Emulator

Qt: Optimize log viewer to not mess with text rendering if hidden
Jeffrey Pfau jeffrey@endrift.com
Mon, 28 Dec 2015 04:44:16 -0500
commit

ad9ea7125fbfd5e482c677768be209f30ddf6ac7

parent

63e1875f6bdae4254992b6bcf692532d479cbdfc

2 files changed, 26 insertions(+), 6 deletions(-)

jump to
M src/platform/qt/LogView.cppsrc/platform/qt/LogView.cpp

@@ -69,7 +69,12 @@ connect(this, SIGNAL(levelsDisabled(int)), log, SLOT(disableLevels(int)));

} 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; if (m_lines > m_lineLimit) { clearLine();

@@ -140,11 +145,21 @@ clearLine();

} } +void LogView::showEvent(QShowEvent*) { + while (!m_pendingLines.isEmpty()) { + m_ui.view->appendPlainText(m_pendingLines.dequeue()); + } +} + void LogView::clearLine() { - QTextCursor cursor(m_ui.view->document()); - cursor.setPosition(0); - cursor.select(QTextCursor::BlockUnderCursor); - cursor.removeSelectedText(); - cursor.deleteChar(); + if (m_ui.view->document()->isEmpty()) { + m_pendingLines.dequeue(); + } else { + QTextCursor cursor(m_ui.view->document()); + cursor.setPosition(0); + cursor.select(QTextCursor::BlockUnderCursor); + cursor.removeSelectedText(); + cursor.deleteChar(); + } --m_lines; }
M src/platform/qt/LogView.hsrc/platform/qt/LogView.h

@@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef QGBA_LOG_VIEW #define QGBA_LOG_VIEW +#include <QQueue> #include <QWidget> #include "ui_LogView.h"

@@ -36,12 +37,16 @@

private slots: void setMaxLines(int); +protected: + virtual void showEvent(QShowEvent*) override; + private: static const int DEFAULT_LINE_LIMIT = 1000; Ui::LogView m_ui; int m_lines; int m_lineLimit; + QQueue<QString> m_pendingLines; void setLevel(int level, bool);