Skip to content

Commit 1026372

Browse files
author
mhugent
committed
additional macro for logger, more std::cout cleans
git-svn-id: http://svn.osgeo.org/qgis/trunk@5177 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 5f9ef38 commit 1026372

File tree

4 files changed

+110
-192
lines changed

4 files changed

+110
-192
lines changed

src/core/qgslogger.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@
1515
* *
1616
***************************************************************************/
1717

18-
#ifndef QGSLOGGER
19-
#define QGSLOGGER
18+
#ifndef QGSLOGGER_H
19+
#define QGSLOGGER_H
2020

2121
#include <iostream>
2222
#include <sstream>
2323
#include <QString>
2424

2525
#ifdef QGISDEBUG
2626
#define QgsDebugMsg(str) QgsLogger::debug(QString(str), 1, __FILE__, __FUNCTION__, __LINE__);
27+
#define QgsDebugMsgLevel(str, level) QgsLogger::debug(QString(str), level,\
28+
__FILE__, __FUNCTION__, __LINE__);
2729
#else
28-
#define QgsDebugMsg(str)
30+
#define QgsDebugMsg(str)
31+
#define QgsDebugMsgVal(str, val, level)
2932
#endif
3033

3134
/**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:

src/gui/qgsmaplayerregistry.cpp

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <iostream>
2020

2121
#include "qgsmaplayerregistry.h"
22+
#include "qgslogger.h"
2223
#include "qgsproject.h"
2324

2425

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

4243
QgsMapLayerRegistry::QgsMapLayerRegistry(QObject *parent, const char *name) : QObject(parent,name)
4344
{
44-
#ifdef QGISDEBUG
45-
std::cout << "QgsMapLayerRegistry created!" << std::endl;
46-
#endif
45+
QgsDebugMsg("QgsMapLayerRegistry created!");
4746
// constructor does nothing
4847
}
4948
// get the layer count (number of registered layers)
@@ -93,9 +92,7 @@ QgsMapLayer * QgsMapLayerRegistry::mapLayer(QString theLayerId)
9392
QgsMapLayer *
9493
QgsMapLayerRegistry::addMapLayer( QgsMapLayer * theMapLayer, bool theEmitSignal )
9594
{
96-
#ifdef QGISDEBUG
97-
std::cout << "QgsMapLayerRegistry::addMaplayer - '" << theMapLayer->name().toLocal8Bit().data() << "'."<< std::endl;
98-
#endif
95+
QgsDebugMsg("QgsMapLayerRegistry::addMaplayer - '" + theMapLayer->name());
9996
//check the layer is not already registered!
10097
std::map<QString,QgsMapLayer*>::iterator myIterator = mMapLayers.find(theMapLayer->getLayerID());
10198
//if myIterator returns mMapLayers.end() then it does not exist in registry and its safe to add it
@@ -113,10 +110,7 @@ QgsMapLayer *
113110
}
114111
else
115112
{
116-
117-
#ifdef QGISDEBUG
118-
std::cout << "addMaplayer - " << theMapLayer->name().toLocal8Bit().data() << " already registered" << std::endl;
119-
#endif
113+
QgsDebugMsg("addMaplayer - " + theMapLayer->name() + " already registered");
120114
return 0x0;
121115
}
122116
} // QgsMapLayerRegistry::addMapLayer
@@ -125,31 +119,21 @@ QgsMapLayer *
125119

126120
void QgsMapLayerRegistry::removeMapLayer(QString theLayerId, bool theEmitSignal)
127121
{
128-
#ifdef QGISDEBUG
129-
std::cout << "QgsMapLayerRegistry::removemaplayer - emitting signal to notify all users of this layer to release it." << std::endl;
130-
#endif
122+
QgsDebugMsg("QgsMapLayerRegistry::removemaplayer - emitting signal to notify all users of this layer to release it.");
131123
if (theEmitSignal)
132124
emit layerWillBeRemoved(theLayerId);
133-
#ifdef QGISDEBUG
134-
std::cout << "QgsMapLayerRegistry::removemaplayer - deleting map layer." << std::endl;
135-
#endif
125+
QgsDebugMsg("QgsMapLayerRegistry::removemaplayer - deleting map layer.");
136126
delete mMapLayers[theLayerId];
137-
#ifdef QGISDEBUG
138-
std::cout << "QgsMapLayerRegistry::removemaplayer - unregistering map layer." << std::endl;
139-
#endif
127+
QgsDebugMsg("QgsMapLayerRegistry::removemaplayer - unregistering map layer.");
140128
mMapLayers.erase(theLayerId);
141-
#ifdef QGISDEBUG
142-
std::cout << "QgsMapLayerRegistry::removemaplayer - operation complete." << std::endl;
143-
#endif
129+
QgsDebugMsg("QgsMapLayerRegistry::removemaplayer - operation complete.");
144130
// notify the project we've made a change
145131
QgsProject::instance()->dirty(true);
146132
}
147133

148134
void QgsMapLayerRegistry::removeAllMapLayers()
149135
{
150-
#ifdef QGISDEBUG
151-
std::cout << "QgsMapLayerRegistry::removeAllMapLayers"<< std::endl;
152-
#endif
136+
QgsDebugMsg("QgsMapLayerRegistry::removeAllMapLayers");
153137

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

176160
std::map<QString,QgsMapLayer*> & QgsMapLayerRegistry::mapLayers()
177161
{
178-
#ifdef QGISDEBUG
179-
std::cout << "QgsMapLayerRegistry::mapLayers"<< std::endl;
180-
#endif
181-
162+
QgsDebugMsg("QgsMapLayerRegistry::mapLayers");
182163
return mMapLayers;
183164
}
184165

185166

186167

187168
void QgsMapLayerRegistry::connectNotify( const char * signal )
188169
{
189-
#ifdef QGISDEBUG
190-
std::cerr << "QgsMapLayerRegistry connected to " << signal << "\n";
191-
#endif
170+
QgsDebugMsg("QgsMapLayerRegistry connected to " + QString(signal));
192171
} // QgsMapLayerRegistry::connectNotify

0 commit comments

Comments
 (0)