QGIS API Documentation
4.3.0-Master (52aa6503bed)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
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
39
class
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(),
67
Qgis::MessageLevel
level =
Qgis::MessageLevel::Warning
,
68
bool
notifyUser =
true
,
69
const
char
*file = __builtin_FILE(),
70
const
char
*function = __builtin_FUNCTION(),
71
int
line = __builtin_LINE(),
72
Qgis::StringFormat
format =
Qgis::StringFormat::PlainText
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
112
friend
class
QgsMessageLogNotifyBlocker
;
113
};
114
128
class
CORE_EXPORT
QgsMessageLogNotifyBlocker
129
{
130
public
:
136
QgsMessageLogNotifyBlocker
();
137
138
QgsMessageLogNotifyBlocker
(
const
QgsMessageLogNotifyBlocker
&other ) =
delete
;
139
QgsMessageLogNotifyBlocker
&
operator=
(
const
QgsMessageLogNotifyBlocker
&other ) =
delete
;
140
141
~QgsMessageLogNotifyBlocker
();
142
143
private
:
144
#ifdef SIP_RUN
145
QgsMessageLogNotifyBlocker
(
const
QgsMessageLogNotifyBlocker
&other );
146
#endif
147
};
148
156
class
CORE_EXPORT
QgsMessageLogConsole
:
public
QObject
157
{
158
Q_OBJECT
159
160
public
:
164
QgsMessageLogConsole
();
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
Qgis::MessageLevel
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition
qgis.h:160
Qgis::Warning
@ Warning
Warning message.
Definition
qgis.h:162
Qgis::Info
@ Info
Information message.
Definition
qgis.h:161
Qgis::StringFormat
StringFormat
Format of log message.
Definition
qgis.h:175
Qgis::StringFormat::PlainText
@ PlainText
Text message.
Definition
qgis.h:176
QgsMessageLogConsole::formatLogMessage
QString formatLogMessage(const QString &message, const QString &tag, Qgis::MessageLevel level=Qgis::MessageLevel::Info) const
Formats a log message.
Definition
qgsmessagelog.cpp:95
QgsMessageLogConsole::QgsMessageLogConsole
QgsMessageLogConsole()
Constructor for QgsMessageLogConsole.
Definition
qgsmessagelog.cpp:71
QgsMessageLogConsole::logMessage
virtual void logMessage(const QString &message, const QString &tag, Qgis::MessageLevel level)
Logs a message to stderr.
Definition
qgsmessagelog.cpp:82
QgsMessageLogNotifyBlocker::QgsMessageLogNotifyBlocker
QgsMessageLogNotifyBlocker(const QgsMessageLogNotifyBlocker &other)=delete
QgsMessageLogNotifyBlocker::operator=
QgsMessageLogNotifyBlocker & operator=(const QgsMessageLogNotifyBlocker &other)=delete
QgsMessageLogNotifyBlocker::QgsMessageLogNotifyBlocker
QgsMessageLogNotifyBlocker()
Constructor for QgsMessageLogNotifyBlocker.
Definition
qgsmessagelog.cpp:107
QgsMessageLog::messageReceivedWithFormat
void messageReceivedWithFormat(const QString &message, const QString &tag, Qgis::MessageLevel level, Qgis::StringFormat)
Emitted whenever the log receives a message.
QgsMessageLog::logMessage
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).
Definition
qgsmessagelog.cpp:35
QgsMessageLog::QgsMessageLogNotifyBlocker
friend class QgsMessageLogNotifyBlocker
Definition
qgsmessagelog.h:112
QgsMessageLog::messageReceived
Q_DECL_DEPRECATED void messageReceived(const QString &message, const QString &tag, Qgis::MessageLevel level)
Emitted whenever the log receives a message.
QgsMessageLog::messageReceived
void messageReceived(bool received)
Emitted whenever the log receives a message which is not a Qgis::MessageLevel::Info level message and...
QgsMessageLog::QgsMessageLog
QgsMessageLog()=default
qgis.h
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition
qgis_sip.h:113
Generated on
for QGIS API Documentation by
1.17.0