Skip to content

Commit

Permalink
More flexible API for preview job determination
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 4, 2017
1 parent 16a1bd7 commit 01e8ed8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions python/core/qgsdataprovider.sip
Expand Up @@ -380,6 +380,7 @@ Current time stamp of data source
.. versionadded:: 3.0
%End


signals:

void fullExtentCalculated();
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsdataprovider.cpp
Expand Up @@ -42,7 +42,7 @@ void QgsDataProvider::setListening( bool isListening )
Q_UNUSED( isListening );
}

bool QgsDataProvider::renderInPreview( double lastRenderingTimeMS, double maxRenderingTimeMS )
bool QgsDataProvider::renderInPreview( QgsDataProvider::PreviewContext context )
{
return lastRenderingTimeMS <= maxRenderingTimeMS;
return context.lastRenderingTimeMs <= context.maxRenderingTimeMs;
}
19 changes: 18 additions & 1 deletion src/core/qgsdataprovider.h
Expand Up @@ -461,6 +461,23 @@ class CORE_EXPORT QgsDataProvider : public QObject
*/
virtual void setListening( bool isListening );

#ifndef SIP_RUN

/**
* Stores settings related to the context in which a preview job runs.
* \note Not available in Python bindings
* \since QGIS 3.0
*/
struct PreviewContext
{
//! Previous rendering time for the layer, in ms
double lastRenderingTimeMs = -1;

//! Default maximum allowable render time, in ms
double maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
};
#endif

/**
* Returns whether the layer must be rendered in preview jobs.
*
Expand All @@ -474,7 +491,7 @@ class CORE_EXPORT QgsDataProvider : public QObject
*
* \note not available in Python bindings
*/
virtual bool renderInPreview( double lastRenderingTimeMS, double maxRenderingTimeMS ); // SIP_SKIP
virtual bool renderInPreview( QgsDataProvider::PreviewContext context ); // SIP_SKIP

signals:

Expand Down
5 changes: 4 additions & 1 deletion src/gui/qgsmapcanvas.cpp
Expand Up @@ -2273,9 +2273,12 @@ void QgsMapCanvas::startPreviewJob( int number )
// truncate preview layers to fast layers
const QList<QgsMapLayer *> layers = jobSettings.layers();
QList< QgsMapLayer * > previewLayers;
QgsDataProvider::PreviewContext context;
context.maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
for ( QgsMapLayer *layer : layers )
{
if ( !layer->dataProvider()->renderInPreview( mLastLayerRenderTime.value( layer->id() ), MAXIMUM_LAYER_PREVIEW_TIME_MS ) )
context.lastRenderingTimeMs = mLastLayerRenderTime.value( layer->id() );
if ( !layer->dataProvider()->renderInPreview( context ) )
{
QgsDebugMsgLevel( QString( "Layer %1 not rendered because it does not match the renderInPreview criterion %2" ).arg( layer->id() ).arg( mLastLayerRenderTime.value( layer->id() ) ), 3 );
continue;
Expand Down

0 comments on commit 01e8ed8

Please sign in to comment.