Commit 209db5a6 authored by grunau's avatar grunau
Browse files

Implement log message filtering

Typing text into the log viewer's QLineEdit now causes all log
messages that don't contain that text to be filtered out. To
support this, message caching had to be moved to the log viewer.

git-svn-id: https://camplinux.in.tum.de/svn/campvis/branches/gui-redux@517 bb408c1c-ae56-11e1-83d9-df6b3e0c105e
parent bdb90ce7
......@@ -40,7 +40,7 @@ namespace campvis {
_log->addCat("", true);
connect(_log, SIGNAL(s_messageAppended(const QString&)),
_logDisplay, SLOT(append(const QString&)));
this, SLOT(appendMessage(const QString&)));
}
LogViewerWidget::~LogViewerWidget() {
......@@ -72,7 +72,8 @@ namespace campvis {
_logDisplay->setReadOnly(true);
_mainLayout->addWidget(_logDisplay);
connect(_clear_button, SIGNAL(clicked()), _logDisplay, SLOT(clear()));
connect(_clear_button, SIGNAL(clicked()), this, SLOT(clearMessages()));
connect(_filter_line_edit, SIGNAL(textEdited(const QString&)), this, SLOT(filterLogMessages(const QString&)));
}
void LogViewerWidget::init() {
......@@ -83,4 +84,31 @@ namespace campvis {
LogMgr.removeLog(_log);
}
void LogViewerWidget::appendMessage(const QString& message)
{
_logDisplay->append(message);
_logMessages.push_back(message);
}
void LogViewerWidget::clearMessages()
{
_logDisplay->clear();
_logMessages.clear();
}
void LogViewerWidget::filterLogMessages(const QString& text)
{
QRegExp regexp = QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString);
_logDisplay->clear();
QTextDocument *logDocument = _logDisplay->document();
QTextCursor cursor = QTextCursor(logDocument);
for (std::deque<QString>::iterator it = _logMessages.begin(); it != _logMessages.end(); it++) {
if (regexp.indexIn(*it) != -1) {
cursor.insertText(*it);
cursor.insertText("\n");
}
}
}
}
......@@ -74,15 +74,32 @@ namespace campvis {
*/
void deinit();
signals:
void dataContainerChanged(const QString&);
protected:
/**
* Setup the the log viewer's GUI
*/
void setupGUI();
private slots:
/**
* Append the given message to the log viewer
*
* \param message message to append to the log viewer
*/
void appendMessage(const QString& message);
/**
* Delete all messages from the log viewer
*/
void clearMessages();
/**
* Filter out log messages that don't contain the given text.
*
* \param text text to look for in log messages
*/
void filterLogMessages(const QString& text);
private:
QVBoxLayout* _mainLayout; ///< Main layout of this widget
QHBoxLayout* _controls_layout; ///< Layout storing this widget's controls
......@@ -90,6 +107,7 @@ namespace campvis {
QLineEdit* _filter_line_edit; ///< Text field where filter terms are entered
QLabel* _filter_label; ///< Button used for clearing the log display
BufferingLog* _log; ///< Log buffering messages
std::deque<QString> _logMessages; ///< Queue storing a limited number of recent log messages
QTextEdit* _logDisplay; ///< Widget displaying log messages
};
}
......
......@@ -15,7 +15,7 @@ namespace campvis {
showLevel_ = showLevel;
}
void BufferingLog::logFiltered(const std::string& cat, LogLevel level, const std::string& msg,
void BufferingLog::logFiltered(const std::string& cat, tgt::LogLevel level, const std::string& msg,
const std::string& /*extendedInfo*/)
{
std::string output = "";
......
......@@ -7,14 +7,12 @@
#include <deque>
#include <QObject>
using namespace tgt;
namespace campvis {
/**
* BufferingLog stores up to the specified number of messages in memory.
*/
class BufferingLog : public QObject, public Log {
class BufferingLog : public QObject, public tgt::Log {
Q_OBJECT
......@@ -49,7 +47,7 @@ namespace campvis {
unsigned int _maxSize;
tbb::mutex _localMutex;
std::deque<std::string> _buffer;
void logFiltered(const std::string &cat, LogLevel level, const std::string& msg, const std::string& extendedInfo="");
void logFiltered(const std::string &cat, tgt::LogLevel level, const std::string& msg, const std::string& extendedInfo="");
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment