Skip to content

Commit d751036

Browse files
committedMay 25, 2012
validation/geometry/threading fixes:
- fTools/polygon centroids: catch missing centroid with invalid geometry (fixes #4963) - fTools/validate geometry: * fix final position of progress bar * don't use isGeosValid() * zoom to feature on locationless errors (including OTFR support) * store/restore dialog position - QgsGeometry(Validator): * log GEOS exceptions * (closed) rings need at least 4 points not 3 * log error when geometry can't be exported to GEOS * don't produce "geometry is valid" error - improve logging from threads * keep message output from main thread as popup * log message from threads to message log (fixes crash on python error in thread)
1 parent d208b29 commit d751036

File tree

8 files changed

+126
-80
lines changed

8 files changed

+126
-80
lines changed
 

‎python/plugins/fTools/tools/doGeometry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,11 @@ def polygon_centroids( self ):
620620
self.emit( SIGNAL( "runStatus( PyQt_PyObject )" ), nElement )
621621
inGeom = inFeat.geometry()
622622
atMap = inFeat.attributeMap()
623-
outGeom = QgsGeometry( inGeom.centroid() )
623+
outGeom = inGeom.centroid()
624624
if outGeom is None:
625625
return "math_error"
626626
outFeat.setAttributeMap( atMap )
627-
outFeat.setGeometry( outGeom )
627+
outFeat.setGeometry( QgsGeometry( outGeom ) )
628628
writer.addFeature( outFeat )
629629
del writer
630630
return True

‎python/plugins/fTools/tools/doValidate.py

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ def __init__(self, iface):
9393
self.storedScale = self.iface.mapCanvas().scale()
9494
# create marker for error
9595
self.marker = MarkerErrorGeometry(self.iface.mapCanvas())
96+
97+
settings = QSettings()
98+
self.restoreGeometry( settings.value("/fTools/ValidateDialog/geometry").toByteArray() )
99+
100+
def closeEvent(self, e):
101+
settings = QSettings()
102+
settings.setValue( "/fTools/ValidateDialog/geometry", QVariant(self.saveGeometry()) )
103+
QMainWindow.closeEvent(self, e)
104+
del self.marker
96105

97106
def keyPressEvent( self, e ):
98107
if ( e.modifiers() == Qt.ControlModifier or \
@@ -115,38 +124,56 @@ def accept( self ):
115124
elif self.cmbField.isVisible() and self.cmbField.currentText() == "":
116125
QMessageBox.information( self, self.tr("Error!"), self.tr( "Please specify input field" ) )
117126
else:
118-
self.validate( self.inShape.currentText(), self.useSelected.checkState() )
127+
self.vlayer = ftools_utils.getVectorLayerByName( self.inShape.currentText() )
128+
self.validate( self.useSelected.checkState() )
119129

120130
def zoomToError(self, curr, prev):
121131
if curr is None:
122132
return
123133
row = curr.row() # if we clicked in the first column, we want the second
124134
item = self.tblUnique.item(row, 1)
125135

126-
e = item.data(Qt.UserRole).toPyObject()
127-
if e is None:
128-
return
129-
130136
mc = self.iface.mapCanvas()
131-
x = e.x()
132-
y = e.y()
133-
self.marker.setGeom(x, y) # Set Marker
134137
mc.zoomToPreviousExtent()
135-
scale = mc.scale()
136-
rect = QgsRectangle(float(x)-(4.0/scale),float(y)-(4.0/scale),
137-
float(x)+(4.0/scale),float(y)+(4.0/scale))
138+
139+
if mc.mapRenderer().hasCrsTransformEnabled():
140+
ct = QgsCoordinateTransform( self.vlayer.crs(), mc.mapRenderer().destinationCrs() )
141+
142+
e = item.data(Qt.UserRole).toPyObject()
143+
144+
if type(e)==QgsPoint:
145+
if not ct is None:
146+
e = ct.transform( e )
147+
148+
self.marker.setGeom(e.x(), e.y())
149+
150+
rect = mc.extent()
151+
rect.expand( 0.25, e )
152+
153+
else:
154+
self.marker.reset()
155+
156+
ft = QgsFeature()
157+
(fid,ok) = self.tblUnique.item(row, 0).text().toInt()
158+
if not ok or not self.vlayer.featureAtId( fid, ft, True):
159+
return
160+
161+
rect = ft.geometry().boundingBox()
162+
if not ct is None:
163+
rect = ct.transformBoundingBox( rect )
164+
rect.expand(1.05)
165+
138166
# Set the extent to our new rectangle
139167
mc.setExtent(rect)
140168
# Refresh the map
141169
mc.refresh()
142170

143-
def validate( self, myLayer, mySelection ):
144-
vlayer = ftools_utils.getVectorLayerByName( myLayer )
171+
def validate( self, mySelection ):
145172
self.tblUnique.clearContents()
146173
self.tblUnique.setRowCount( 0 )
147174
self.lstCount.clear()
148175
self.buttonOk.setEnabled( False )
149-
self.testThread = validateThread( self.iface.mainWindow(), self, vlayer, mySelection )
176+
self.testThread = validateThread( self.iface.mainWindow(), self, self.vlayer, mySelection )
150177
QObject.connect( self.testThread, SIGNAL( "runFinished(PyQt_PyObject)" ), self.runFinishedFromThread )
151178
QObject.connect( self.testThread, SIGNAL( "runStatus(PyQt_PyObject)" ), self.runStatusFromThread )
152179
QObject.connect( self.testThread, SIGNAL( "runRange(PyQt_PyObject)" ), self.runRangeFromThread )
@@ -214,7 +241,6 @@ def run( self ):
214241
self.running = True
215242
output = self.check_geometry( self.vlayer )
216243
self.emit( SIGNAL( "runFinished(PyQt_PyObject)" ), output )
217-
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), 100 )
218244

