Skip to content

Commit 542d8e5

Browse files
author
mhugent
committed
more removed std::couts
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5209 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent a410113 commit 542d8e5

9 files changed

+203
-341
lines changed

src/core/qgslabelattributes.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ QgsLabelAttributes::QgsLabelAttributes( bool def )
5353
mBorderWidthIsSet( false ),
5454
mBorderStyleIsSet( false )
5555
{
56-
#ifdef QGISDEBUG
57-
std::cerr << "QgsLabelAttributes::QgsLabelAttributes()" << std::endl;
58-
#endif
5956

6057
if ( def ) { // set defaults
6158
setText ( "Label" );

src/core/qgslogger.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@
2727
#define QgsDebugMsgLevel(str, level) QgsLogger::debug(QString(str), level,\
2828
__FILE__, __FUNCTION__, __LINE__);
2929
#else
30-
#define QgsDebugMsg(str)
31-
#define QgsDebugMsgVal(str, val, level)
32-
#define QgsDebugMsgLevel(str, level) ""
30+
#define QgsDebugMsg(str)
31+
#define QgsDebugMsgLevel(str, level)
3332
#endif
3433

3534
/**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/core/qgsscalecalculator.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <assert.h>
2121
#include <math.h>
2222
#include <qstring.h>
23+
#include "qgslogger.h"
2324
#include "qgsrect.h"
2425
#include "qgsscalecalculator.h"
2526

@@ -66,9 +67,7 @@ double QgsScaleCalculator::calculate(QgsRect &mapExtent, int canvasWidth)
6667
assert("bad map units");
6768
break;
6869
}
69-
#ifdef QGISDEBUG
70-
std::cerr << "Using conversionFactor of " << conversionFactor << std::endl;
71-
#endif
70+
QgsDebugMsg("Using conversionFactor of " + QString::number(conversionFactor));
7271
double scale = (delta * conversionFactor)/(canvasWidth/mDpi);
7372
return scale;
7473
}
@@ -97,10 +96,6 @@ double QgsScaleCalculator::calculateGeographicDistance(QgsRect &mapExtent)
9796
double R = ra* sqrt(1-pow(e,2))/(1 - pow(e,2)*pow(sin(lat1*rads),2));
9897
double d = c *R; // kilometers;
9998
double meters = d * 1000.0;
100-
101-
102-
#ifdef QGISDEBUG
103-
std::cerr << "Distance across map extent (m): " << meters << std::endl;
104-
#endif
99+
QgsDebugMsg("Distance across map extent (m): " + QString::number(meters));
105100
return meters;
106101
}

src/gui/qgslabel.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ static const char * const ident_ =
4848

4949
QgsLabel::QgsLabel( std::vector<QgsField> const & fields )
5050
{
51-
#ifdef QGISDEBUG
52-
std::cerr << "QgsLabel::QgsLabel()" << std::endl;
53-
#endif
5451

5552
mField = fields;
5653
mLabelField.resize ( LabelFieldCount );

src/gui/qgsmaplayerset.cpp

+8-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
***************************************************************************/
1515
/* $Id$ */
1616

17-
17+
#include "qgslogger.h"
1818
#include "qgsmaplayerset.h"
1919
#include "qgsmaplayerregistry.h"
2020
#include "qgsproject.h"
@@ -29,10 +29,7 @@ void QgsMapLayerSet::setLayerSet(const std::deque<QString>& layers)
2929

3030
void QgsMapLayerSet::updateFullExtent()
3131
{
32-
#ifdef QGISDEBUG
33-
std::cout << "QgsMapLayerSet::updateFullExtent() called !" << std::endl;
34-
#endif
35-
32+
QgsDebugMsg("QgsMapLayerSet::updateFullExtent() called !");
3633
QgsMapLayerRegistry* registry = QgsMapLayerRegistry::instance();
3734
bool projectionsEnabled = (QgsProject::instance()->readNumEntry("SpatialRefSys","/ProjectionsEnabled",0)!=0);
3835

@@ -48,16 +45,13 @@ void QgsMapLayerSet::updateFullExtent()
4845
QgsMapLayer * lyr = registry->mapLayer(*it);
4946
if (lyr == NULL)
5047
{
51-
std::cout << "WARNING: layer '" << (*it).toLocal8Bit().data()
52-
<< "' not found in map layer registry!" << std::endl;
48+
QgsLogger::warning("WARNING: layer '" + (*it) + "' not found in map layer registry!");
5349
}
5450
else
5551
{
56-
57-
#ifdef QGISDEBUG
58-
std::cout << "Updating extent using " << lyr->name().toLocal8Bit().data() << std::endl;
59-
std::cout << "Input extent: " << lyr->extent().stringRep().toLocal8Bit().data() << std::endl;
60-
#endif
52+
QgsDebugMsg("Updating extent using " + lyr->name());
53+
QgsDebugMsg("Input extent: " + lyr->extent().stringRep());
54+
6155
// Layer extents are stored in the coordinate system (CS) of the
6256
// layer. The extent must be projected to the canvas CS prior to passing
6357
// on to the updateFullExtent function
@@ -72,7 +66,8 @@ void QgsMapLayerSet::updateFullExtent()
7266
}
7367
catch (QgsCsException &cse)
7468
{
75-
qDebug( "Transform error caught in %s line %d:\n%s", __FILE__, __LINE__, cse.what());
69+
QgsLogger::warning("Transform error caught in " + QString(__FILE__) + " line " +\
70+
QString::number(__LINE__) + QString(cse.what()));
7671
}
7772
}
7873
else

src/gui/qgsmaprender.cpp

+32-43
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <cmath>
1818

19+
#include "qgslogger.h"
1920
#include "qgsmaprender.h"
2021
#include "qgsscalecalculator.h"
2122
#include "qgsmaptopixel.h"
@@ -143,14 +144,18 @@ void QgsMapRender::adjustExtentToSize()
143144
}
144145

