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 struct Message {
48 QtMsgType type;
49 QString message;
50
51 QString toRichText(bool colored = true,
52 bool bulletPoint = false) const noexcept;
53 };
54
55 // Constructors / Destructor
56
60 MessageLogger(bool record = true, QObject* parent = nullptr) noexcept;
61
65 MessageLogger(MessageLogger* parentLogger, const QString& group = QString(),
66 bool record = false, QObject* parent = nullptr) noexcept;
67
73 MessageLogger(const MessageLogger& other) = delete;
74
78 virtual ~MessageLogger() noexcept;
79
80 // Getters
81 bool hasMessages() const noexcept;
82 QList<Message> getMessages() const noexcept;
83 QStringList getMessagesPlain() const noexcept;
84 QString getMessagesRichText() const noexcept;
85
86 // General Methods
87 void clear() noexcept;
88 void log(QtMsgType type, const QString& msg) noexcept;
89 void debug(const QString& msg) noexcept;
90 void info(const QString& msg) noexcept;
91 void warning(const QString& msg) noexcept;
92 void critical(const QString& msg) noexcept;
93
94 // Operator Overloadings
95 MessageLogger& operator=(const MessageLogger& rhs) = delete;
96
97signals:
98 void msgEmitted(const Message& msg);
99
100private: // Data
101#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
102 mutable QRecursiveMutex mMutex;
103#else
104 mutable QMutex mMutex;
105#endif
106 QPointer<MessageLogger> mParent;
107 QString mPrefix;
109 QList<Message> mMessages;
110};
111
112/*******************************************************************************
113 * End of File
114 ******************************************************************************/
115
116} // namespace librepcb
117
118#endif
Generic logger class to pass messages between objects.
Definition: messagelogger.h:43
void clear() noexcept
Definition: messagelogger.cpp:128
QPointer< MessageLogger > mParent
Definition: messagelogger.h:106
void msgEmitted(const Message &msg)
QRecursiveMutex mMutex
Definition: messagelogger.h:102
void debug(const QString &msg) noexcept
Definition: messagelogger.cpp:147
QString mPrefix
Definition: messagelogger.h:107
void warning(const QString &msg) noexcept
Definition: messagelogger.cpp:155
QList< Message > getMessages() const noexcept
Definition: messagelogger.cpp:99
void log(QtMsgType type, const QString &msg) noexcept
Definition: messagelogger.cpp:133
bool mRecord
Definition: messagelogger.h:108
QList< Message > mMessages
Definition: messagelogger.h:109
void info(const QString &msg) noexcept
Definition: messagelogger.cpp:151
QStringList getMessagesPlain() const noexcept
Definition: messagelogger.cpp:108
QString getMessagesRichText() const noexcept
Definition: messagelogger.cpp:116
void critical(const QString &msg) noexcept
Definition: messagelogger.cpp:159
bool hasMessages() const noexcept
Definition: messagelogger.cpp:94
Definition: occmodel.cpp:77
Definition: messagelogger.h:47
QString toRichText(bool colored=true, bool bulletPoint=false) const noexcept
Definition: messagelogger.cpp:34
QtMsgType type
Definition: messagelogger.h:48
QString message
Definition: messagelogger.h:49