Skip to content

Commit

Permalink
additional macro for logger, more std::cout cleans
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5177 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 5, 2006
1 parent 30d4b24 commit df6922e
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 192 deletions.
9 changes: 6 additions & 3 deletions src/core/qgslogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@
* *
***************************************************************************/

#ifndef QGSLOGGER
#define QGSLOGGER
#ifndef QGSLOGGER_H
#define QGSLOGGER_H

#include <iostream>
#include <sstream>
#include <QString>

#ifdef QGISDEBUG
#define QgsDebugMsg(str) QgsLogger::debug(QString(str), 1, __FILE__, __FUNCTION__, __LINE__);
#define QgsDebugMsgLevel(str, level) QgsLogger::debug(QString(str), level,\
__FILE__, __FUNCTION__, __LINE__);
#else
#define QgsDebugMsg(str)
#define QgsDebugMsg(str)
#define QgsDebugMsgVal(str, val, level)
#endif

/**QgsLogger is a class to print debug/warning/error messages to the console. The advantage of this class over std::cout, std::cerr & co. is that the output can be controlled with environment variables:
Expand Down
43 changes: 11 additions & 32 deletions src/gui/qgsmaplayerregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <iostream>

#include "qgsmaplayerregistry.h"
#include "qgslogger.h"
#include "qgsproject.h"


Expand All @@ -41,9 +42,7 @@ QgsMapLayerRegistry *QgsMapLayerRegistry::instance()

QgsMapLayerRegistry::QgsMapLayerRegistry(QObject *parent, const char *name) : QObject(parent,name)
{
#ifdef QGISDEBUG
std::cout << "QgsMapLayerRegistry created!" << std::endl;
#endif
QgsDebugMsg("QgsMapLayerRegistry created!");
// constructor does nothing
}
// get the layer count (number of registered layers)
Expand Down Expand Up @@ -93,9 +92,7 @@ QgsMapLayer * QgsMapLayerRegistry::mapLayer(QString theLayerId)
QgsMapLayer *
QgsMapLayerRegistry::addMapLayer( QgsMapLayer * theMapLayer, bool theEmitSignal )
{
#ifdef QGISDEBUG
std::cout << "QgsMapLayerRegistry::addMaplayer - '" << theMapLayer->name().toLocal8Bit().data() << "'."<< std::endl;
#endif
QgsDebugMsg("QgsMapLayerRegistry::addMaplayer - '" + theMapLayer->name());
//check the layer is not already registered!
std::map<QString,QgsMapLayer*>::iterator myIterator = mMapLayers.find(theMapLayer->getLayerID());
//if myIterator returns mMapLayers.end() then it does not exist in registry and its safe to add it
Expand All @@ -113,10 +110,7 @@ QgsMapLayer *
}
else
{

#ifdef QGISDEBUG
std::cout << "addMaplayer - " << theMapLayer->name().toLocal8Bit().data() << " already registered" << std::endl;
#endif
QgsDebugMsg("addMaplayer - " + theMapLayer->name() + " already registered");
return 0x0;
}
} // QgsMapLayerRegistry::addMapLayer
Expand All @@ -125,31 +119,21 @@ QgsMapLayer *

void QgsMapLayerRegistry::removeMapLayer(QString theLayerId, bool theEmitSignal)
{
#ifdef QGISDEBUG
std::cout << "QgsMapLayerRegistry::removemaplayer - emitting signal to notify all users of this layer to release it." << std::endl;
#endif
QgsDebugMsg("QgsMapLayerRegistry::removemaplayer - emitting signal to notify all users of this layer to release it.");
if (theEmitSignal)
emit layerWillBeRemoved(theLayerId);
#ifdef QGISDEBUG
std::cout << "QgsMapLayerRegistry::removemaplayer - deleting map layer." << std::endl;
#endif
QgsDebugMsg("QgsMapLayerRegistry::removemaplayer - deleting map layer.");
delete mMapLayers[theLayerId];
#ifdef QGISDEBUG
std::cout << "QgsMapLayerRegistry::removemaplayer - unregistering map layer." << std::endl;
#endif
QgsDebugMsg("QgsMapLayerRegistry::removemaplayer - unregistering map layer.");
mMapLayers.erase(theLayerId);
#ifdef QGISDEBUG
std::cout << "QgsMapLayerRegistry::removemaplayer - operation complete." << std::endl;
#endif
QgsDebugMsg("QgsMapLayerRegistry::removemaplayer - operation complete.");
// notify the project we've made a change
QgsProject::instance()->dirty(true);
}

void QgsMapLayerRegistry::removeAllMapLayers()
{
#ifdef QGISDEBUG
std::cout << "QgsMapLayerRegistry::removeAllMapLayers"<< std::endl;
#endif
QgsDebugMsg("QgsMapLayerRegistry::removeAllMapLayers");

// moved before physically removing the layers
emit removedAll(); // now let all canvas Observers know to clear
Expand All @@ -175,18 +159,13 @@ void QgsMapLayerRegistry::removeAllMapLayers()

std::map<QString,QgsMapLayer*> & QgsMapLayerRegistry::mapLayers()
{
#ifdef QGISDEBUG
std::cout << "QgsMapLayerRegistry::mapLayers"<< std::endl;
#endif

QgsDebugMsg("QgsMapLayerRegistry::mapLayers");
return mMapLayers;
}



void QgsMapLayerRegistry::connectNotify( const char * signal )
{
#ifdef QGISDEBUG
std::cerr << "QgsMapLayerRegistry connected to " << signal << "\n";
#endif
QgsDebugMsg("QgsMapLayerRegistry connected to " + QString(signal));
} // QgsMapLayerRegistry::connectNotify
Loading

0 comments on commit df6922e

Please sign in to comment.