Skip to content
Permalink
Browse files
[FEATURE] message log window
  • Loading branch information
jef-n committed Nov 18, 2011
1 parent 2dab911 commit 2ab61ff64fedd01a1da6b53c4440605f2e2ec57e
@@ -49,6 +49,7 @@
%Include qgsmaptopixel.sip
%Include qgsmarkercatalogue.sip
%Include qgsmessageoutput.sip
%Include qgsmessagelog.sip
%Include qgsoverlayobject.sip
%Include qgspluginlayer.sip
%Include qgspluginlayerregistry.sip
@@ -0,0 +1,10 @@
class QgsMessageLog
{
%TypeHeaderCode
#include <qgsmessagelog.h>
%End

public:
//! add a message to the instance (and create it if necessary)
static void logMessage( QString message, QString tag = QString::null, int level = 0 );
};
@@ -137,6 +137,7 @@
#include "qgsmergeattributesdialog.h"
#include "qgsmessageviewer.h"
#include "qgsmimedatautils.h"
#include "qgsmessagelog.h"
#include "qgsnewvectorlayerdialog.h"
#include "qgsoptions.h"
#include "qgspastetransformations.h"
@@ -169,7 +170,8 @@
#include "qgsvectorfilewriter.h"
#include "qgsvectorlayer.h"
#include "qgsvectorlayerproperties.h"
//#include "qgswmssourceselect.h"
#include "qgsmessagelogviewer.h"

#include "ogr/qgsogrsublayersdialog.h"
#include "ogr/qgsopenvectorlayerdialog.h"
#include "ogr/qgsvectorlayersaveasdialog.h"
@@ -468,6 +470,15 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
mpGpsDock->setWidget( mpGpsWidget );
mpGpsDock->hide();

mLogViewer = new QgsMessageLogViewer();

mLogDock = new QDockWidget( tr( "Log Messages" ), this );
mLogDock->setObjectName( "MessageLog" );
mLogDock->setAllowedAreas( Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea );
addDockWidget( Qt::BottomDockWidgetArea, mLogDock );
mLogDock->setWidget( mLogViewer );
mLogDock->hide();

mInternalClipboard = new QgsClipboard; // create clipboard
mQgisInterface = new QgisAppInterface( this ); // create the interfce

@@ -490,7 +501,6 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent,
// set graphical message output
QgsMessageOutput::setMessageOutputCreator( messageOutputViewer_ );


// set graphical credential requester
new QgsCredentialDialog( this );

@@ -5458,6 +5468,7 @@ void QgisApp::showMapTip()
}
}
}

void QgisApp::projectPropertiesProjections()
{
// Driver to display the project props dialog and switch to the
@@ -73,6 +73,8 @@ class QgsDecorationCopyright;
class QgsDecorationNorthArrow;
class QgsDecorationScaleBar;

class QgsMessageLogViewer;

#include <QMainWindow>
#include <QToolBar>
#include <QAbstractSocket>
@@ -440,6 +442,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow

void versionReplyFinished();

QgsMessageLogViewer *logViewer() { return mLogViewer; }

protected:

//! Handle state changes (WindowTitleChange)
@@ -773,8 +777,6 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! Activates label property tool
void changeLabelProperties();



signals:
/** emitted when a key is pressed and we want non widget sublasses to be able
to pick up on this (e.g. maplayer) */
@@ -907,7 +909,7 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
QDockWidget *mOverviewDock;
QDockWidget *mpTileScaleDock;
QDockWidget *mpGpsDock;

QDockWidget *mLogDock;

#ifdef Q_WS_MAC
//! Window menu action to select this window
@@ -1076,6 +1078,8 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
//! Persistent GPS toolbox
QgsGPSInformationWidget * mpGpsWidget;

QgsMessageLogViewer *mLogViewer;

QgsPalLabeling* mLBL;

//! project changed
@@ -30,7 +30,7 @@
#include "qgspythonutils.h"
#include "qgisapp.h"
#include "qgslogger.h"

#include "qgsmessagelog.h"

/* typedefs for plugins */
typedef QgisPlugin *create_ui( QgisInterface * qI );
@@ -236,7 +236,7 @@ void QgsPluginRegistry::loadPythonPlugin( QString packageName )
{
if ( !mPythonUtils || !mPythonUtils->isEnabled() )
{
QgsDebugMsg( "Python is not enabled in QGIS." );
QgsMessageLog::logMessage( QObject::tr( "Python is not enabled in QGIS." ), QObject::tr( "Plugins" ) );
return;
}

@@ -261,9 +261,7 @@ void QgsPluginRegistry::loadPythonPlugin( QString packageName )

// add to settings
settings.setValue( "/PythonPlugins/" + packageName, true );
std::cout << "Loaded : " << pluginName.toLocal8Bit().constData() << " (package: "
<< packageName.toLocal8Bit().constData() << ")" << std::endl; // OK

QgsMessageLog::logMessage( QObject::tr( "Loaded %1 (package: %2)" ).arg( pluginName ).arg( packageName ), QObject::tr( "Plugins" ) );
}
}

@@ -288,9 +286,9 @@ void QgsPluginRegistry::loadCppPlugin( QString theFullPathName )
myError += QObject::tr( "Library name is %1\n" ).arg( myLib.fileName() );

bool loaded = myLib.load();
if ( ! loaded )
if ( !loaded )
{
QgsDebugMsg( "Failed to load " + theFullPathName );
QgsMessageLog::logMessage( QObject::tr( "Failed to load %1 (Reason: %2)" ).arg( myLib.fileName() ).arg( myLib.errorString() ), QObject::tr( "Plugins" ) );
return;
}