219245
def stop(self):
220246
self.running = False
@@ -243,7 +269,7 @@ def check_geometry( self, vlayer ):
243269
self.emit(SIGNAL("runStatus(PyQt_PyObject)"), nElement)
244270
nElement += 1
245271
# Check Add error
246-
if not (geom.isGeosEmpty() or geom.isGeosValid() ) :
272+
if not geom.isGeosEmpty():
247273
lstErrors.append((feat.id(), list(geom.validateGeometry())))
248274
self.emit( SIGNAL( "runStatus(PyQt_PyObject)" ), nFeat )
249275
return lstErrors

‎src/app/qgisapp.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include <QToolButton>
6666
#include <QVBoxLayout>
6767
#include <QWhatsThis>
68+
#include <QThread>
6869

6970
#include <qgsnetworkaccessmanager.h>
7071

@@ -318,7 +319,10 @@ static void setTitleBarText_( QWidget & qgisApp )
318319
*/
319320
static QgsMessageOutput *messageOutputViewer_()
320321
{
321-
return new QgsMessageViewer( QgisApp::instance() );
322+
if ( QThread::currentThread() == QApplication::instance()->thread() )
323+
return new QgsMessageViewer( QgisApp::instance() );
324+
else
325+
return new QgsMessageOutputConsole();
322326
}
323327

324328
static void customSrsValidation_( QgsCoordinateReferenceSystem* srs )

‎src/app/qgscustomization.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include <QToolButton>
3636
#include <QStatusBar>
3737
#include <QMetaObject>
38-
#include <QThread>
3938

4039
#ifdef Q_OS_MACX
4140
QgsCustomizationDialog::QgsCustomizationDialog( QWidget *parent )

‎src/core/qgsgeometry.cpp

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ email : morb at ozemail dot com dot au
2222
#include "qgsgeometry.h"
2323
#include "qgsapplication.h"
2424
#include "qgslogger.h"
25+
#include "qgsmessagelog.h"
2526
#include "qgspoint.h"
2627
#include "qgsrectangle.h"
2728

@@ -36,8 +37,7 @@ email : morb at ozemail dot com dot au
3637
#define CATCH_GEOS(r) \
3738
catch (GEOSException &e) \
3839
{ \
39-
Q_UNUSED(e); \
40-
QgsDebugMsg("GEOS: " + QString( e.what() ) ); \
40+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr("GEOS") ); \
4141
return r; \
4242
}
4343

@@ -90,7 +90,7 @@ static void throwGEOSException( const char *fmt, ... )
9090
vsnprintf( buffer, sizeof buffer, fmt, ap );
9191
va_end( ap );
9292

93-
QgsDebugMsg( QString( "GEOS exception encountered: %1" ).arg( buffer ) );
93+
QgsDebugMsg( QString( "GEOS exception: %1" ).arg( buffer ) );
9494

