Quantum GIS API Documentation  1.8
src/core/qgsmessageoutput.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsmessageoutput.h  -  interface for showing messages
00003     ----------------------
00004     begin                : April 2006
00005     copyright            : (C) 2006 by Martin Dobias
00006     email                : wonder.sk at gmail dot com
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 #include "qgsmessageoutput.h"
00017 #include "qgslogger.h"
00018 #include "qgsmessagelog.h"
00019 
00020 #include <QRegExp>
00021 
00022 static QgsMessageOutput* messageOutputConsole_()
00023 {
00024   return new QgsMessageOutputConsole;
00025 }
00026 
00027 // default output creator - console
00028 MESSAGE_OUTPUT_CREATOR QgsMessageOutput::mMessageOutputCreator = messageOutputConsole_;
00029 
00030 
00031 void QgsMessageOutput::setMessageOutputCreator( MESSAGE_OUTPUT_CREATOR f )
00032 {
00033   mMessageOutputCreator = f;
00034 }
00035 
00036 QgsMessageOutput* QgsMessageOutput::createMessageOutput()
00037 {
00038   return mMessageOutputCreator();
00039 }
00040 
00041 QgsMessageOutput::~QgsMessageOutput()
00042 {
00043 }
00044 
00046 // QgsMessageOutputConsole
00047 
00048 QgsMessageOutputConsole::QgsMessageOutputConsole()
00049     : mMessage( "" )
00050 {
00051 }
00052 
00053 void QgsMessageOutputConsole::setMessage( const QString& message, MessageType msgType )
00054 {
00055   mMessage = message;
00056   mMsgType = msgType;
00057 }
00058 
00059 void QgsMessageOutputConsole::appendMessage( const QString& message )
00060 {
00061   mMessage += message;
00062 }
00063 
00064 void QgsMessageOutputConsole::showMessage( bool )
00065 {
00066   if ( mMsgType == MessageHtml )
00067   {
00068     mMessage.replace( "<br>", "\n" );
00069     mMessage.replace( "&nbsp;", " " );
00070     mMessage.replace( QRegExp("</?[^>]+>"), "" );
00071   }
00072   QgsMessageLog::logMessage( mMessage, mTitle.isNull() ? QObject::tr( "Console" ) : mTitle );
00073   emit destroyed();
00074   delete this;
00075 }
00076 
00077 void QgsMessageOutputConsole::setTitle( const QString& title )
00078 {
00079   mTitle = title;
00080 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines