mirror of https://github.com/mgba-emu/mgba.git
Clear backlog automatically
This commit is contained in:
parent
fa255dc808
commit
d3a4c027e4
|
@ -1,5 +1,8 @@
|
||||||
#include "LogView.h"
|
#include "LogView.h"
|
||||||
|
|
||||||
|
#include <QTextBlock>
|
||||||
|
#include <QTextCursor>
|
||||||
|
|
||||||
using namespace QGBA;
|
using namespace QGBA;
|
||||||
|
|
||||||
LogView::LogView(QWidget* parent)
|
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.levelError, SIGNAL(toggled(bool)), this, SLOT(setLevelError(bool)));
|
||||||
connect(m_ui.levelFatal, SIGNAL(toggled(bool)), this, SLOT(setLevelFatal(bool)));
|
connect(m_ui.levelFatal, SIGNAL(toggled(bool)), this, SLOT(setLevelFatal(bool)));
|
||||||
connect(m_ui.levelGameError, SIGNAL(toggled(bool)), this, SLOT(setLevelGameError(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) {
|
void LogView::postLog(int level, const QString& log) {
|
||||||
|
@ -21,6 +26,10 @@ void LogView::postLog(int level, const QString& log) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_ui.view->appendPlainText(QString("%1:\t%2").arg(toString(level)).arg(log));
|
m_ui.view->appendPlainText(QString("%1:\t%2").arg(toString(level)).arg(log));
|
||||||
|
++m_lines;
|
||||||
|
if (m_lines > LINE_LIMIT) {
|
||||||
|
clearLine();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LogView::clear() {
|
void LogView::clear() {
|
||||||
|
@ -96,3 +105,12 @@ QString LogView::toString(int level) {
|
||||||
}
|
}
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LogView::clearLine() {
|
||||||
|
QTextCursor cursor(m_ui.view->document());
|
||||||
|
cursor.setPosition(0);
|
||||||
|
cursor.select(QTextCursor::BlockUnderCursor);
|
||||||
|
cursor.removeSelectedText();
|
||||||
|
cursor.deleteChar();
|
||||||
|
--m_lines;
|
||||||
|
}
|
||||||
|
|
|
@ -31,12 +31,17 @@ private slots:
|
||||||
void setLevelGameError(bool);
|
void setLevelGameError(bool);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static const int LINE_LIMIT = 1000;
|
||||||
|
|
||||||
Ui::LogView m_ui;
|
Ui::LogView m_ui;
|
||||||
int m_logLevel;
|
int m_logLevel;
|
||||||
|
int m_lines;
|
||||||
|
|
||||||
static QString toString(int level);
|
static QString toString(int level);
|
||||||
void setLevel(int level) { m_logLevel |= level; }
|
void setLevel(int level) { m_logLevel |= level; }
|
||||||
void clearLevel(int level) { m_logLevel &= ~level; }
|
void clearLevel(int level) { m_logLevel &= ~level; }
|
||||||
|
|
||||||
|
void clearLine();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
<string>Debug</string>
|
<string>Debug</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checked">
|
<property name="checked">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
<string>Stub</string>
|
<string>Stub</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checked">
|
<property name="checked">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -48,7 +48,7 @@
|
||||||
<string>Info</string>
|
<string>Info</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checked">
|
<property name="checked">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
<string>Game Error</string>
|
<string>Game Error</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checked">
|
<property name="checked">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
@ -143,22 +143,5 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections>
|
<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>
|
|
||||||
</ui>
|
</ui>
|
||||||
|
|
Loading…
Reference in New Issue