QGIS API Documentation  2.4.0-Chugiak
 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
29 
30 
32 {
34 }
35 
37 {
38  return mMessageOutputCreator();
39 }
40 
42 {
43 }
44 
46 // QgsMessageOutputConsole
47 
49  : mMessage( "" )
50 {
51 }
52 
53 void QgsMessageOutputConsole::setMessage( const QString& message, MessageType msgType )
54 {
55  mMessage = message;
56  mMsgType = msgType;
57 }
58 
59 void QgsMessageOutputConsole::appendMessage( const QString& message )
60 {
61  mMessage += message;
62 }
63 
65 {
66  if ( mMsgType == MessageHtml )
67  {
68  mMessage.replace( "<br>", "\n" );
69  mMessage.replace( "&nbsp;", " " );
70  mMessage.replace( QRegExp( "</?[^>]+>" ), "" );
71  }
72  QgsMessageLog::logMessage( mMessage, mTitle.isNull() ? QObject::tr( "Console" ) : mTitle );
73  emit destroyed();
74  delete this;
75 }
76 
77 void QgsMessageOutputConsole::setTitle( const QString& title )
78 {
79  mTitle = title;
80 }
static void setMessageOutputCreator(MESSAGE_OUTPUT_CREATOR f)
sets function that will be used to create message output
virtual void setTitle(const QString &title)
set title for the messages
MessageType
message can be in plain text or in html format
static MESSAGE_OUTPUT_CREATOR mMessageOutputCreator
Pointer to the function which creates the class for output.
static QgsMessageOutput * messageOutputConsole_()
virtual void appendMessage(const QString &message)
message to be appended to the current text
static QgsMessageOutput * createMessageOutput()
function that returns new class derived from QgsMessageOutput (don't forget to delete it then) ...
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
QgsMessageOutput *(* MESSAGE_OUTPUT_CREATOR)()
Default implementation of message output interface.
virtual void showMessage(bool blocking=true)
sends the message to the standard output
QString mMessage
stores current message
QString mTitle
stores current title
Interface for showing messages from QGIS in GUI independent way.
virtual ~QgsMessageOutput()
virtual destructor
virtual void setMessage(const QString &message, MessageType msgType)
set message, it won't be displayed until
void destroyed()
signals that object will be destroyed and shouldn't be used anymore
#define tr(sourceText)