9595
throw GEOSException( QString::fromUtf8( buffer ) );
9696
}
@@ -166,7 +166,7 @@ static GEOSGeometry *cloneGeosGeom( const GEOSGeometry *geom )
166166
}
167167
catch ( GEOSException &e )
168168
{
169-
Q_UNUSED( e );
169+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
170170
for ( int i = 0; i < geoms.count(); i++ )
171171
GEOSGeom_destroy( geoms[i] );
172172

@@ -261,7 +261,7 @@ static GEOSCoordSequence *createGeosCoordSequence( const QgsPolyline& points )
261261
}
262262
catch ( GEOSException &e )
263263
{
264-
Q_UNUSED( e );
264+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
265265
/*if ( coord )
266266
GEOSCoordSeq_destroy( coord );*/
267267
throw;
@@ -285,7 +285,7 @@ static GEOSGeometry *createGeosCollection( int typeId, QVector<GEOSGeometry*> ge
285285
}
286286
catch ( GEOSException &e )
287287
{
288-
Q_UNUSED( e );
288+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
289289
}
290290

291291
delete [] geomarr;
@@ -304,7 +304,7 @@ static GEOSGeometry *createGeosLineString( const QgsPolyline& polyline )
304304
}
305305
catch ( GEOSException &e )
306306
{
307-
Q_UNUSED( e );
307+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
308308
//MH: for strange reasons, geos3 crashes when removing the coordinate sequence
309309
//if ( coord )
310310
//GEOSCoordSeq_destroy( coord );
@@ -337,7 +337,7 @@ static GEOSGeometry *createGeosLinearRing( const QgsPolyline& polyline )
337337
}
338338
catch ( GEOSException &e )
339339
{
340-
Q_UNUSED( e );
340+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
341341
/* as MH has noticed ^, this crashes geos
342342
if ( coord )
343343
GEOSCoordSeq_destroy( coord );*/
@@ -389,7 +389,7 @@ static GEOSGeometry *createGeosPolygon( const QgsPolygon& polygon )
389389
}
390390
catch ( GEOSException &e )
391391
{
392-
Q_UNUSED( e );
392+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
393393
for ( int i = 0; i < geoms.count(); i++ )
394394
GEOSGeom_destroy( geoms[i] );
395395
return 0;
@@ -421,7 +421,7 @@ QgsGeometry* QgsGeometry::fromWkt( QString wkt )
421421
}
422422
catch ( GEOSException &e )
423423
{
424-
Q_UNUSED( e );
424+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
425425
return 0;
426426
}
427427
}
@@ -456,7 +456,8 @@ QgsGeometry* QgsGeometry::fromMultiPoint( const QgsMultiPoint& multipoint )
456456
}
457457
catch ( GEOSException &e )
458458
{
459-
Q_UNUSED( e );
459+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
460+
460461
for ( int i = 0; i < geoms.size(); ++i )
461462
GEOSGeom_destroy( geoms[i] );
462463

@@ -477,7 +478,8 @@ QgsGeometry* QgsGeometry::fromMultiPolyline( const QgsMultiPolyline& multiline )
477478
}
478479
catch ( GEOSException &e )
479480
{
480-
Q_UNUSED( e );
481+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
482+
481483
for ( int i = 0; i < geoms.count(); i++ )
482484
GEOSGeom_destroy( geoms[i] );
483485

@@ -501,7 +503,8 @@ QgsGeometry* QgsGeometry::fromMultiPolygon( const QgsMultiPolygon& multipoly )
501503
}
502504
catch ( GEOSException &e )
503505
{
504-
Q_UNUSED( e );
506+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
507+
505508
for ( int i = 0; i < geoms.count(); i++ )
506509
GEOSGeom_destroy( geoms[i] );
507510

@@ -2394,7 +2397,7 @@ double QgsGeometry::closestVertexWithContext( const QgsPoint& point, int& atVert
23942397
}
23952398
catch ( GEOSException &e )
23962399
{
2397-
Q_UNUSED( e );
2400+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
23982401
return -1;
23992402
}
24002403

@@ -2706,7 +2709,8 @@ int QgsGeometry::addRing( const QList<QgsPoint>& ring )
27062709
}
27072710
catch ( GEOSException &e )
27082711
{
2709-
Q_UNUSED( e );
2712+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
2713+
27102714
if ( newRingPolygon )
27112715
GEOSGeom_destroy( newRingPolygon );
27122716
else if ( newRing )
@@ -2739,7 +2743,8 @@ int QgsGeometry::addRing( const QList<QgsPoint>& ring )
27392743
}
27402744
catch ( GEOSException &e )
27412745
{
2742-
Q_UNUSED( e );
2746+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
2747+
27432748
if ( shell )
27442749
GEOSGeom_destroy( shell );
27452750
else if ( shellRing )
@@ -2776,7 +2781,8 @@ int QgsGeometry::addRing( const QList<QgsPoint>& ring )
27762781
}
27772782
catch ( GEOSException &e )
27782783
{
2779-
Q_UNUSED( e );
2784+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
2785+
27802786
if ( hole )
27812787
GEOSGeom_destroy( hole );
27822788
else if ( holeRing )
@@ -2924,7 +2930,8 @@ int QgsGeometry::addPart( const QList<QgsPoint> &points )
29242930
}
29252931
catch ( GEOSException &e )
29262932
{
2927-
Q_UNUSED( e );
2933+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
2934+
29282935
if ( newRing )
29292936
GEOSGeom_destroy( newRing );
29302937

@@ -2947,7 +2954,7 @@ int QgsGeometry::addPart( const QList<QgsPoint> &points )
29472954
}
29482955
catch ( GEOSException &e )
29492956
{
2950-
Q_UNUSED( e );
2957+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
29512958

29522959
if ( newPart )
29532960
GEOSGeom_destroy( newPart );
@@ -3839,7 +3846,7 @@ bool QgsGeometry::contains( QgsPoint* p )
38393846
}
38403847
catch ( GEOSException &e )
38413848
{
3842-
Q_UNUSED( e );
3849+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
38433850
returnval = false;
38443851
}
38453852

