LibrePCB Developers Documentation
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#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
104 mutable QRecursiveMutex mMutex;
105#else
106 mutable QMutex mMutex;
107#endif
108 QPointer<MessageLogger> mParent;
109 QString mPrefix;
111 QList<Message> mMessages;
112};
113
114/*******************************************************************************
115 * End of File
116 ******************************************************************************/
117
118} // namespace librepcb
119
120#endif
Generic logger class to pass messages between objects.
Definition: messagelogger.h:43
void clear() noexcept
Definition: messagelogger.cpp:130
QPointer< MessageLogger > mParent
Definition: messagelogger.h:108
QString getMessagesRichText(ColorTheme theme) const noexcept
Definition: messagelogger.cpp:118
void msgEmitted(const Message &msg)
QRecursiveMutex mMutex
Definition: messagelogger.h:104
void debug(const QString &msg) noexcept
Definition: messagelogger.cpp:149
QString mPrefix
Definition: messagelogger.h:109
void warning(const QString &msg) noexcept
Definition: messagelogger.cpp:157
QList< Message > getMessages() const noexcept
Definition: messagelogger.cpp:101
ColorTheme
Definition: messagelogger.h:47
void log(QtMsgType type, const QString &msg) noexcept
Definition: messagelogger.cpp:135
bool mRecord
Definition: messagelogger.h:110
QList< Message > mMessages
Definition: messagelogger.h:111
void info(const QString &msg) noexcept
Definition: messagelogger.cpp:153
QStringList getMessagesPlain() const noexcept
Definition: messagelogger.cpp:110
void critical(const QString &msg) noexcept
Definition: messagelogger.cpp:161
bool hasMessages() const noexcept
Definition: messagelogger.cpp:96
Definition: occmodel.cpp:77
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