@@ -317,6 +315,7 @@ void QgsPluginRegistry::loadCppPlugin( QString theFullPathName )
addPlugin( baseName, QgsPluginMetadata( myLib.fileName(), pName(), pl ) );
//add it to the qsettings file [ts]
settings.setValue( "/Plugins/" + baseName, true );
QgsMessageLog::logMessage( QObject::tr( "Loaded %1 (Path: %2)" ).arg( pName() ).arg( myLib.fileName() ), QObject::tr( "Plugins" ) );

QObject *o = dynamic_cast<QObject *>( pl );
if ( o )
@@ -356,14 +355,14 @@ void QgsPluginRegistry::loadCppPlugin( QString theFullPathName )
}
else
{
QgsDebugMsg( "Unable to find the class factory for " + theFullPathName );
QgsMessageLog::logMessage( QObject::tr( "Unable to find the class factory for %1." ).arg( theFullPathName ), QObject::tr( "Plugins" ) );
}

}
break;
default:
// type is unknown
QgsDebugMsg( "Plugin " + theFullPathName + " did not return a valid type and cannot be loaded" );
QgsMessageLog::logMessage( QObject::tr( "Plugin %1 did not return a valid type and cannot be loaded" ).arg( theFullPathName ), QObject::tr( "Plugins" ) );
break;
}
}
@@ -448,8 +447,7 @@ bool QgsPluginRegistry::checkCppPlugin( QString pluginFullPath )
bool loaded = myLib.load();
if ( ! loaded )
{
//QgsDebugMsg("Failed to load " + myLib.fileName());
//QgsDebugMsg("Reason: " + myLib.errorString());
QgsMessageLog::logMessage( QObject::tr( "Failed to load %1 (Reason: %2)" ).arg( myLib.fileName() ).arg( myLib.errorString() ), QObject::tr( "Plugins" ) );
return false;
}

@@ -73,6 +73,7 @@ SET(QGIS_CORE_SRCS
qgsmaptopixel.cpp
qgsmessageoutput.cpp
qgsmimedatautils.cpp
qgsmessagelog.cpp
qgscredentials.cpp
qgsoverlayobject.cpp
qgspalgeometry.cpp
@@ -0,0 +1,40 @@
/***************************************************************************
qgsmessagelog.h - interface for logging messages
----------------------
begin : October 2011
copyright : (C) 2011 by Juergen E. Fischer
email : jef at norbit dot de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsmessagelog.h"
#include <iostream>

class QgsMessageLogConsole;

void (*QgsMessageLog::gmLogger)( QString message, QString tag, int level ) = 0;

void QgsMessageLog::setLogger( void (*f)( QString message, QString tag, int level ) )
{
gmLogger = f;
}

void QgsMessageLog::logMessage( QString message, QString tag, int level )
{
if( !gmLogger )
QgsMessageLogConsole::logger( message, tag, level );
else
gmLogger( message, tag, level );
}

void QgsMessageLogConsole::logger( QString message, QString tag, int level )
{
std::cout << tag.toLocal8Bit().data() << "[" << level << "]: " << message.toLocal8Bit().data() << std::endl;
}

@@ -0,0 +1,60 @@
/***************************************************************************
qgsmessagelog.h - interface for logging messages
----------------------
begin : October 2011
copyright : (C) 2011 by Juergen E. Fischer
email : jef at norbit dot de
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSMESSAGELOG_H
#define QGSMESSAGELOG_H

#include <QString>
#include <QObject>

/** \ingroup core
* Interface for logging messages from QGIS in GUI independent way.
* This class provides abstraction of a tabbed window for showing messages to the user.
* By default QgsMessageLogOutput will be used if not overridden with another
* message log creator function.
* QGIS application uses QgsMessageLog class for logging messages in a dockable
* window for the user.
* \note added in 1.9
*/
class CORE_EXPORT QgsMessageLog
{
public:
//! add a message to the instance (and create it if necessary)
static void logMessage( QString message, QString tag = QString::null, int level = 0 );

//! set log message
static void setLogger( void (*logger)( QString message, QString tag, int level ) );

private:
//! function
static void (*gmLogger)( QString message, QString tag, int level );
};


/**
\brief Default implementation of message logging interface
This class outputs log messages to the standard output. Therefore it might
be the right choice for apps without GUI.
*/
class CORE_EXPORT QgsMessageLogConsole
{
public:
static void logger( QString message, QString tag = QString::null, int level = 0 );
};

#endif
@@ -60,6 +60,7 @@ qgsmaptoolemitpoint.cpp
qgsmaptoolpan.cpp
qgsmaptoolzoom.cpp
qgsmessageviewer.cpp
qgsmessagelogviewer.cpp
qgsnewhttpconnection.cpp
qgsnewvectorlayerdialog.cpp
qgsnumericsortlistviewitem.cpp
@@ -123,6 +124,7 @@ qgsmapcanvas.h
qgsmapoverviewcanvas.h
qgsmaptoolemitpoint.h
qgsmessageviewer.h
qgsmessagelogviewer.h
qgsnewhttpconnection.h
qgsnewvectorlayerdialog.h
qgscredentialdialog.h
@@ -181,6 +183,7 @@ SET(QGIS_GUI_UI_HDRS
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsdetaileditemwidgetbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsgenericprojectionselectorbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsmessageviewer.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsmessagelogviewer.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgscredentialdialog.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsprojectionselectorbase.h
${CMAKE_CURRENT_BINARY_DIR}/../ui/ui_qgsquerybuilderbase.h

0 comments on commit 2ab61ff

Please sign in to comment.