145146
#ifdef QGISDEBUG
146-
std::cout << "========== Current Scale ==========" << std::endl;
147-
std::cout << "Current extent is " << mExtent.stringRep().toLocal8Bit().data() << std::endl;
148-
std::cout << "MuppX is: " << muppX << "\n" << "MuppY is: " << muppY << std::endl;
149-
std::cout << "Pixmap width: " << myWidth << ", height: " << myHeight << std::endl;
150-
std::cout << "Extent width: " << mExtent.width() << ", height: " << mExtent.height() << std::endl;
151-
std::cout << "whitespace: " << whitespace << std::endl;
147+
QgsDebugMsg("========== Current Scale ==========");
148+
QgsDebugMsg("Current extent is " + mExtent.stringRep());
149+
QgsLogger::debug("MuppX", muppX, 1, __FILE__, __FUNCTION__, __LINE__);
150+
QgsLogger::debug("MuppY", muppY, 1, __FILE__, __FUNCTION__, __LINE__);
151+
QgsLogger::debug("Pixmap width", myWidth, 1, __FILE__, __FUNCTION__, __LINE__);
152+
QgsLogger::debug("Pixmap height", myHeight, 1, __FILE__, __FUNCTION__, __LINE__);
153+
QgsLogger::debug("Extent width", mExtent.width(), 1, __FILE__, __FUNCTION__, __LINE__);
154+
QgsLogger::debug("Extent height", mExtent.height(), 1, __FILE__, __FUNCTION__, __LINE__);
155+
QgsLogger::debug("whitespace: ", whitespace, 1, __FILE__, __FUNCTION__, __LINE__);
152156
#endif
153157

158+
154159
// update extent
155160
mExtent.setXmin(dxmin);
156161
mExtent.setXmax(dxmax);
@@ -161,8 +166,7 @@ void QgsMapRender::adjustExtentToSize()
161166
mScale = mScaleCalculator->calculate(mExtent, myWidth);
162167

163168
#ifdef QGISDEBUG
164-
std::cout << "Scale (assuming meters as map units) = 1:" << mScale << std::endl;
165-
std::cout << "------------------------------------------ " << std::endl;
169+
QgsLogger::debug("Scale (assuming meters as map units) = 1", mScale, 1, __FILE__, __FUNCTION__, __LINE__);
166170
#endif
167171

