QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
46 // QgsMessageOutputConsole
47 
49  : mMessage( "" )
50  , mMsgType( MessageText )
51 {
52 }
53 
54 void QgsMessageOutputConsole::setMessage( const QString& message, MessageType msgType )
55 {
56  mMessage = message;
57  mMsgType = msgType;
58 }
59 
60 void QgsMessageOutputConsole::appendMessage( const QString& message )
61 {
62  mMessage += message;
63 }
64 
66 {
67  if ( mMsgType == MessageHtml )
68  {
69  mMessage.replace( "<br>", "\n" );
70  mMessage.replace( "&nbsp;", " " );
71  mMessage.replace( QRegExp( "</?[^>]+>" ), "" );
72  }
73  QgsMessageLog::logMessage( mMessage, mTitle.isNull() ? QObject::tr( "Console" ) : mTitle );
74  emit destroyed();
75  delete this;
76 }
77 
78 void QgsMessageOutputConsole::setTitle( const QString& title )
79 {
80  mTitle = title;
81 }