QGIS API Documentation 3.43.0-Master (0bee5d6404c)
qgsmessagelog.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsmessagelog.h - interface for logging messages
3 ----------------------
4 begin : October 2011
5 copyright : (C) 2011 by Juergen E. Fischer
6 email : jef at norbit dot de
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSMESSAGELOG_H
17#define QGSMESSAGELOG_H
18
19#include <QString>
20#include <QObject>
21
22#include "qgis_core.h"
23#include "qgis.h"
24
39class CORE_EXPORT QgsMessageLog : public QObject
40{
41 Q_OBJECT
42
43 public:
44
45 QgsMessageLog() = default;
46
47 // TODO: Update this code to use std::source_location from C++20 when transitioning to a fully C++20-compliant codebase.
48 // Currently, we rely on __builtin_XXX functions (e.g., __builtin_FILE(), __builtin_LINE()),
49 // which have been successfully tested across multiple systems (Windows, macOS, Linux, FreeBSD)
50 // and compilers (LLVM, GCC, MSVC).
51 // Note: We tested with LLVM on FreeBSD and macOS, and std::experimental::source_location is not available.
52 // It works fine with GNU. It also seems unavailable with MSVC.
53 // For now, we stick with __builtin_XXX because it is "portable" and functional across all tested environments.
54 // We'll switch to std::source_location once the transition to C++20 is complete.
55
63 static void logMessage( const QString &message, const QString &tag = QString(), Qgis::MessageLevel level = Qgis::MessageLevel::Warning, bool notifyUser = true,
64 const char *file = __builtin_FILE(), const char *function = __builtin_FUNCTION(), int line = __builtin_LINE() );
65
66 signals:
67
74 void messageReceived( const QString &message, const QString &tag, Qgis::MessageLevel level );
75
76 //TODO QGIS 4.0 - remove received argument
77
86 void messageReceived( bool received );
87
88 private:
89
90 void emitMessage( const QString &message, const QString &tag, Qgis::MessageLevel level, bool notifyUser = true );
91
92 int mAdviseBlockCount = 0;
93
95
96};
97
112{
113 public:
114
121
124
126
127 private:
128
129#ifdef SIP_RUN
131#endif
132};
133
141class CORE_EXPORT QgsMessageLogConsole : public QObject
142{
143 Q_OBJECT
144
145 public:
146
151
152 protected:
153
162 QString formatLogMessage( const QString &message, const QString &tag, Qgis::MessageLevel level = Qgis::MessageLevel::Info ) const;
163
164 public slots:
165
173 virtual void logMessage( const QString &message, const QString &tag, Qgis::MessageLevel level );
174};
175
176#endif
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:154
@ Warning
Warning message.
Definition qgis.h:156
@ Info
Information message.
Definition qgis.h:155
Default implementation of message logging interface.
Temporarily blocks the application QgsMessageLog (see QgsApplication::messageLog()) from emitting the...
QgsMessageLogNotifyBlocker(const QgsMessageLogNotifyBlocker &other)=delete
QgsMessageLogNotifyBlocker & operator=(const QgsMessageLogNotifyBlocker &other)=delete
Interface for logging messages from QGIS in GUI independent way.
void messageReceived(const QString &message, const QString &tag, Qgis::MessageLevel level)
Emitted whenever the log receives a message.
void messageReceived(bool received)
Emitted whenever the log receives a message which is not a Qgis::MessageLevel::Info level message and...
QgsMessageLog()=default