168172
mCoordXForm->setParameters(mMupp, dxmin, dymin, myHeight);
@@ -171,14 +175,11 @@ void QgsMapRender::adjustExtentToSize()
171175

172176
void QgsMapRender::render(QPainter* painter)
173177
{
174-
175-
#ifdef QGISDEBUG
176-
std::cout << "========== Rendering ==========" << std::endl;
177-
#endif
178+
QgsDebugMsg("========== Rendering ==========");
178179

179180
if (mExtent.isEmpty())
180181
{
181-
std::cout << "empty extent... not rendering" << endl;
182+
QgsLogger::warning("empty extent... not rendering");
182183
return;
183184
}
184185

@@ -191,7 +192,7 @@ void QgsMapRender::render(QPainter* painter)
191192
int myRenderCounter = 0;
192193

193194
#ifdef QGISDEBUG
194-
std::cout << "QgsMapRender::render: Starting to render layer stack." << std::endl;
195+
QgsDebugMsg("QgsMapRender::render: Starting to render layer stack.");
195196
QTime renderTime;
196197
renderTime.start();
197198
#endif
@@ -201,49 +202,41 @@ void QgsMapRender::render(QPainter* painter)
201202

202203
while (li != layers.end())
203204
{
204-
#ifdef QGISDEBUG
205-
std::cout << "QgsMapRender::render: at layer item '" << (*li).toLocal8Bit().data() << "'." << std::endl;
206-
#endif
205+
QgsDebugMsg("QgsMapRender::render: at layer item '" + (*li));
207206

208207
// This call is supposed to cause the progress bar to
209208
// advance. However, it seems that updating the progress bar is
210209
// incompatible with having a QPainter active (the one that is
211210
// passed into this function), as Qt produces a number of errors
212211
// when try to do so. I'm (Gavin) not sure how to fix this, but
213212
// added these comments and debug statement to help others...
214-
std::cerr << "If there is a QPaintEngine error here, it is caused by an"
215-
<< " emit call just after line " << __LINE__
216-
<< " in file " << __FILE__ << ".\n";
213+
QgsDebugMsg("If there is a QPaintEngine error here, it is caused by an emit call");
217214

218215
emit setProgress(myRenderCounter++,layers.size());
219216
QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer(*li);
220217

221218
if (!ml)
222219
{
223-
#ifdef QGISDEBUG
224-
std::cout << "QgsMapRender::render: layer not found in registry!" << std::endl;
225-
#endif
220+
QgsLogger::warning("QgsMapRender::render: layer not found in registry!");
226221
li++;
227222
continue;
228223
}
229224

230225
#ifdef QGISDEBUG
231-
std::cout << "QgsMapRender::render: Rendering layer " << ml->name().toLocal8Bit().data() << '\n'
232-
<< " Layer minscale " << ml->minScale()
233-
<< ", maxscale " << ml->maxScale() << '\n'
234-
<< " Scale dep. visibility enabled? "
235-
<< ml->scaleBasedVisibility() << '\n'
236-
<< " Input extent: " << ml->extent().stringRep().toLocal8Bit().data()
237-
<< std::endl;
226+
QgsDebugMsg("QgsMapRender::render: Rendering layer " + ml->name());
227+
QgsLogger::debug(" Layer minscale ", ml->minScale(), 1, __FILE__, __FUNCTION__, __LINE__);
228+
QgsLogger::debug(" Layer maxscale ", ml->maxScale(), 1, __FILE__, __FUNCTION__, __LINE__);
229+
QgsLogger::debug(" Scale dep. visibility enabled? ", ml->scaleBasedVisibility(), 1,\
230+
__FILE__, __FUNCTION__, __LINE__);
231+
QgsLogger::debug(" Input extent: " + ml->extent().stringRep(), 1, __FILE__, __FUNCTION__, __LINE__);
238232
try
239233
{
240-
std::cout << " Transformed extent: "
241-
<< ml->coordinateTransform()->transformBoundingBox(ml->extent()).stringRep().toLocal8Bit().data()
242-
<< std::endl;
234+
QgsDebugMsg(" Transformed extent: " + ml->coordinateTransform()->transformBoundingBox(ml->extent()).stringRep());
243235
}
244236
catch (QgsCsException &cse)
245237
{
246-
qDebug( "Transform error caught in %s line %d:\n%s", __FILE__, __LINE__, cse.what());
238+
QgsLogger::warning("Transform error caught in " + QString(__FILE__) + " line " + QString(__LINE__) +\
239+
QString(cse.what()));
247240
}
248241
#endif
249242

@@ -273,10 +266,8 @@ void QgsMapRender::render(QPainter* painter)
273266
}
274267
else
275268
{
276-
#ifdef QGISDEBUG
277-
std::cout << "QgsMapRender::render: Layer not rendered because it is not within "
278-
<< "the defined visibility scale range" << std::endl;
279-
#endif
269+
QgsDebugMsg("QgsMapRender::render: Layer not rendered because it is not within the defined \
270+
visibility scale range")
280271
}
281272

282273
} // if (ml->visible())
@@ -285,9 +276,7 @@ void QgsMapRender::render(QPainter* painter)
285276

286277
} // while (li != end)
287278

