QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 "qgis.h"
20#include "qgis_core.h"
21
22#include <QObject>
23#include <QString>
24
39class CORE_EXPORT QgsMessageLog : public QObject
40{
41 Q_OBJECT
42
43 public:
44 QgsMessageLog() = default;
45
46 // TODO: Update this code to use std::source_location from C++20 when transitioning to a fully C++20-compliant codebase.
47 // Currently, we rely on __builtin_XXX functions (e.g., __builtin_FILE(), __builtin_LINE()),
48 // which have been successfully tested across multiple systems (Windows, macOS, Linux, FreeBSD)
49 // and compilers (LLVM, GCC, MSVC).
50 // Note: We tested with LLVM on FreeBSD and macOS, and std::experimental::source_location is not available.
51 // It works fine with GNU. It also seems unavailable with MSVC.
52 // For now, we stick with __builtin_XXX because it is "portable" and functional across all tested environments.
53 // We'll switch to std::source_location once the transition to C++20 is complete.
54
64 static void logMessage(
65 const QString &message,
66 const QString &tag = QString(),
68 bool notifyUser = true,
69 const char *file = __builtin_FILE(),
70 const char *function = __builtin_FUNCTION(),
71 int line = __builtin_LINE(),
73 );
74
75 signals:
76
85 Q_DECL_DEPRECATED void messageReceived( const QString &message, const QString &tag, Qgis::MessageLevel level ) SIP_DEPRECATED;
86
93 void messageReceivedWithFormat( const QString &message, const QString &tag, Qgis::MessageLevel level, Qgis::StringFormat );
94
95 //TODO QGIS 5.0 - remove received argument
96
105 void messageReceived( bool received );
106
107 private:
108 void emitMessage( const QString &message, const QString &tag, Qgis::MessageLevel level, bool notifyUser = true, Qgis::StringFormat format = Qgis::StringFormat::PlainText );
109
110 int mAdviseBlockCount = 0;
111
113};
114
129{
130 public:
137
140
142
143 private:
144#ifdef SIP_RUN
146#endif
147};
148
156class CORE_EXPORT QgsMessageLogConsole : public QObject
157{
158 Q_OBJECT
159
160 public:
165
166 protected:
175 QString formatLogMessage( const QString &message, const QString &tag, Qgis::MessageLevel level = Qgis::MessageLevel::Info ) const;
176
177 public slots:
178
186 virtual void logMessage( const QString &message, const QString &tag, Qgis::MessageLevel level );
187
198 virtual void logMessage( const QString &message, const QString &tag, Qgis::MessageLevel level, Qgis::StringFormat format );
199};
200
201#endif
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:160
@ Warning
Warning message.
Definition qgis.h:162
@ Info
Information message.
Definition qgis.h:161
StringFormat
Format of log message.
Definition qgis.h:175
@ PlainText
Text message.
Definition qgis.h:176
QString formatLogMessage(const QString &message, const QString &tag, Qgis::MessageLevel level=Qgis::MessageLevel::Info) const
Formats a log message.
QgsMessageLogConsole()
Constructor for QgsMessageLogConsole.
virtual void logMessage(const QString &message, const QString &tag, Qgis::MessageLevel level)
Logs a message to stderr.
QgsMessageLogNotifyBlocker(const QgsMessageLogNotifyBlocker &other)=delete
QgsMessageLogNotifyBlocker & operator=(const QgsMessageLogNotifyBlocker &other)=delete
QgsMessageLogNotifyBlocker()
Constructor for QgsMessageLogNotifyBlocker.
void messageReceivedWithFormat(const QString &message, const QString &tag, Qgis::MessageLevel level, Qgis::StringFormat)
Emitted whenever the log receives a message.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
friend class QgsMessageLogNotifyBlocker
Q_DECL_DEPRECATED 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
#define SIP_DEPRECATED
Definition qgis_sip.h:113