From 145bc8467b9f4271ca15654bc4bc6f7a8bc816b6 Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 19 Aug 2010 08:14:00 +0000 Subject: Added filter. --- client/debug.cc | 31 +++++++++++++++++++++++++++---- client/debug.h | 4 ++++ 2 files changed, 31 insertions(+), 4 deletions(-) (limited to 'client') diff --git a/client/debug.cc b/client/debug.cc index 1507b2e..67608a3 100644 --- a/client/debug.cc +++ b/client/debug.cc @@ -33,6 +33,11 @@ #include #include #include +#include +#include +#include + +#include static const char * const class_str[] = { "debug", "error", "warn", "log" }; @@ -82,6 +87,18 @@ DebugWindow::DebugWindow() connect(a, SIGNAL(toggled(bool)), this, SLOT(log_toggled(bool))); a->setChecked(true); + QWidgetAction *wa = new QWidgetAction(toolbar2); + wa->setDefaultWidget(new QLabel("Filter:")); + toolbar2->addAction(wa); + + wa = new QWidgetAction(toolbar2); + QLineEdit *fe = new QLineEdit(); + wa->setDefaultWidget(fe); + toolbar2->addAction(wa); + connect(fe, SIGNAL(textChanged(QString)), + this, SLOT(filter_changed(QString))); + fe->setText(".*"); + QSettings settings("Aasimon.org", "Pracro"); settings.beginGroup("DebugWindow"); resize(settings.value("size", QSize(700, 800)).toSize()); @@ -107,6 +124,11 @@ void DebugWindow::clear() lst->clear(); } +void DebugWindow::filter_changed(QString f) +{ + filter = f; +} + void DebugWindow::debug_toggled(bool on) { show_debug = on; @@ -135,8 +157,6 @@ void DebugWindow::log(const char *func, const char *file, const int line, if(cl == _warn && show_warning == false) return; // Ignore if(cl == _log && show_log == false) return; // Ignore - timer.stop(); - // Remove trailing newlines. while(msg.endsWith("\n")) msg = msg.left(msg.length() - 1); @@ -146,15 +166,18 @@ void DebugWindow::log(const char *func, const char *file, const int line, class_str[(unsigned)cl], file, func, line); txt += " : " + msg; + QRegExp r(filter); + if(r.indexIn(txt) == -1) return; + + timer.stop(); + QListWidgetItem *item = new QListWidgetItem(); item->setText(txt); if(cl == _error) item->setBackground(QBrush(QColor(230, 200, 200))); if(cl == _warn) item->setBackground(QBrush(QColor(200, 200, 230))); if(cl == _log) item->setBackground(QBrush(QColor(200, 230, 200))); - lst->addItem(item); - // lst->scrollToBottom(); timer.start(100); } diff --git a/client/debug.h b/client/debug.h index e583afc..e75dad0 100644 --- a/client/debug.h +++ b/client/debug.h @@ -31,6 +31,7 @@ #include #include #include +#include typedef enum { _debug, @@ -56,11 +57,14 @@ private slots: void error_toggled(bool); void warning_toggled(bool); void log_toggled(bool); + void filter_changed(QString); private: QListWidget *lst; QTimer timer; + QString filter; + bool show_debug; bool show_error; bool show_warning; -- cgit v1.2.3