@@ -5458,7 +5465,7 @@ GEOSGeometry* QgsGeometry::reshapePolygon( const GEOSGeometry* polygon, const GE
54585465
}
54595466
catch ( GEOSException &e )
54605467
{
5461-
Q_UNUSED( e );
5468+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
54625469
nIntersections = 0;
54635470
}
54645471

@@ -5569,7 +5576,7 @@ GEOSGeometry* QgsGeometry::reshapeLine( const GEOSGeometry* line, const GEOSGeom
55695576
}
55705577
catch ( GEOSException &e )
55715578
{
5572-
Q_UNUSED( e );
5579+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
55735580
atLeastTwoIntersections = false;
55745581
}
55755582

@@ -6724,9 +6731,7 @@ bool QgsGeometry::isGeosValid()
67246731
}
67256732
catch ( GEOSException &e )
67266733
{
6727-
// looks like geometry is fubar
6728-
Q_UNUSED( e );
6729-
QgsDebugMsg( QString( "GEOS exception caught: %1" ).arg( e.what() ) );
6734+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
67306735
return false;
67316736
}
67326737
}
@@ -6749,9 +6754,7 @@ bool QgsGeometry::isGeosEmpty()
67496754
}
67506755
catch ( GEOSException &e )
67516756
{
6752-
// looks like geometry is fubar
6753-
Q_UNUSED( e );
6754-
QgsDebugMsg( QString( "GEOS exception caught: %1" ).arg( e.what() ) );
6757+
QgsMessageLog::logMessage( QObject::tr( "Exception: %1" ).arg( e.what() ), QObject::tr( "GEOS" ) );
67556758
return false;
67566759
}
67576760
}

‎src/core/qgsgeometryvalidator.cpp

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ void QgsGeometryValidator::validatePolyline( int i, QgsPolyline line, bool ring
8282
{
8383
if ( ring )
8484
{
85-
if ( line.size() < 3 )
85+
if ( line.size() < 4 )
8686
{
87-
QString msg = QObject::tr( "ring %1 with less than three points" ).arg( i );
87+
QString msg = QObject::tr( "ring %1 with less than four points" ).arg( i );
8888
QgsDebugMsg( msg );
8989
emit errorFound( QgsGeometry::Error( msg ) );
9090
mErrorCount++;
@@ -193,47 +193,55 @@ void QgsGeometryValidator::validatePolygon( int idx, const QgsPolygon &polygon )
193193

194194
void QgsGeometryValidator::run()
195195
{
196-
QgsDebugMsg( "validation thread started." );
197-
198196
mErrorCount = 0;
199197
#if defined(GEOS_VERSION_MAJOR) && defined(GEOS_VERSION_MINOR) && \
200198
( (GEOS_VERSION_MAJOR==3 && GEOS_VERSION_MINOR>=3) || GEOS_VERSION_MAJOR>3)
201199
QSettings settings;
202200
if ( settings.value( "/qgis/digitizing/validate_geometries", 1 ).toInt() == 2 )
203201
{
204202
char *r = 0;
205-
GEOSGeometry *g = 0;
206-
if ( GEOSisValidDetail( mG.asGeos(), GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g ) != 1 )
203+
GEOSGeometry *g0 = mG.asGeos();
204+
if ( !g0 )
207205
{
208-
if ( g )
206+
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:could not produce geometry for GEOS (check log window)" ) ) );
207+
}
208+
else
209+
{
210+
GEOSGeometry *g1 = 0;
211+
if ( GEOSisValidDetail( g0, GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE, &r, &g1 ) != 1 )
209212
{
210-
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( g );
213+
if ( g1 )
214+
{
215+
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( g1 );
211216

212-
unsigned int n;
213-
if ( GEOSCoordSeq_getSize( cs, &n ) && n == 1 )
217+
unsigned int n;
218+
if ( GEOSCoordSeq_getSize( cs, &n ) && n == 1 )
219+
{
220+
double x, y;
221+
GEOSCoordSeq_getX( cs, 0, &x );
222+
GEOSCoordSeq_getY( cs, 0, &y );
223+
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ), QgsPoint( x, y ) ) );
224+
mErrorCount++;
225+
}
226+
227+
GEOSGeom_destroy( g1 );
228+
}
229+
else
214230
{
215-
double x, y;
216-
GEOSCoordSeq_getX( cs, 0, &x );
217-
GEOSCoordSeq_getY( cs, 0, &y );
218-
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ), QgsPoint( x, y ) ) );
231+
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ) ) );
219232
mErrorCount++;
220233
}
221234