288-
#ifdef QGISDEBUG
289-
std::cout << "QgsMapRender::render: Done rendering map layers" << std::endl;
290-
#endif
279+
QgsDebugMsg("QgsMapRender::render: Done rendering map layers");
291280

292281
if (!mOverview)
293282
{
@@ -321,8 +310,8 @@ void QgsMapRender::render(QPainter* painter)
321310
emit setProgress(1,1);
322311

323312
#ifdef QGISDEBUG
324-
std::cout << "QgsMapRender::render: Rendering done in " <<
325-
renderTime.elapsed() / 1000.0 << " seconds" << std::endl;
313+
QgsLogger::debug("QgsMapRender::render: Rendering done in (seconds)", renderTime.elapsed() / 1000.0, 1,\
314+
__FILE__, __FUNCTION__, __LINE__);
326315
#endif
327316

328317
mDrawing = false;

src/gui/qgsvectorlayer.cpp

+10-31
Original file line numberDiff line numberDiff line change
@@ -902,19 +902,14 @@ void QgsVectorLayer::draw(QPainter * p, QgsRect * viewExtent, QgsMapToPixel * th
902902
msg += cse.what();
903903
qWarning(msg.toLocal8Bit().data());
904904
}
905-
906-
#ifdef QGISDEBUG
907-
std::cerr << "Total features processed is " << featureCount << std::endl;
908-
#endif
905+
QgsDebugMsg("Total features processed is " + QString::number(featureCount));
909906
// XXX Something in our draw event is triggering an additional draw event when resizing [TE 01/26/06]
910907
// XXX Calling this will begin processing the next draw event causing image havoc and recursion crashes.
911908
//qApp->processEvents();
912909
}
913910
else
914911
{
915-
#ifdef QGISDEBUG
916-
qWarning("Warning, QgsRenderer is null in QgsVectorLayer::draw()");
917-
#endif
912+
QgsLogger::warning("QgsRenderer is null in QgsVectorLayer::draw()");
918913
}
919914
}
920915

@@ -2120,9 +2115,7 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
21202115

21212116
// show the extent
21222117
QString s = mbr->stringRep();
2123-
#ifdef QGISDEBUG
2124-
std::cout << "Extent of layer: " << s.toLocal8Bit().data() << std::endl;
2125-
#endif
2118+
QgsDebugMsg("Extent of layer: " + s);
21262119
// store the extent
21272120
layerExtent.setXmax(mbr->xMax());
21282121
layerExtent.setXmin(mbr->xMin());
@@ -2138,16 +2131,11 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
21382131

