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
14#include "gba/gba.h"
15
16namespace QGBA {
17
18class LogController : public QObject {
19Q_OBJECT
20
21private:
22 class Stream {
23 public:
24 Stream(LogController* controller, int level, int category);
25 ~Stream();
26
27 Stream& operator<<(const QString&);
28
29 private:
30 int m_level;
31 int m_category;
32 LogController* m_log;
33
34 QStringList m_queue;
35 };
36
37public:
38 LogController(int levels, QObject* parent = nullptr);
39
40 int levels() const { return m_logLevel; }
41
42 Stream operator()(int category, int level);
43
44 static LogController* global();
45 static QString toString(int level);
46
47signals:
48 void logPosted(int level, int category, const QString& log);
49 void levelsSet(int levels);
50 void levelsEnabled(int levels);
51 void levelsDisabled(int levels);
52
53public slots:
54 void postLog(int level, int category, const QString& string);
55 void setLevels(int levels);
56 void enableLevels(int levels);
57 void disableLevels(int levels);
58
59private:
60 int m_logLevel;
61
62 static LogController s_global;
63};
64
65#define LOG(C, L) (*LogController::global())(_mLOG_CAT_ ## C (), mLOG_ ## L)
66
67}
68
69#endif