-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathQtLogger.h
More file actions
69 lines (53 loc) · 1.92 KB
/
QtLogger.h
File metadata and controls
69 lines (53 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2015, Christopher J. Foster and the other displaz contributors.
// Use of this code is governed by the BSD-style license found in LICENSE.txt
#ifndef QT_LOGGER_H_INCLUDED
#define QT_LOGGER_H_INCLUDED
#include <QObject>
#include <QPlainTextEdit>
#include <QString>
#include "logger.h"
#include "qtutil.h"
/// Logger class which logs output to qt signals
class QtLogger : public QObject, public Logger
{
Q_OBJECT
public:
QtLogger(QObject* parent = 0) : QObject(parent) {}
signals:
/// Signal emitted every time a log message comes in
void logMessage(int logLevel, QString msg);
/// Signal emitted when processing progress has been made
void progressPercent(int percent);
protected:
virtual void logImpl(LogLevel level, const std::string& msg)
{
emit logMessage(level, QString::fromUtf8(msg.c_str()));
}
virtual void progressImpl(double progressFraction)
{
emit progressPercent(int(100*progressFraction));
}
};
/// Global displaz logger instance
extern QtLogger g_logger;
//------------------------------------------------------------------------------
/// Viewer widget for log messages.
///
/// This is intended to work together with the Logger class as a frontend which
/// does to the actual log message formatting. The logger frontend is
/// threadsafe, but LogViewer must run on the GUI thread.
class LogViewer : public QPlainTextEdit
{
Q_OBJECT
public:
LogViewer(QWidget* parent = 0);
public slots:
/// Connect given logger to the viewer.
///
/// Note that for thread safety this must be a queued connection, hence
/// the special purpose method here.
void connectLogger(QtLogger* logger);
/// Append plain text message to the running log
void appendLogMessage(int logLevel, QString msg);
};
#endif // QT_LOGGER_H_INCLUDED