Clean up QgsRasterBlockFeedback class

This commit is contained in:
Martin Dobias 2016-09-09 16:02:18 +08:00
parent 267f263351
commit f6a2a5e744
5 changed files with 54 additions and 29 deletions

View File

@ -11,19 +11,28 @@ class QgsRasterBlockFeedback : QgsFeedback
%End
public:
//! construct a new raster block feedback object
//! Construct a new raster block feedback object
QgsRasterBlockFeedback( QObject* parent = nullptr );
//! whether the raster provider should return only data that are already available
//! without waiting for full result
bool preview_only;
//! whether our painter is drawing to a temporary image used just by this layer
bool render_partial_output;
//! may be emitted by raster data provider to indicate that some partial data are available
//! May be emitted by raster data provider to indicate that some partial data are available
//! and a new preview image may be produced
virtual void onNewData();
//! Whether the raster provider should return only data that are already available
//! without waiting for full result. By default this flag is not enabled.
//! @see setPreviewOnly()
bool isPreviewOnly() const;
//! set flag whether the block request is for preview purposes only
//! @see isPreviewOnly()
void setPreviewOnly( bool preview );
//! Whether our painter is drawing to a temporary image used just by this layer
//! @see setRenderPartialOutput()
bool renderPartialOutput() const;
//! Set whether our painter is drawing to a temporary image used just by this layer
//! @see renderPartialOutput()
void setRenderPartialOutput( bool enable );
};

View File

@ -88,7 +88,7 @@ void QgsRasterDrawer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsM
}
}
if ( feedback && feedback->render_partial_output )
if ( feedback && feedback->renderPartialOutput() )
{
// there could have been partial preview written before
// so overwrite anything with the resulting image.

View File

@ -37,19 +37,35 @@
class CORE_EXPORT QgsRasterBlockFeedback : public QgsFeedback
{
public:
//! construct a new raster block feedback object
QgsRasterBlockFeedback( QObject* parent = nullptr ) : QgsFeedback( parent ), preview_only( false ), render_partial_output( false ) {}
//! Construct a new raster block feedback object
QgsRasterBlockFeedback( QObject* parent = nullptr ) : QgsFeedback( parent ), mPreviewOnly( false ), mRenderPartialOutput( false ) {}
//! whether the raster provider should return only data that are already available
//! without waiting for full result
bool preview_only;
//! whether our painter is drawing to a temporary image used just by this layer
bool render_partial_output;
//! may be emitted by raster data provider to indicate that some partial data are available
//! May be emitted by raster data provider to indicate that some partial data are available
//! and a new preview image may be produced
virtual void onNewData() {}
//! Whether the raster provider should return only data that are already available
//! without waiting for full result. By default this flag is not enabled.
//! @see setPreviewOnly()
bool isPreviewOnly() const { return mPreviewOnly; }
//! set flag whether the block request is for preview purposes only
//! @see isPreviewOnly()
void setPreviewOnly( bool preview ) { mPreviewOnly = preview; }
//! Whether our painter is drawing to a temporary image used just by this layer
//! @see setRenderPartialOutput()
bool renderPartialOutput() const { return mRenderPartialOutput; }
//! Set whether our painter is drawing to a temporary image used just by this layer
//! @see renderPartialOutput()
void setRenderPartialOutput( bool enable ) { mRenderPartialOutput = enable; }
private:
//! Whether the raster provider should return only data that are already available
//! without waiting for full result
bool mPreviewOnly;
//! Whether our painter is drawing to a temporary image used just by this layer
bool mRenderPartialOutput;
};

View File

@ -231,14 +231,14 @@ QgsRasterLayerRenderer::Feedback::Feedback( QgsRasterLayerRenderer *r )
: mR( r )
, mMinimalPreviewInterval( 250 )
{
render_partial_output = r->mContext.testFlag( QgsRenderContext::RenderPartialOutput );
setRenderPartialOutput( r->mContext.testFlag( QgsRenderContext::RenderPartialOutput ) );
}
void QgsRasterLayerRenderer::Feedback::onNewData()
{
qDebug( "\nGOT NEW DATA!\n" );
if ( !render_partial_output )
if ( !renderPartialOutput() )
return; // we were not asked for partial renders and we may not have a temporary image for overwriting...
// update only once upon a time
@ -252,8 +252,8 @@ void QgsRasterLayerRenderer::Feedback::onNewData()
QTime t;
t.start();
QgsRasterBlockFeedback feedback;
feedback.preview_only = true;
feedback.render_partial_output = true;
feedback.setPreviewOnly( true );
feedback.setRenderPartialOutput( true );
QgsRasterIterator iterator( mR->mPipe->last() );
QgsRasterDrawer drawer( &iterator );
drawer.draw( mR->mPainter, mR->mRasterViewPort, mR->mMapToPixel, &feedback );

View File

@ -780,7 +780,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
// draw other res tiles if preview
QPainter p( image );
if ( feedback && feedback->preview_only && missing.count() > 0 )
if ( feedback && feedback->isPreviewOnly() && missing.count() > 0 )
{
// some tiles are still missing, so let's see if we have any cached tiles
// from lower or higher resolution available to give the user a bit of context
@ -825,14 +825,14 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
p.setRenderHint( QPainter::SmoothPixmapTransform, true );
p.drawImage( ti.rect, ti.img );
if ( feedback && feedback->preview_only )
if ( feedback && feedback->isPreviewOnly() )
_drawDebugRect( p, ti.rect, Qt::green );
}
p.end();
int t2 = t.elapsed() - t1;
if ( feedback && feedback->preview_only )
if ( feedback && feedback->isPreviewOnly() )
{
qDebug( "PREVIEW - CACHED: %d / MISSING: %d", tileImages.count(), requests.count() - tileImages.count() );
qDebug( "PREVIEW - TIME: this res %d ms | other res %d ms | TOTAL %d ms", t0 + t2, t1, t0 + t1 + t2 );
@ -840,7 +840,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth, i
else if ( !requestsFinal.isEmpty() )
{
// let the feedback object know about the tiles we have already
if ( feedback && feedback->render_partial_output )
if ( feedback && feedback->renderPartialOutput() )
feedback->onNewData();
// order tile requests according to the distance from view center
@ -3908,7 +3908,7 @@ void QgsWmsTiledImageDownloadHandler::tileReplyFinished()
}
else
{
if ( !( mFeedback && mFeedback->preview_only ) )
if ( !( mFeedback && mFeedback->isPreviewOnly() ) )
{
// report any errors except for the one we have caused by cancelling the request
if ( reply->error() != QNetworkReply::OperationCanceledError )