Skip to content

Commit

Permalink
Add method to QgsRasterBlockFeedback to collect error messages
Browse files Browse the repository at this point in the history
And append raster errors to rendering errors whenever encountered
  • Loading branch information
nyalldawson committed May 21, 2019
1 parent 230c62f commit 60deffb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 1 deletion.
19 changes: 19 additions & 0 deletions python/core/auto_generated/raster/qgsrasterinterface.sip.in
Expand Up @@ -61,6 +61,25 @@ Whether our painter is drawing to a temporary image used just by this layer
Set whether our painter is drawing to a temporary image used just by this layer

.. seealso:: :py:func:`renderPartialOutput`
%End

void appendError( const QString &error );
%Docstring
Appends an error message to the stored list of errors. Should be called
whenever an error is encountered while retrieving a raster block.

.. seealso:: :py:func:`errors`

.. versionadded:: 3.8.0
%End

QStringList errors() const;
%Docstring
Returns a list of any errors encountered while retrieving the raster block.

.. seealso:: :py:func:`appendError`

.. versionadded:: 3.8.0
%End

};
Expand Down
20 changes: 20 additions & 0 deletions src/core/raster/qgsrasterinterface.h
Expand Up @@ -76,6 +76,23 @@ class CORE_EXPORT QgsRasterBlockFeedback : public QgsFeedback
*/
void setRenderPartialOutput( bool enable ) { mRenderPartialOutput = enable; }

/**
* Appends an error message to the stored list of errors. Should be called
* whenever an error is encountered while retrieving a raster block.
*
* \see errors()
* \since QGIS 3.8.0
*/
void appendError( const QString &error ) { mErrors.append( error ); }

/**
* Returns a list of any errors encountered while retrieving the raster block.
*
* \see appendError()
* \since QGIS 3.8.0
*/
QStringList errors() const { return mErrors; }

private:

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

//! Whether our painter is drawing to a temporary image used just by this layer
bool mRenderPartialOutput = false;

//! List of errors encountered while retrieving block
QStringList mErrors;
};


Expand Down
6 changes: 6 additions & 0 deletions src/core/raster/qgsrasterlayerrenderer.cpp
Expand Up @@ -272,6 +272,12 @@ bool QgsRasterLayerRenderer::render()
QgsRasterDrawer drawer( &iterator );
drawer.draw( mPainter, mRasterViewPort, mMapToPixel, mFeedback );

const QStringList errors = mFeedback->errors();
for ( const QString &error : errors )
{
mErrors.append( error );
}

QgsDebugMsgLevel( QStringLiteral( "total raster draw time (ms): %1" ).arg( time.elapsed(), 5 ), 4 );

return true;
Expand Down
3 changes: 3 additions & 0 deletions src/providers/arcgisrest/qgsamsprovider.cpp
Expand Up @@ -463,6 +463,9 @@ bool QgsAmsProvider::readBlock( int /*bandNo*/, const QgsRectangle &viewExtent,
draw( viewExtent, width, height );
if ( mCachedImage.width() != width || mCachedImage.height() != height )
{
if ( feedback )
feedback->appendError( tr( "Unexpected image size for block" ) );

QgsDebugMsg( QStringLiteral( "Unexpected image size for block" ) );
return false;
}
Expand Down
6 changes: 5 additions & 1 deletion src/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -904,7 +904,11 @@ bool QgsGdalProvider::readBlock( int bandNo, QgsRectangle const &extent, int pi

if ( err != CPLE_None )
{
QgsLogger::warning( "RasterIO error: " + QString::fromUtf8( CPLGetLastErrorMsg() ) );
const QString lastError = QString::fromUtf8( CPLGetLastErrorMsg() ) ;
if ( feedback )
feedback->appendError( lastError );

QgsLogger::warning( "RasterIO error: " + lastError );
qgsFree( tmpBlock );
return false;
}
Expand Down

0 comments on commit 60deffb

Please sign in to comment.