QGIS API Documentation 3.99.0-Master (a8f284845db)
Loading...
Searching...
No Matches
qgsmessageoutput.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsmessageoutput.h - interface for showing messages
3 ----------------------
4 begin : April 2006
5 copyright : (C) 2006 by Martin Dobias
6 email : wonder.sk at gmail dot com
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#include "qgsmessageoutput.h"
17
18#include "qgslogger.h"
19#include "qgsmessagelog.h"
20
21#include <QRegularExpression>
22#include <QString>
23
24#include "moc_qgsmessageoutput.cpp"
25
26using namespace Qt::StringLiterals;
27
28static QgsMessageOutput *messageOutputConsole_()
29{
30 return new QgsMessageOutputConsole;
31}
32
33// default output creator - console
34MESSAGE_OUTPUT_CREATOR QgsMessageOutput::mMessageOutputCreator = messageOutputConsole_;
35
36
38{
39 mMessageOutputCreator = f;
40}
41
43{
44 return mMessageOutputCreator();
45}
46
47void QgsMessageOutput::showMessage( const QString &title, const QString &message, Qgis::StringFormat format )
48{
50 output->setTitle( title );
51 output->setMessage( message, format );
52 output->showMessage();
53}
54
56// QgsMessageOutputConsole
57
58void QgsMessageOutputConsole::setMessage( const QString &message, Qgis::StringFormat format )
59{
60 mMessage = message;
61 mFormat = format;
62}
63
64void QgsMessageOutputConsole::appendMessage( const QString &message )
65{
66 mMessage += message;
67}
68
70{
71 if ( mFormat == Qgis::StringFormat::Html )
72 {
73 mMessage.replace( "<br>"_L1, "\n"_L1 );
74 mMessage.replace( "&nbsp;"_L1, " "_L1 );
75 const thread_local QRegularExpression tagRX( u"</?[^>]+>"_s );
76 mMessage.replace( tagRX, QString() );
77 }
78 QgsMessageLog::logMessage( mMessage, mTitle.isNull() ? QObject::tr( "Console" ) : mTitle );
79 emit destroyed();
80 delete this;
81}
82
83void QgsMessageOutputConsole::setTitle( const QString &title )
84{
85 mTitle = title;
86}
87
StringFormat
Format of log message.
Definition qgis.h:173
@ Html
HTML message.
Definition qgis.h:175
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).
Default implementation of message output interface.
void setTitle(const QString &title) override
Sets title for the messages.
void destroyed()
signals that object will be destroyed and shouldn't be used anymore
void appendMessage(const QString &message) override
message to be appended to the current text
void setMessage(const QString &message, Qgis::StringFormat format) override
Sets message, it won't be displayed until.
void showMessage(bool blocking=true) override
sends the message to the standard output
Interface for showing messages from QGIS in GUI independent way.
virtual void showMessage(bool blocking=true)=0
display the message to the user and deletes itself
static QgsMessageOutput * createMessageOutput()
function that returns new class derived from QgsMessageOutput (don't forget to delete it then if show...
static void setMessageOutputCreator(MESSAGE_OUTPUT_CREATOR f)
sets function that will be used to create message output
virtual void setMessage(const QString &message, Qgis::StringFormat format)=0
Sets message, it won't be displayed until.
virtual void setTitle(const QString &title)=0
Sets title for the messages.
QgsMessageOutput *(* MESSAGE_OUTPUT_CREATOR)()