QGIS API Documentation 3.41.0-Master (64d82d4c163)
Loading...
Searching...
No Matches
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
54 // TODO: Update this code to use std::source_location from C++20 when transitioning to a fully C++20-compliant codebase.
55 // Currently, we rely on __builtin_XXX functions (e.g., __builtin_FILE(), __builtin_LINE()),
56 // which have been successfully tested across multiple systems (Windows, macOS, Linux, FreeBSD)
57 // and compilers (LLVM, GCC, MSVC).
58 // Note: We tested with LLVM on FreeBSD and macOS, and std::experimental::source_location is not available.
59 // It works fine with GNU. It also seems unavailable with MSVC.
60 // For now, we stick with __builtin_XXX because it is "portable" and functional across all tested environments.
61 // We'll switch to std::source_location once the transition to C++20 is complete.
62 static void logMessage( const QString &message, const QString &tag = QString(), Qgis::MessageLevel level = Qgis::MessageLevel::Warning, bool notifyUser = true,
63 const char *file = __builtin_FILE(), const char *function = __builtin_FUNCTION(), int line = __builtin_LINE() );
64
65 signals:
66
73 void messageReceived( const QString &message, const QString &tag, Qgis::MessageLevel level );
74
75 //TODO QGIS 4.0 - remove received argument
76
85 void messageReceived( bool received );
86
87 private:
88
89 void emitMessage( const QString &message, const QString &tag, Qgis::MessageLevel level, bool notifyUser = true );
90
91 int mAdviseBlockCount = 0;
92
94
95};
96
111{
112 public:
113
120
123
125
126 private:
127
128#ifdef SIP_RUN
130#endif
131};
132
140class CORE_EXPORT QgsMessageLogConsole : public QObject
141{
142 Q_OBJECT
143
144 public:
145
150
151 protected:
152
161 QString formatLogMessage( const QString &message, const QString &tag, Qgis::MessageLevel level = Qgis::MessageLevel::Info ) const;
162
163 public slots:
164
172 virtual void logMessage( const QString &message, const QString &tag, Qgis::MessageLevel level );
173};
174
175#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