222-
GEOSGeom_destroy( g );
235+
GEOSFree( r );
223236
}
224-
else
225-
{
226-
emit errorFound( QgsGeometry::Error( QObject::tr( "GEOS error:%1" ).arg( r ) ) );
227-
mErrorCount++;
228-
}
229-
230-
GEOSFree( r );
231237
}
232238

233239
return;
234240
}
235241
#endif
236242

243+
QgsDebugMsg( "validation thread started." );
244+
237245
switch ( mG.wkbType() )
238246
{
239247
case QGis::WKBPoint:
@@ -309,14 +317,16 @@ void QgsGeometryValidator::run()
309317
{
310318
emit errorFound( QObject::tr( "Geometry validation was aborted." ) );
311319
}
312-
else if ( mErrorCount == 0 )
320+
else if ( mErrorCount > 0 )
313321
{
314-
emit errorFound( QObject::tr( "Geometry is valid." ) );
322+
emit errorFound( QObject::tr( "Geometry has %1 errors." ).arg( mErrorCount ) );
315323
}
324+
#if 0
316325
else
317326
{
318-
emit errorFound( QObject::tr( "Geometry has %1 errors." ).arg( mErrorCount ) );
327+
emit errorFound( QObject::tr( "Geometry is valid." ) );
319328
}
329+
#endif
320330
}
321331

322332
void QgsGeometryValidator::addError( QgsGeometry::Error e )

‎src/core/qgsmessageoutput.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
#include "qgsmessageoutput.h"
1717
#include "qgslogger.h"
18+
#include "qgsmessagelog.h"
19+
20+
#include <QRegExp>
1821

1922
static QgsMessageOutput* messageOutputConsole_()
2023
{
@@ -47,9 +50,10 @@ QgsMessageOutputConsole::QgsMessageOutputConsole()
4750
{
4851
}
4952

50-
void QgsMessageOutputConsole::setMessage( const QString& message, MessageType )
53+
void QgsMessageOutputConsole::setMessage( const QString& message, MessageType msgType )
5154
{
5255
mMessage = message;
56+
mMsgType = msgType;
5357
}
5458

5559
void QgsMessageOutputConsole::appendMessage( const QString& message )
@@ -59,14 +63,13 @@ void QgsMessageOutputConsole::appendMessage( const QString& message )
5963

6064
void QgsMessageOutputConsole::showMessage( bool )
6165
{
62-
// show title if provided
63-
if ( !mTitle.isNull() )
66+
if ( mMsgType == MessageHtml )
6467
{
65-
QgsDebugMsg( QString( "%1:" ).arg( mTitle ) );
68+
mMessage.replace( "<br>", "\n" );
69+
mMessage.replace( "&nbsp;", " " );
70+
mMessage.replace( QRegExp("<\/?[^>]+>"), "" );
6671
}
67-
68-
// show the message
69-
QgsDebugMsg( mMessage );
72+
QgsMessageLog::logMessage( mMessage, mTitle.isNull() ? QObject::tr( "Console" ) : mTitle );
7073
emit destroyed();
7174
delete this;
7275
}

‎src/core/qgsmessageoutput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class CORE_EXPORT QgsMessageOutputConsole : public QObject, public QgsMessageOut
107107
//! stores current title
108108
QString mTitle;
109109

110+
MessageType mMsgType;
110111
};
111112

112113
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.