21392132
if (providerKey == "postgres")
21402133
{
2141-
#ifdef QGISDEBUG
2142-
std::cout << "Beautifying layer name " << layerName.toLocal8Bit().data() << std::endl;
2143-
#endif
2134+
QgsDebugMsg("Beautifying layer name " + layerName);
21442135
// adjust the display name for postgres layers
21452136
layerName = layerName.mid(layerName.find(".") + 1);
21462137
layerName = layerName.left(layerName.find("(") - 1); // Take one away, to avoid a trailing space
2147-
#ifdef QGISDEBUG
2148-
std::cout << "Beautified name is " << layerName.toLocal8Bit().data() << std::endl;
2149-
#endif
2150-
2138+
QgsDebugMsg("Beautifying layer name " + layerName);
21512139
}
21522140

21532141
// upper case the first letter of the layer name
@@ -3238,10 +3226,8 @@ void QgsVectorLayer::setCoordinateSystem()
32383226
//slot is defined inthe maplayer superclass
32393227
connect(mCoordinateTransform, SIGNAL(invalidTransformInput()), this, SLOT(invalidTransformInput()));
32403228

3241-
#ifdef QGISDEBUG
3242-
std::cout << "QgsVectorLayer::setCoordinateSystem ------------------------------------------------start" << std::endl;
3243-
std::cout << "QgsVectorLayer::setCoordinateSystem ----- Computing Coordinate System" << std::endl;
3244-
#endif
3229+
QgsDebugMsg("QgsVectorLayer::setCoordinateSystem ------------------------------------------------start");
3230+
QgsDebugMsg("QgsVectorLayer::setCoordinateSystem ----- Computing Coordinate System");
32453231
//
32463232
// Get the layers project info and set up the QgsCoordinateTransform
32473233
// for this layer
@@ -3255,18 +3241,13 @@ void QgsVectorLayer::setCoordinateSystem()
32553241
{
32563242
mySourceWKT=QString("");
32573243
}
3258-
3259-
#ifdef QGISDEBUG
3260-
std::cout << "QgsVectorLayer::setCoordinateSystem --- using wkt\n" << mySourceWKT.toLocal8Bit().data() << std::endl;
3261-
#endif
3244+
QgsDebugMsg("QgsVectorLayer::setCoordinateSystem --- using wkt " + mySourceWKT);
32623245
mCoordinateTransform->sourceSRS().createFromWkt(mySourceWKT);
32633246
//mCoordinateTransform->sourceSRS()->createFromWkt(getProjectionWKT());
32643247
}
32653248
else
32663249
{
3267-
#ifdef QGISDEBUG
3268-
std::cout << "QgsVectorLayer::setCoordinateSystem --- using srid " << srid << std::endl;
3269-
#endif
3250+
QgsDebugMsg("QgsVectorLayer::setCoordinateSystem --- using srid " + QString::number(srid));
32703251
mCoordinateTransform->sourceSRS().createFromSrid(srid);
32713252
}
32723253

@@ -3287,9 +3268,7 @@ void QgsVectorLayer::setCoordinateSystem()
32873268
// the same as the input projection, otherwise set the output to the
32883269
// project srs
32893270

3290-
#ifdef QGISDEBUG
3291-
std::cout << "Layer registry has " << QgsMapLayerRegistry::instance()->count() << " layers " << std::endl;
3292-
#endif
3271+
QgsDebugMsg("Layer registry has " + QString::number(QgsMapLayerRegistry::instance()->count()) + " layers ");
32933272
if (QgsMapLayerRegistry::instance()->count() ==0)
32943273
{
32953274
mCoordinateTransform->destSRS().createFromProj4(

src/providers/ogr/qgsogrprovider.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ const std::list<std::pair<QString, QString> >& attributes)
15201520
OGRDataSource::DestroyDataSource(dataSource);
15211521

15221522
#ifdef QGISDEBUG
1523-
QgsLogger::debug("GDAL Version number", GDAL_VERSION_NUM, __FILE__, __FUNCTION__, __LINE__);
1523+
QgsLogger::debug("GDAL Version number", GDAL_VERSION_NUM, 1, __FILE__, __FUNCTION__, __LINE__);
15241524
#endif
15251525
#if GDAL_VERSION_NUM >= 1310
15261526
if(reference)

0 commit comments

Comments
 (0)