LibrePCB Developers Documentation
Loading...
Searching...
No Matches
messagelogger.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_MESSAGELOGGER_H
21#define LIBREPCB_CORE_MESSAGELOGGER_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include <QtCore>
27
28/*******************************************************************************
29 * Namespace / Forward Declarations
30 ******************************************************************************/
31namespace librepcb {
32
33/*******************************************************************************
34 * Class MessageLogger
35 ******************************************************************************/
36
43class MessageLogger final : public QObject {
44 Q_OBJECT
45
46public:
47 enum class ColorTheme { None, Light, Dark };
48
49 struct Message {
50 QtMsgType type;
51 QString message;
52
53 QString toRichText(ColorTheme theme,
54 bool bulletPoint = false) const noexcept;
55 };
56
57 // Constructors / Destructor
58
62 MessageLogger(bool record = true, QObject* parent = nullptr) noexcept;
63
67 MessageLogger(MessageLogger* parentLogger, const QString& group = QString(),
68 bool record = false, QObject* parent = nullptr) noexcept;
69
75 MessageLogger(const MessageLogger& other) = delete;
76
80 virtual ~MessageLogger() noexcept;
81
82 // Getters
83 bool hasMessages() const noexcept;
84 QList<Message> getMessages() const noexcept;
85 QStringList getMessagesPlain() const noexcept;
86 QString getMessagesRichText(ColorTheme theme) const noexcept;
87
88 // General Methods
89 void clear() noexcept;
90 void log(QtMsgType type, const QString& msg) noexcept;
91 void debug(const QString& msg) noexcept;
92 void info(const QString& msg) noexcept;
93 void warning(const QString& msg) noexcept;
94 void critical(const QString& msg) noexcept;
95
96 // Operator Overloadings
97 MessageLogger& operator=(const MessageLogger& rhs) = delete;
98
99signals:
100 void msgEmitted(const Message& msg);
101
102private: // Data
103 mutable QRecursiveMutex mMutex;
105 QString mPrefix;
108};
109
110/*******************************************************************************
111 * End of File
112 ******************************************************************************/
113
114} // namespace librepcb
115
116#endif
Generic logger class to pass messages between objects.
Definition messagelogger.h:43
void clear() noexcept
Definition messagelogger.cpp:116
QPointer< MessageLogger > mParent
Definition messagelogger.h:104
QString getMessagesRichText(ColorTheme theme) const noexcept
Definition messagelogger.cpp:104
void msgEmitted(const Message &msg)
QRecursiveMutex mMutex
Definition messagelogger.h:103
void debug(const QString &msg) noexcept
Definition messagelogger.cpp:135
QString mPrefix
Definition messagelogger.h:105
void warning(const QString &msg) noexcept
Definition messagelogger.cpp:143
QList< Message > getMessages() const noexcept
Definition messagelogger.cpp:87
ColorTheme
Definition messagelogger.h:47
void log(QtMsgType type, const QString &msg) noexcept
Definition messagelogger.cpp:121
bool mRecord
Definition messagelogger.h:106
QList< Message > mMessages
Definition messagelogger.h:107
void info(const QString &msg) noexcept
Definition messagelogger.cpp:139
QStringList getMessagesPlain() const noexcept
Definition messagelogger.cpp:96
void critical(const QString &msg) noexcept
Definition messagelogger.cpp:147
bool hasMessages() const noexcept
Definition messagelogger.cpp:82
Definition occmodel.cpp:76
Definition messagelogger.h:49
QString toRichText(ColorTheme theme, bool bulletPoint=false) const noexcept
Definition messagelogger.cpp:34
QtMsgType type
Definition messagelogger.h:50
QString message
Definition messagelogger.h:51