Commit 916d5bab authored by Julien Wintz's avatar Julien Wintz
Browse files

Adding log view widgets. WIP.

parent e88b30f6
......@@ -4,9 +4,9 @@
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Mon Mar 9 21:06:43 2009 (+0100)
## Version: $Id$
## Last-Updated: Thu Mar 1 15:22:38 2012 (+0100)
## Last-Updated: Fri Mar 2 15:20:31 2012 (+0100)
## By: Julien Wintz
## Update #: 80
## Update #: 81
######################################################################
##
### Commentary:
......@@ -22,6 +22,7 @@
## #################################################################
add_subdirectory(dtkLogger)
add_subdirectory(dtkLogView)
## #################################################################
## dtkCrypto examples
......
### CMakeLists.txt ---
##
## Author: Julien Wintz
## Copyright (C) 2008-2011 - Julien Wintz, Inria.
## Created: Thu Mar 1 15:20:19 2012 (+0100)
## Version: $Id$
## Last-Updated: Fri Mar 2 15:17:44 2012 (+0100)
## By: Julien Wintz
## Update #: 9
######################################################################
##
### Commentary:
##
######################################################################
##
### Change log:
##
######################################################################
project(dtkLogView)
## #################################################################
## Build rules
## #################################################################
add_executable(${PROJECT_NAME} MACOSX_BUNDLE
main.cpp)
target_link_libraries(${PROJECT_NAME}
${QT_LIBRARIES}
dtkLog)
/* main.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:16:32 2012 (+0100)
* Version: $Id$
* Last-Updated: Fri Mar 2 19:09:13 2012 (+0100)
* By: Julien Wintz
* Update #: 61
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include <dtkLog/dtkLog.h>
#include <dtkLog/dtkLogView.h>
#include <QtGui>
// /////////////////////////////////////////////////////////////////
// Helper function
// /////////////////////////////////////////////////////////////////
QString dtkLogPath(QCoreApplication *application);
// /////////////////////////////////////////////////////////////////
// Dummy thread
// /////////////////////////////////////////////////////////////////
class LogProducer : public QThread
{
public:
LogProducer(void) {
this->count = 1;
}
void run(void) {
while(this->count) {
dtkTrace() << count++;
sleep(1);
}
}
void stop(void) {
this->count = 0;
}
private:
int count;
};
// /////////////////////////////////////////////////////////////////
// main
// /////////////////////////////////////////////////////////////////
int main(int argc, char **argv)
{
QApplication application(argc, argv);
application.setApplicationName("dtkLogView");
dtkLogger::instance().setLevel(dtkLog::Trace);
dtkLogView *view = new dtkLogView;
view->setWindowTitle("dtk Log View");
view->resize(680, 350);
view->show();
view->raise();
LogProducer p1;
p1.start();
int status = application.exec();
p1.stop();
p1.wait();
delete view;
return status;
}
// /////////////////////////////////////////////////////////////////
// Helper function
// /////////////////////////////////////////////////////////////////
QString dtkLogPath(QCoreApplication *application)
{
QString path = QDir(application->applicationDirPath()).filePath(QString("%1.log").arg(application->applicationName()));
if (path.contains(QString("%1.app/Contents/MacOS/").arg(application->applicationName())))
path.remove(QString("%1.app/Contents/MacOS/").arg(application->applicationName()));
return path;
}
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 15:23:18 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 23:14:39 2012 (+0100)
* Last-Updated: Fri Mar 2 18:53:06 2012 (+0100)
* By: Julien Wintz
* Update #: 225
* Update #: 227
*/
/* Commentary:
......@@ -87,7 +87,7 @@ QString dtkLogPath(QCoreApplication *application);
int main(int argc, char **argv)
{
QCoreApplication application(argc, argv);
application.setApplicationName(argv[0]);
application.setApplicationName("dtkLogger");
qRegisterMetaType<Pixel>();
......
......@@ -4,9 +4,9 @@
## Copyright (C) 2008 - Julien Wintz, Inria.
## Created: Mon Jul 20 22:21:50 2009 (+0200)
## Version: $Id$
## Last-Updated: Wed Feb 29 23:51:00 2012 (+0100)
## Last-Updated: Fri Mar 2 15:40:25 2012 (+0100)
## By: Julien Wintz
## Update #: 225
## Update #: 227
######################################################################
##
### Commentary:
......@@ -133,7 +133,6 @@ endif(BUILD_SHARED_LIBS)
target_link_libraries(${PROJECT_NAME}
${QT_LIBRARIES}
dtkCore
dtkScript)
## #################################################################
......
......@@ -4,9 +4,9 @@
## Copyright (C) 2008-2011 - Julien Wintz, Inria.
## Created: Thu Mar 1 14:34:49 2012 (+0100)
## Version: $Id$
## Last-Updated: Thu Mar 1 17:29:16 2012 (+0100)
## Last-Updated: Fri Mar 2 15:32:15 2012 (+0100)
## By: Julien Wintz
## Update #: 19
## Update #: 23
######################################################################
##
### Commentary:
......@@ -27,14 +27,18 @@ set(${PROJECT_NAME}_HEADERS
dtkLog.h
dtkLogger.h
dtkLogEngine.h
dtkLogDestination.h)
dtkLogDestination.h
dtkLogView.h)
set(${PROJECT_NAME}_HEADERS_MOC)
set(${PROJECT_NAME}_HEADERS_MOC
dtkLogView.h
dtkLogView_p.h)
set(${PROJECT_NAME}_SOURCES
dtkLogger.cpp
dtkLogEngine.cpp
dtkLogDestination.cpp)
dtkLogDestination.cpp
dtkLogView.cpp)
## #################################################################
## Build rules
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 15:15:19 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 23:37:00 2012 (+0100)
* Last-Updated: Fri Mar 2 19:04:40 2012 (+0100)
* By: Julien Wintz
* Update #: 22
* Update #: 53
*/
/* Commentary:
......@@ -18,6 +18,7 @@
*/
#include "dtkLogDestination.h"
#include "dtkLogView_p.h"
// /////////////////////////////////////////////////////////////////
// dtkLogDestination
......@@ -71,3 +72,30 @@ void dtkLogDestinationFile::write(const QString& message)
d->stream << message << endl;
d->stream.flush();
}
// /////////////////////////////////////////////////////////////////
// dtkLogDestinationView
// /////////////////////////////////////////////////////////////////
class dtkLogDestinationViewPrivate
{
public:
dtkLogViewList *view;
};
dtkLogDestinationView::dtkLogDestinationView(dtkLogViewList *view) : d(new dtkLogDestinationViewPrivate)
{
d->view = view;
}
dtkLogDestinationView::~dtkLogDestinationView(void)
{
delete d;
d = NULL;
}
void dtkLogDestinationView::write(const QString& message)
{
d->view->append(message);
}
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 15:10:22 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 18:01:37 2012 (+0100)
* Last-Updated: Fri Mar 2 19:01:08 2012 (+0100)
* By: Julien Wintz
* Update #: 24
* Update #: 35
*/
/* Commentary:
......@@ -66,6 +66,26 @@ private:
dtkLogDestinationFilePrivate *d;
};
// /////////////////////////////////////////////////////////////////
// dtkLogDestinationList
// /////////////////////////////////////////////////////////////////
class dtkLogDestinationViewPrivate;
class dtkLogViewList;
class DTKLOG_EXPORT dtkLogDestinationView : public dtkLogDestination
{
public:
dtkLogDestinationView(dtkLogViewList *view);
~dtkLogDestinationView(void);
public:
void write(const QString& message);
private:
dtkLogDestinationViewPrivate *d;
};
// /////////////////////////////////////////////////////////////////
// dtkLogDestinationPointer
// /////////////////////////////////////////////////////////////////
......
/* dtkLogView.cpp ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:13:52 2012 (+0100)
* Version: $Id$
* Last-Updated: Fri Mar 2 19:08:23 2012 (+0100)
* By: Julien Wintz
* Update #: 98
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#include "dtkLogView.h"
#include "dtkLogView_p.h"
// /////////////////////////////////////////////////////////////////
// dtkLogViewTree
// /////////////////////////////////////////////////////////////////
dtkLogViewTree::dtkLogViewTree(QWidget *parent) : QTreeWidget(parent)
{
this->setAttribute(Qt::WA_MacShowFocusRect, false);
this->setFrameShape(QFrame::HLine);
this->setHeaderHidden(true);
QTreeWidgetItem *runtime_log = new QTreeWidgetItem(QStringList() << "Runtime log");
QTreeWidgetItem *file_log = new QTreeWidgetItem(QStringList() << "File log");
QTreeWidgetItem *dummy_a_log = new QTreeWidgetItem(QStringList() << "a.log");
QTreeWidgetItem *dummy_b_log = new QTreeWidgetItem(QStringList() << "b.log");
file_log->addChild(dummy_a_log);
file_log->addChild(dummy_b_log);
this->addTopLevelItem(runtime_log);
this->addTopLevelItem(file_log);
}
dtkLogViewTree::~dtkLogViewTree(void)
{
}
// /////////////////////////////////////////////////////////////////
// dtkLogViewList
// /////////////////////////////////////////////////////////////////
dtkLogViewList::dtkLogViewList(QWidget *parent) : QListView(parent)
{
this->setAttribute(Qt::WA_MacShowFocusRect, false);
this->setFrameShape(QFrame::NoFrame);
this->setRuntime();
}
dtkLogViewList::~dtkLogViewList(void)
{
}
void dtkLogViewList::setRuntime(void)
{
dtkLogger::instance().attachView(this);
this->setModel(&(this->model));
}
void dtkLogViewList::append(const QString& message)
{
this->list << message;
this->model.setStringList(this->list);
}
// /////////////////////////////////////////////////////////////////
// dtkLogView
// /////////////////////////////////////////////////////////////////
dtkLogView::dtkLogView(QWidget *parent) : QWidget(parent), d(new dtkLogViewPrivate)
{
d->tree = new dtkLogViewTree(this);
d->tree->setMaximumWidth(200);
d->list = new dtkLogViewList(this);
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(d->tree);
layout->addWidget(d->list);
}
dtkLogView::~dtkLogView(void)
{
delete d;
d = NULL;
}
/* dtkLogView.h ---
*
* Author: Julien Wintz
* 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)
* By: Julien Wintz
* Update #: 7
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKLOGVIEW_H
#define DTKLOGVIEW_H
#include "dtkLogExport.h"
#include <QtGui>
class dtkLogViewPrivate;
class DTKLOG_EXPORT dtkLogView : public QWidget
{
Q_OBJECT
public:
dtkLogView(QWidget *parent = 0);
~dtkLogView(void);
private:
dtkLogViewPrivate *d;
};
#endif
/* dtkLogView_p.h ---
*
* Author: Julien Wintz
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Fri Mar 2 15:30:16 2012 (+0100)
* Version: $Id$
* Last-Updated: Fri Mar 2 19:03:52 2012 (+0100)
* By: Julien Wintz
* Update #: 35
*/
/* Commentary:
*
*/
/* Change log:
*
*/
#ifndef DTKLOGVIEW_P_H
#define DTKLOGVIEW_P_H
#include "dtkLogger.h"
#include <QtGui>
// /////////////////////////////////////////////////////////////////
// dtkLogViewTree
// /////////////////////////////////////////////////////////////////
class dtkLogViewTree : public QTreeWidget
{
Q_OBJECT
public:
dtkLogViewTree(QWidget *parent = 0);
~dtkLogViewTree(void);
};
// /////////////////////////////////////////////////////////////////
// dtkLogViewList
// /////////////////////////////////////////////////////////////////
class dtkLogViewList : public QListView
{
Q_OBJECT
public:
dtkLogViewList(QWidget *parent = 0);
~dtkLogViewList(void);
public:
void setRuntime(void);
public:
void append(const QString& message);
private:
QStringList list;
QStringListModel model;
};
// /////////////////////////////////////////////////////////////////
// dtkLogViewPrivate
// /////////////////////////////////////////////////////////////////
class dtkLogViewPrivate
{
public:
dtkLogViewTree *tree;
dtkLogViewList *list;
};
#endif
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 17:19:52 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 23:36:24 2012 (+0100)
* Last-Updated: Fri Mar 2 18:57:59 2012 (+0100)
* By: Julien Wintz
* Update #: 60
* Update #: 86
*/
/* Commentary:
......@@ -65,6 +65,23 @@ void dtkLogger::detachFile(const QString& path)
d->files.remove(path);
}
void dtkLogger::attachView(dtkLogViewList *view)
{
d->views[view] = dtkLogDestinationPointer(new dtkLogDestinationView(view));
d->destinations << d->views[view];
}
void dtkLogger::detachView(dtkLogViewList *view)
{
if(!d->views.contains(view))
return;
d->destinations.removeOne(d->views[view]);
d->views.remove(view);
}
dtkLogger::dtkLogger(void) : d(new dtkLoggerPrivate)
{
d->level = dtkLog::Info;
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 17:18:31 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 22:32:31 2012 (+0100)
* Last-Updated: Fri Mar 2 18:47:34 2012 (+0100)
* By: Julien Wintz
* Update #: 16
* Update #: 29
*/
/* Commentary:
......@@ -25,8 +25,9 @@
#include <QtCore>
class dtkLogDestination;
class dtkLoggerPrivate;
class dtkLogDestination;
class dtkLogViewList;
class DTKLOG_EXPORT dtkLogger
{
......@@ -47,6 +48,10 @@ public:
void attachFile(const QString& path);
void detachFile(const QString& path);
public:
void attachView(dtkLogViewList *view);
void detachView(dtkLogViewList *view);
private:
dtkLogger(void);
dtkLogger(const dtkLogger& other);
......
......@@ -4,9 +4,9 @@
* Copyright (C) 2008-2011 - Julien Wintz, Inria.
* Created: Thu Mar 1 17:26:54 2012 (+0100)
* Version: $Id$
* Last-Updated: Thu Mar 1 22:42:02 2012 (+0100)
* Last-Updated: Fri Mar 2 18:56:14 2012 (+0100)
* By: Julien Wintz
* Update #: 23
* Update #: 41
*/
/* Commentary:
......@@ -25,14 +25,17 @@
#include <QtCore>
class dtkLogViewList;
class dtkLoggerPrivate
{
public:
dtkLog::Level level;
public:
dtkLogDestinationPointer console;
QHash<QString, dtkLogDestinationPointer> files;
dtkLogDestinationPointer console;
QHash<QString, dtkLogDestinationPointer> files;
QHash<dtkLogViewList *, dtkLogDestinationPointer> views;