src/platform/qt/LogController.h (view raw)
1/* Copyright (c) 2013-2015 Jeffrey Pfau
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6#ifndef QGBA_LOG_CONTROLLER
7#define QGBA_LOG_CONTROLLER
8
9#include "GBAApp.h"
10
11#include <QObject>
12#include <QStringList>
13
14namespace QGBA {
15
16class LogController : public QObject {
17Q_OBJECT
18
19private:
20 class Stream {
21 public:
22 Stream(LogController* controller, int level, int category);
23 ~Stream();
24
25 Stream& operator<<(const QString&);
26
27 private:
28 int m_level;
29 int m_category;
30 LogController* m_log;
31
32 QStringList m_queue;
33 };
34
35public:
36 LogController(int levels, QObject* parent = nullptr);
37
38 int levels() const { return m_logLevel; }
39
40 Stream operator()(int category, int level);
41
42 static LogController* global();
43 static QString toString(int level);
44
45signals:
46 void logPosted(int level, int category, const QString& log);
47 void levelsSet(int levels);
48 void levelsEnabled(int levels);
49 void levelsDisabled(int levels);
50
51public slots:
52 void postLog(int level, int category, const QString& string);
53 void setLevels(int levels);
54 void enableLevels(int levels);
55 void disableLevels(int levels);
56
57private:
58 int m_logLevel;
59
60 static LogController s_global;
61};
62
63#define LOG(C, L) (*LogController::global())(_mLOG_CAT_ ## C (), mLOG_ ## L)
64
65}
66
67#endif