QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
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 
42 {
43 }
44 
45 
46 void QgsMessageOutput::showMessage( const QString& title, const QString& message, MessageType msgType )
47 {
49  output->setTitle( title );
50  output->setMessage( message, msgType );
51  output->showMessage();
52 }
53 
55 // QgsMessageOutputConsole
56 
58  : mMessage( "" )
59  , mMsgType( MessageText )
60 {
61 }
62 
64 {
65  mMessage = message;
66  mMsgType = msgType;
67 }
68 
70 {
71  mMessage += message;
72 }
73 
75 {
76  if ( mMsgType == MessageHtml )
77  {
78  mMessage.replace( "<br>", "\n" );
79  mMessage.replace( "&nbsp;", " " );
80  mMessage.replace( QRegExp( "</?[^>]+>" ), "" );
81  }
82  QgsMessageLog::logMessage( mMessage, mTitle.isNull() ? QObject::tr( "Console" ) : mTitle );
83  emit destroyed();
84  delete this;
85 }
86 
88 {
89  mTitle = title;
90 }
91 
static void setMessageOutputCreator(MESSAGE_OUTPUT_CREATOR f)
sets function that will be used to create message output
MessageType
message can be in plain text or in html format
virtual void setTitle(const QString &title)=0
set title for the messages
static QgsMessageOutput * messageOutputConsole_()
static QgsMessageOutput * createMessageOutput()
function that returns new class derived from QgsMessageOutput (don&#39;t forget to delete it then if show...
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isNull() const
QgsMessageOutput *(* MESSAGE_OUTPUT_CREATOR)()
Default implementation of message output interface.
virtual void setMessage(const QString &message, MessageType msgType) override
set message, it won&#39;t be displayed until
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
virtual void setMessage(const QString &message, MessageType msgType)=0
set message, it won&#39;t be displayed until
virtual void setTitle(const QString &title) override
set title for the messages
virtual void appendMessage(const QString &message) override
message to be appended to the current text
virtual void showMessage(bool blocking=true)=0
display the message to the user and deletes itself
QString & replace(int position, int n, QChar after)
Interface for showing messages from QGIS in GUI independent way.
virtual ~QgsMessageOutput()
virtual destructor
void destroyed()
signals that object will be destroyed and shouldn&#39;t be used anymore
virtual void showMessage(bool blocking=true) override
sends the message to the standard output