Clear backlog automatically

This commit is contained in:
Jeffrey Pfau 2014-10-13 02:43:27 -07:00
parent fa255dc808
commit d3a4c027e4
3 changed files with 29 additions and 23 deletions

View File

@ -1,5 +1,8 @@
#include "LogView.h"
#include <QTextBlock>
#include <QTextCursor>
using namespace QGBA;
LogView::LogView(QWidget* parent)
@ -13,7 +16,9 @@ LogView::LogView(QWidget* parent)
connect(m_ui.levelError, SIGNAL(toggled(bool)), this, SLOT(setLevelError(bool)));
connect(m_ui.levelFatal, SIGNAL(toggled(bool)), this, SLOT(setLevelFatal(bool)));
connect(m_ui.levelGameError, SIGNAL(toggled(bool)), this, SLOT(setLevelGameError(bool)));
m_logLevel = -1;
connect(m_ui.clear, SIGNAL(clicked()), this, SLOT(clear()));
m_logLevel = GBA_LOG_WARN | GBA_LOG_ERROR | GBA_LOG_FATAL;
m_lines = 0;
}
void LogView::postLog(int level, const QString& log) {
@ -21,6 +26,10 @@ void LogView::postLog(int level, const QString& log) {
return;
}
m_ui.view->appendPlainText(QString("%1:\t%2").arg(toString(level)).arg(log));
++m_lines;
if (m_lines > LINE_LIMIT) {
clearLine();
}
}
void LogView::clear() {
@ -96,3 +105,12 @@ QString LogView::toString(int level) {
}
return QString();
}
void LogView::clearLine() {
QTextCursor cursor(m_ui.view->document());
cursor.setPosition(0);
cursor.select(QTextCursor::BlockUnderCursor);
cursor.removeSelectedText();
cursor.deleteChar();
--m_lines;
}

View File

@ -31,12 +31,17 @@ private slots:
void setLevelGameError(bool);
private:
static const int LINE_LIMIT = 1000;
Ui::LogView m_ui;
int m_logLevel;
int m_lines;
static QString toString(int level);
void setLevel(int level) { m_logLevel |= level; }
void clearLevel(int level) { m_logLevel &= ~level; }
void clearLine();
};
}

View File

@ -28,7 +28,7 @@
<string>Debug</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@ -38,7 +38,7 @@
<string>Stub</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@ -48,7 +48,7 @@
<string>Info</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@ -104,7 +104,7 @@
<string>Game Error</string>
</property>
<property name="checked">
<bool>true</bool>
<bool>false</bool>
</property>
</widget>
</item>
@ -143,22 +143,5 @@
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>clear</sender>
<signal>clicked()</signal>
<receiver>view</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>98</x>
<y>376</y>
</hint>
<hint type="destinationlabel">
<x>299</x>
<y>311</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>