QGIS API Documentation 3.41.0-Master (3440c17df1d)
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#include "moc_qgsmessageoutput.cpp"
18#include "qgslogger.h"
19#include "qgsmessagelog.h"
20
21#include <QRegularExpression>
22
23static QgsMessageOutput *messageOutputConsole_()
24{
25 return new QgsMessageOutputConsole;
26}
27
28// default output creator - console
29MESSAGE_OUTPUT_CREATOR QgsMessageOutput::mMessageOutputCreator = messageOutputConsole_;
30
31
33{
34 mMessageOutputCreator = f;
35}
36
38{
39 return mMessageOutputCreator();
40}
41
42void QgsMessageOutput::showMessage( const QString &title, const QString &message, MessageType msgType )
43{
45 output->setTitle( title );
46 output->setMessage( message, msgType );
47 output->showMessage();
48}
49
51// QgsMessageOutputConsole
52
53void QgsMessageOutputConsole::setMessage( const QString &message, MessageType msgType )
54{
55 mMessage = message;
56 mMsgType = msgType;
57}
58
59void QgsMessageOutputConsole::appendMessage( const QString &message )
60{
61 mMessage += message;
62}
63
65{
66 if ( mMsgType == MessageHtml )
67 {
68 mMessage.replace( QLatin1String( "<br>" ), QLatin1String( "\n" ) );
69 mMessage.replace( QLatin1String( "&nbsp;" ), QLatin1String( " " ) );
70 const thread_local QRegularExpression tagRX( QStringLiteral( "</?[^>]+>" ) );
71 mMessage.replace( tagRX, QString() );
72 }
73 QgsMessageLog::logMessage( mMessage, mTitle.isNull() ? QObject::tr( "Console" ) : mTitle );
74 emit destroyed();
75 delete this;
76}
77
78void QgsMessageOutputConsole::setTitle( const QString &title )
79{
80 mTitle = title;
81}
82
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Default implementation of message output interface.
void setMessage(const QString &message, MessageType msgType) override
Sets message, it won't be displayed until.
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 showMessage(bool blocking=true) override
sends the message to the standard output
Interface for showing messages from QGIS in GUI independent way.
MessageType
message can be in plain text or in html format
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, MessageType msgType)=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)()