Commit febda439 authored by Julien Wintz's avatar Julien Wintz
Browse files

Updated logging layer. Adding filtering for log widget.

parent abcc4761
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:16:32 2012 (+0100)
* Version: $Id$
* Last-Updated: Mon Mar 5 13:02:15 2012 (+0100)
* Last-Updated: Tue Mar 6 11:03:13 2012 (+0100)
* By: Julien Wintz
* Update #: 73
* Update #: 84
*/
/* Commentary:
......@@ -36,7 +36,12 @@ public:
void run(void) {
while(this->count) {
dtkTrace() << count++;
sleep(1);
dtkDebug() << count;
dtkInfo() << count;
dtkWarn() << count;
dtkError() << count;
dtkFatal() << count;
msleep(500);
}
}
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:13:52 2012 (+0100)
* Version: $Id$
* Last-Updated: Mon Mar 5 14:12:28 2012 (+0100)
* Last-Updated: Tue Mar 6 11:04:24 2012 (+0100)
* By: Julien Wintz
* Update #: 183
* Update #: 361
*/
/* Commentary:
......@@ -22,6 +22,54 @@
#include "dtkLogView.h"
#include "dtkLogView_p.h"
// /////////////////////////////////////////////////////////////////
// dtkLogViewBar
// /////////////////////////////////////////////////////////////////
dtkLogViewBar::dtkLogViewBar(QWidget *parent) : QFrame(parent)
{
QPushButton *b_trace = new QPushButton("Trace", this);
QPushButton *b_debug = new QPushButton("Debug", this);
QPushButton *b_info = new QPushButton("Info", this);
QPushButton *b_warn = new QPushButton("Warn", this);
QPushButton *b_error = new QPushButton("Error", this);
QPushButton *b_fatal = new QPushButton("Fatal", this);
b_trace->setCheckable(true);
b_debug->setCheckable(true);
b_info->setCheckable(true);
b_warn->setCheckable(true);
b_error->setCheckable(true);
b_fatal->setCheckable(true);
b_trace->setChecked(true);
b_debug->setChecked(true);
b_info->setChecked(true);
b_warn->setChecked(true);
b_error->setChecked(true);
b_fatal->setChecked(true);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->addWidget(b_trace);
layout->addWidget(b_debug);
layout->addWidget(b_info);
layout->addWidget(b_warn);
layout->addWidget(b_error);
layout->addWidget(b_fatal);
connect(b_trace, SIGNAL(clicked(bool)), this, SIGNAL(displayTrace(bool)));
connect(b_debug, SIGNAL(clicked(bool)), this, SIGNAL(displayDebug(bool)));
connect(b_info, SIGNAL(clicked(bool)), this, SIGNAL(displayInfo(bool)));
connect(b_warn, SIGNAL(clicked(bool)), this, SIGNAL(displayWarn(bool)));
connect(b_error, SIGNAL(clicked(bool)), this, SIGNAL(displayError(bool)));
connect(b_fatal, SIGNAL(clicked(bool)), this, SIGNAL(displayFatal(bool)));
}
dtkLogViewBar::~dtkLogViewBar(void)
{
}
// /////////////////////////////////////////////////////////////////
// dtkLogViewTree
// /////////////////////////////////////////////////////////////////
......@@ -66,6 +114,11 @@ dtkLogViewList::dtkLogViewList(QWidget *parent) : QListView(parent)
{
this->model = new dtkLogModel(this);
this->proxy = new QSortFilterProxyModel(this);
this->proxy->setFilterKeyColumn(0);
this->setModel(this->proxy);
this->setAttribute(Qt::WA_MacShowFocusRect, false);
this->setFrameShape(QFrame::NoFrame);
this->setRuntime();
......@@ -80,7 +133,7 @@ void dtkLogViewList::setRuntime(void)
{
dtkLogger::instance().attachModel(this->model);
this->setModel(this->model);
this->proxy->setSourceModel(this->model);
}
void dtkLogViewList::setFile(const QString& path)
......@@ -99,7 +152,7 @@ void dtkLogViewList::setFile(const QString& path)
QStringListModel *model = new QStringListModel(contents.split("\n"));
this->setModel(model);
this->proxy->setSourceModel(model);
this->models.insert(path, model);
......@@ -108,25 +161,62 @@ void dtkLogViewList::setFile(const QString& path)
// connect(watcher, SIGNAL(fileChanged(const QString&)), this, SLOT(setFile(const QString&)));
}
void dtkLogViewList::setFilter(const QRegExp& expression)
{
this->proxy->setFilterRegExp(expression);
}
// /////////////////////////////////////////////////////////////////
// dtkLogViewPrivate
// /////////////////////////////////////////////////////////////////
QRegExp dtkLogViewPrivate::expression(void)
{
if(this->exclude.isEmpty())
return QRegExp();
QString patterns;
foreach(QString pattern, this->exclude)
patterns.append(QString("%1|").arg(pattern));
patterns.chop(1);
return QRegExp(QString("^(?!%1).*").arg(patterns), Qt::CaseSensitive, QRegExp::RegExp2);
}
// /////////////////////////////////////////////////////////////////
// dtkLogView
// /////////////////////////////////////////////////////////////////
dtkLogView::dtkLogView(QWidget *parent) : QWidget(parent), d(new dtkLogViewPrivate)
{
d->bar = new dtkLogViewBar(this);
d->tree = new dtkLogViewTree(this);
d->tree->setMaximumWidth(200);
d->list = new dtkLogViewList(this);
QHBoxLayout *layout = new QHBoxLayout(this);
QHBoxLayout *h_layout = new QHBoxLayout;
h_layout->setContentsMargins(0, 0, 0, 0);
h_layout->setSpacing(0);
h_layout->addWidget(d->tree);
h_layout->addWidget(d->list);
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(d->tree);
layout->addWidget(d->list);
layout->addWidget(d->bar);
layout->addLayout(h_layout);
connect(d->tree, SIGNAL(runtimeClicked()), d->list, SLOT(setRuntime()));
connect(d->tree, SIGNAL(fileClicked(const QString&)), d->list, SLOT(setFile(const QString&)));
connect(d->bar, SIGNAL(displayTrace(bool)), this, SLOT(displayTrace(bool)));
connect(d->bar, SIGNAL(displayDebug(bool)), this, SLOT(displayDebug(bool)));
connect(d->bar, SIGNAL(displayInfo(bool)), this, SLOT(displayInfo(bool)));
connect(d->bar, SIGNAL(displayWarn(bool)), this, SLOT(displayWarn(bool)));
connect(d->bar, SIGNAL(displayError(bool)), this, SLOT(displayError(bool)));
connect(d->bar, SIGNAL(displayFatal(bool)), this, SLOT(displayFatal(bool)));
}
dtkLogView::~dtkLogView(void)
......@@ -135,3 +225,63 @@ dtkLogView::~dtkLogView(void)
d = NULL;
}
void dtkLogView::displayTrace(bool display)
{
if(!display)
d->exclude << "TRACE";
else
d->exclude.removeAll("TRACE");
d->list->setFilter(d->expression());
}
void dtkLogView::displayDebug(bool display)
{
if(!display)
d->exclude << "DEBUG";
else
d->exclude.removeAll("DEBUG");
d->list->setFilter(d->expression());
}
void dtkLogView::displayInfo(bool display)
{
if(!display)
d->exclude << "INFO";
else
d->exclude.removeAll("INFO");
d->list->setFilter(d->expression());
}
void dtkLogView::displayWarn(bool display)
{
if(!display)
d->exclude << "WARN";
else
d->exclude.removeAll("WARN");
d->list->setFilter(d->expression());
}
void dtkLogView::displayError(bool display)
{
if(!display)
d->exclude << "ERROR";
else
d->exclude.removeAll("ERROR");
d->list->setFilter(d->expression());
}
void dtkLogView::displayFatal(bool display)
{
if(!display)
d->exclude << "FATAL";
else
d->exclude.removeAll("FATAL");
d->list->setFilter(d->expression());
}
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:08:10 2012 (+0100)
* Version: $Id$
* Last-Updated: Fri Mar 2 15:15:35 2012 (+0100)
* Last-Updated: Mon Mar 5 14:27:11 2012 (+0100)
* By: Julien Wintz
* Update #: 7
* Update #: 9
*/
/* Commentary:
......@@ -34,6 +34,14 @@ public:
dtkLogView(QWidget *parent = 0);
~dtkLogView(void);
public slots:
void displayTrace(bool display);
void displayDebug(bool display);
void displayInfo(bool display);
void displayWarn(bool display);
void displayError(bool display);
void displayFatal(bool display);
private:
dtkLogViewPrivate *d;
};
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:30:16 2012 (+0100)
* Version: $Id$
* Last-Updated: Mon Mar 5 13:14:13 2012 (+0100)
* Last-Updated: Tue Mar 6 10:04:35 2012 (+0100)
* By: Julien Wintz
* Update #: 50
* Update #: 66
*/
/* Commentary:
......@@ -26,6 +26,27 @@
class dtkLogModel;
// /////////////////////////////////////////////////////////////////
// dtkLogViewBar
// /////////////////////////////////////////////////////////////////
class dtkLogViewBar : public QFrame
{
Q_OBJECT
public:
dtkLogViewBar(QWidget *parent = 0);
~dtkLogViewBar(void);
signals:
void displayTrace(bool);
void displayDebug(bool);
void displayInfo(bool);
void displayWarn(bool);
void displayError(bool);
void displayFatal(bool);
};
// /////////////////////////////////////////////////////////////////
// dtkLogViewTree
// /////////////////////////////////////////////////////////////////
......@@ -66,11 +87,17 @@ public slots:
void setRuntime(void);
void setFile(const QString& path);
public:
void setFilter(const QRegExp& expression);
private:
dtkLogModel *model;
private:
QHash<QString, QStringListModel *> models;
private:
QSortFilterProxyModel *proxy;
};
// /////////////////////////////////////////////////////////////////
......@@ -80,8 +107,15 @@ private:
class dtkLogViewPrivate
{
public:
QRegExp expression(void);
public:
dtkLogViewBar *bar;
dtkLogViewTree *tree;
dtkLogViewList *list;
public:
QStringList exclude;
};
#endif
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