QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 "qgslogger.h"
18 #include "qgsmessagelog.h"
19 
20 #include <QRegExp>
21 
22 static QgsMessageOutput *messageOutputConsole_()
23 {
24  return new QgsMessageOutputConsole;
25 }
26 
27 // default output creator - console
28 MESSAGE_OUTPUT_CREATOR QgsMessageOutput::mMessageOutputCreator = messageOutputConsole_;
29 
30 
32 {
33  mMessageOutputCreator = f;
34 }
35 
37 {
38  return mMessageOutputCreator();
39 }
40 
41 void QgsMessageOutput::showMessage( const QString &title, const QString &message, MessageType msgType )
42 {
44  output->setTitle( title );
45  output->setMessage( message, msgType );
46  output->showMessage();
47 }
48 
50 // QgsMessageOutputConsole
51 
52 void QgsMessageOutputConsole::setMessage( const QString &message, MessageType msgType )
53 {
54  mMessage = message;
55  mMsgType = msgType;
56 }
57 
58 void QgsMessageOutputConsole::appendMessage( const QString &message )
59 {
60  mMessage += message;
61 }
62 
64 {
65  if ( mMsgType == MessageHtml )
66  {
67  mMessage.replace( QLatin1String( "<br>" ), QLatin1String( "\n" ) );
68  mMessage.replace( QLatin1String( "&nbsp;" ), QLatin1String( " " ) );
69  mMessage.replace( QRegExp( "</?[^>]+>" ), QString() );
70  }
71  QgsMessageLog::logMessage( mMessage, mTitle.isNull() ? QObject::tr( "Console" ) : mTitle );
72  emit destroyed();
73  delete this;
74 }
75 
76 void QgsMessageOutputConsole::setTitle( const QString &title )
77 {
78  mTitle = title;
79 }
80 
QgsMessageOutput::setMessage
virtual void setMessage(const QString &message, MessageType msgType)=0
Sets message, it won't be displayed until.
QgsMessageOutputConsole::destroyed
void destroyed()
signals that object will be destroyed and shouldn't be used anymore
QgsMessageOutputConsole::showMessage
void showMessage(bool blocking=true) override
sends the message to the standard output
Definition: qgsmessageoutput.cpp:63
qgsmessageoutput.h
QgsMessageOutputConsole
Default implementation of message output interface.
Definition: qgsmessageoutput.h:98
QgsMessageOutput::showMessage
virtual void showMessage(bool blocking=true)=0
display the message to the user and deletes itself
QgsMessageOutput
Interface for showing messages from QGIS in GUI independent way.
Definition: qgsmessageoutput.h:43
QgsMessageOutput::setMessageOutputCreator
static void setMessageOutputCreator(MESSAGE_OUTPUT_CREATOR f)
sets function that will be used to create message output
Definition: qgsmessageoutput.cpp:31
QgsMessageOutputConsole::appendMessage
void appendMessage(const QString &message) override
message to be appended to the current text
Definition: qgsmessageoutput.cpp:58
QgsMessageOutputConsole::setMessage
void setMessage(const QString &message, MessageType msgType) override
Sets message, it won't be displayed until.
Definition: qgsmessageoutput.cpp:52
QgsMessageOutput::createMessageOutput
static QgsMessageOutput * createMessageOutput()
function that returns new class derived from QgsMessageOutput (don't forget to delete it then if show...
Definition: qgsmessageoutput.cpp:36
QgsMessageOutputConsole::setTitle
void setTitle(const QString &title) override
Sets title for the messages.
Definition: qgsmessageoutput.cpp:76
QgsMessageOutput::setTitle
virtual void setTitle(const QString &title)=0
Sets title for the messages.
QgsMessageOutput::MessageType
MessageType
message can be in plain text or in html format
Definition: qgsmessageoutput.h:47
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
QgsMessageOutput::MessageHtml
@ MessageHtml
Definition: qgsmessageoutput.h:47
qgslogger.h
MESSAGE_OUTPUT_CREATOR
QgsMessageOutput *(* MESSAGE_OUTPUT_CREATOR)()
Definition: qgsmessageoutput.h:27
qgsmessagelog.h