Skip to content

Commit 60deffb

Browse files
committedMay 21, 2019
Add method to QgsRasterBlockFeedback to collect error messages
And append raster errors to rendering errors whenever encountered
1 parent 230c62f commit 60deffb

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed
 

‎python/core/auto_generated/raster/qgsrasterinterface.sip.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,25 @@ Whether our painter is drawing to a temporary image used just by this layer
6161
Set whether our painter is drawing to a temporary image used just by this layer
6262

6363
.. seealso:: :py:func:`renderPartialOutput`
64+
%End
65+
66+
void appendError( const QString &error );
67+
%Docstring
68+
Appends an error message to the stored list of errors. Should be called
69+
whenever an error is encountered while retrieving a raster block.
70+
71+
.. seealso:: :py:func:`errors`
72+
73+
.. versionadded:: 3.8.0
74+
%End
75+
76+
QStringList errors() const;
77+
%Docstring
78+
Returns a list of any errors encountered while retrieving the raster block.
79+
80+
.. seealso:: :py:func:`appendError`
81+
82+
.. versionadded:: 3.8.0
6483
%End
6584

6685
};

‎src/core/raster/qgsrasterinterface.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,23 @@ class CORE_EXPORT QgsRasterBlockFeedback : public QgsFeedback
7676
*/
7777
void setRenderPartialOutput( bool enable ) { mRenderPartialOutput = enable; }
7878

79+
/**
80+
* Appends an error message to the stored list of errors. Should be called
81+
* whenever an error is encountered while retrieving a raster block.
82+
*
83+
* \see errors()
84+
* \since QGIS 3.8.0
85+
*/
86+
void appendError( const QString &error ) { mErrors.append( error ); }
87+
88+
/**
89+
* Returns a list of any errors encountered while retrieving the raster block.
90+
*
91+
* \see appendError()
92+
* \since QGIS 3.8.0
93+
*/
94+
QStringList errors() const { return mErrors; }
95+
7996
private:
8097

8198
/**
@@ -86,6 +103,9 @@ class CORE_EXPORT QgsRasterBlockFeedback : public QgsFeedback
86103

87104
//! Whether our painter is drawing to a temporary image used just by this layer
88105
bool mRenderPartialOutput = false;
106+
107+
//! List of errors encountered while retrieving block
108+
QStringList mErrors;
89109
};
90110

91111

‎src/core/raster/qgsrasterlayerrenderer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,12 @@ bool QgsRasterLayerRenderer::render()
272272
QgsRasterDrawer drawer( &iterator );
273273
drawer.draw( mPainter, mRasterViewPort, mMapToPixel, mFeedback );
274274

275+
const QStringList errors = mFeedback->errors();
276+
for ( const QString &error : errors )
277+
{
278+
mErrors.append( error );
279+
}
280+
275281
QgsDebugMsgLevel( QStringLiteral( "total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );
276282

277283
return true;

‎src/providers/arcgisrest/qgsamsprovider.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ bool QgsAmsProvider::readBlock( int /*bandNo*/, const QgsRectangle &viewExtent,
463463
draw( viewExtent, width, height );
464464
if ( mCachedImage.width() != width || mCachedImage.height() != height )
465465
{
466+
if ( feedback )
467+
feedback->appendError( tr( "Unexpected image size for block" ) );
468+
466469
QgsDebugMsg( QStringLiteral( "Unexpected image size for block" ) );
467470
return false;
468471
}

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,11 @@ bool QgsGdalProvider::readBlock( int bandNo, QgsRectangle const &extent, int pi
904904

905905
if ( err != CPLE_None )
906906
{
907-
QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
907+
const QString lastError = QString::fromUtf8( CPLGetLastErrorMsg() ) ;
908+
if ( feedback )
909+
feedback->appendError( lastError );
910+
911+
QgsLogger::warning( "RasterIO error: " + lastError );
908912
qgsFree( tmpBlock );
909913
return false;
910914
}

0 commit comments

Comments
 (0)
Please sign in to comment.