Clear backlog automatically
Jeffrey Pfau jeffrey@endrift.com
Mon, 13 Oct 2014 02:43:27 -0700
3 files changed,
29 insertions(+),
23 deletions(-)
M
src/platform/qt/LogView.cpp
→
src/platform/qt/LogView.cpp
@@ -1,5 +1,8 @@
#include "LogView.h" +#include <QTextBlock> +#include <QTextCursor> + using namespace QGBA; LogView::LogView(QWidget* parent)@@ -13,7 +16,9 @@ connect(m_ui.levelWarn, SIGNAL(toggled(bool)), this, SLOT(setLevelWarn(bool)));
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 @@ if (!(level & m_logLevel)) {
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 @@ return tr("GAME ERROR");
} return QString(); } + +void LogView::clearLine() { + QTextCursor cursor(m_ui.view->document()); + cursor.setPosition(0); + cursor.select(QTextCursor::BlockUnderCursor); + cursor.removeSelectedText(); + cursor.deleteChar(); + --m_lines; +}
M
src/platform/qt/LogView.h
→
src/platform/qt/LogView.h
@@ -31,12 +31,17 @@ void setLevelFatal(bool);
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(); }; }
M
src/platform/qt/LogView.ui
→
src/platform/qt/LogView.ui
@@ -28,7 +28,7 @@ <property name="text">
<string>Debug</string> </property> <property name="checked"> - <bool>true</bool> + <bool>false</bool> </property> </widget> </item>@@ -38,7 +38,7 @@ <property name="text">
<string>Stub</string> </property> <property name="checked"> - <bool>true</bool> + <bool>false</bool> </property> </widget> </item>@@ -48,7 +48,7 @@ <property name="text">
<string>Info</string> </property> <property name="checked"> - <bool>true</bool> + <bool>false</bool> </property> </widget> </item>@@ -104,7 +104,7 @@ <property name="text">
<string>Game Error</string> </property> <property name="checked"> - <bool>true</bool> + <bool>false</bool> </property> </widget> </item>@@ -143,22 +143,5 @@ </item>
</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>