Commit da038689 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge
Browse files

Closes #387: LogViewerWidget now has a checkbox to select the minimum log...

Closes #387: LogViewerWidget now has a checkbox to select the minimum log level to display. Filtering is performed in widget. Checkboxes to enable/disable each log level, however, seemed to be overkill. If one really wants such specific filtering, he/she can use the filter text box.
parent 06306ff7
......@@ -33,10 +33,10 @@ namespace campvis {
setupGUI();
_log = new BufferingLog(100, this);
_log->addCat("", true, tgt::Info);
_log->addCat("", true, tgt::Debug);
connect(_log, SIGNAL(s_messageAppended(const QString&)),
this, SLOT(appendMessage(const QString&)));
connect(_log, SIGNAL(s_messageAppended(const QString&, int)),
this, SLOT(appendMessage(const QString&, int)));
}
LogViewerWidget::~LogViewerWidget() {
......@@ -60,6 +60,21 @@ namespace campvis {
_filter_label->setBuddy(_filter_line_edit);
_controls_layout->addWidget(_filter_line_edit);
_cbLogLevel = new QComboBox(this);
_cbLogLevel->addItem("Debug", static_cast<int>(tgt::Debug));
_cbLogLevel->addItem("Info", static_cast<int>(tgt::Info));
_cbLogLevel->addItem("Warning", static_cast<int>(tgt::Warning));
_cbLogLevel->addItem("Error", static_cast<int>(tgt::Error));
_cbLogLevel->addItem("Fatal", static_cast<int>(tgt::Fatal));
_cbLogLevel->setCurrentIndex(1);
QLabel* lblLogLevel = new QLabel("Minimum Log Level:");
lblLogLevel->setBuddy(_cbLogLevel);
_controls_layout->addWidget(lblLogLevel);
_controls_layout->addWidget(_cbLogLevel);
_controls_layout->addStretch();
_clear_button = new QPushButton(tr("&Clear"), this);
......@@ -79,6 +94,7 @@ namespace campvis {
connect(_clear_button, SIGNAL(clicked()), this, SLOT(clearMessages()));
connect(_filter_line_edit, SIGNAL(textEdited(const QString&)), this, SLOT(filterLogMessages(const QString&)));
connect(_cbLogLevel, SIGNAL(currentIndexChanged(int)), this, SLOT(onLogLevelChanged(int)));
}
void LogViewerWidget::init() {
......@@ -89,16 +105,19 @@ namespace campvis {
LogMgr.removeLog(_log);
}
void LogViewerWidget::appendMessage(const QString& message)
void LogViewerWidget::appendMessage(const QString& message, int level)
{
_logMessages.push_back(message);
displayMessage(message);
LogEntry entry = { message, level };
_logMessages.push_back(entry);
displayMessage(entry);
}
void LogViewerWidget::displayMessage(const QString& message)
void LogViewerWidget::displayMessage(const LogViewerWidget::LogEntry& message)
{
if (_filterRegExp == 0 || _filterRegExp->indexIn(message) != -1) {
_logDisplay->append(message);
int filterLevel = _cbLogLevel->itemData(_cbLogLevel->currentIndex()).toInt();
if ((message._level >= filterLevel) && (_filterRegExp == 0 || _filterRegExp->indexIn(message._message) != -1)) {
_logDisplay->append(message._message);
}
}
......@@ -119,9 +138,13 @@ namespace campvis {
_logDisplay->clear();
_logHighlighter->setFilterRegExp(_filterRegExp);
for (std::deque<QString>::iterator it = _logMessages.begin(); it != _logMessages.end(); it++) {
for (std::deque<LogEntry>::iterator it = _logMessages.begin(); it != _logMessages.end(); it++) {
displayMessage(*it);
}
}
void LogViewerWidget::onLogLevelChanged(int) {
filterLogMessages(_filter_line_edit->text());
}
}
......@@ -34,6 +34,7 @@
#include "application/tools/bufferinglog.h"
#include "application/gui/loghighlighter.h"
#include <QComboBox>
#include <QLabel>
#include <QWidget>
#include <QVBoxLayout>
......@@ -49,6 +50,11 @@ namespace campvis {
Q_OBJECT;
public:
struct LogEntry {
QString _message;
int _level;
};
/**
* Creates a new DataContainerInspectorWidget.
* \param parent Parent Qt widget, may be 0 (default)
......@@ -85,7 +91,7 @@ namespace campvis {
*
* \param message message to append to the log viewer
*/
void appendMessage(const QString& message);
void appendMessage(const QString& message, int level);
private slots:
/**
......@@ -93,7 +99,7 @@ namespace campvis {
*
* \param message message to display in the log viewer
*/
void displayMessage(const QString& message);
void displayMessage(const LogEntry& message);
/**
* Delete all messages from the log viewer
......@@ -107,6 +113,12 @@ namespace campvis {
*/
void filterLogMessages(const QString& text);
/**
* Slot when _cbLogLevel has changed
* \param int current index of _cbLogLevel
*/
void onLogLevelChanged(int);
private:
QVBoxLayout* _mainLayout; ///< Main layout of this widget
QHBoxLayout* _controls_layout; ///< Layout storing this widget's controls
......@@ -114,10 +126,12 @@ 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
std::deque<LogEntry> _logMessages; ///< Queue storing a limited number of recent log messages
QTextEdit* _logDisplay; ///< Widget displaying log messages
const QRegExp* _filterRegExp; ///< Current filter regexp
LogHighlighter* _logHighlighter; ///< Highlighter for log messages
QComboBox* _cbLogLevel; ///< Minimum Log Level for Log viewer messages
};
}
......
......@@ -66,6 +66,6 @@ namespace campvis {
}
}
emit s_messageAppended(QString::fromStdString(output));
emit s_messageAppended(QString::fromStdString(output), level);
}
}
......@@ -64,8 +64,9 @@ namespace campvis {
* Signal invoked when a new message has been appended to the log.
*
* \param message the new log message
* \param level Log level
*/
void s_messageAppended(const QString& message);
void s_messageAppended(const QString& message, int level);
protected:
unsigned int _maxSize;
......
Supports Markdown
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