Skip to content
Permalink
Browse files

Store previous layer rendering time in canvas, not map layer

  • Loading branch information
nyalldawson committed Dec 2, 2017
1 parent 997619c commit 16a1bd7948fd4c50190ab56eb71433cac9f23179
@@ -916,7 +916,6 @@ Time stamp of data source in the moment when data/metadata were loaded by provid
:rtype: bool
%End


public slots:

void setMinimumScale( double scale );
@@ -137,10 +137,18 @@ List of errors that happened during the rendering job - available when the rende

int renderingTime() const;
%Docstring
Find out how long it took to finish the job (in milliseconds)
Returns the total time it took to finish the job (in milliseconds).
.. seealso:: layerRenderingTime()
:rtype: int
%End

QMap< QString, int > layerRenderingTime() const;
%Docstring
Returns the render time (in ms) per layer, by layer ID.
.. versionadded:: 3.0
:rtype: QMap< str, int >
%End

const QgsMapSettings &mapSettings() const;
%Docstring
Return map settings with which this job was started.
@@ -179,6 +187,7 @@ emitted when asynchronous rendering is finished (or canceled).




};


@@ -882,25 +882,6 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
bool isRefreshOnNotifyEnabled() const { return mIsRefreshOnNofifyEnabled; }

///@cond PRIVATE
#ifndef SIP_RUN

/**
* Set last rendering time.
*
* \note not available in Python bindings
*/
void setLastRenderingTime( double time ) { mLastRenderingTime = time; }

/**
* Get last rendering time.
*
* \note not available in Python bindings
*/
double lastRenderingTime() const { return mLastRenderingTime; }
#endif
///@endcond

public slots:

/**
@@ -1240,7 +1221,6 @@ class CORE_EXPORT QgsMapLayer : public QObject
//! Renderer for 3D views
QgsAbstract3DRenderer *m3DRenderer = nullptr;

double mLastRenderingTime = 0.0;
};

Q_DECLARE_METATYPE( QgsMapLayer * )
@@ -265,10 +265,6 @@ void QgsMapRendererCustomPainterJob::doRender()
job.renderer->render();

job.renderingTime = layerTime.elapsed();
if ( job.layer )
{
job.layer->setLastRenderingTime( job.renderingTime );
}
}

if ( job.img )
@@ -242,13 +242,6 @@ LayerRenderJobs QgsMapRendererJob::prepareJobs( QPainter *painter, QgsLabelingEn
continue;
}

if ( ( mSettings.flags() & QgsMapSettings::RenderPreviewJob ) &&
!ml->dataProvider()->renderInPreview( ml->lastRenderingTime(), MAXIMUM_LAYER_PREVIEW_TIME_MS ) )
{
QgsDebugMsgLevel( "Layer not rendered because it does not match the renderInPreview criterion", 3 );
continue;
}

QgsRectangle r1 = mSettings.visibleExtent(), r2;
QgsCoordinateTransform ct;

@@ -419,8 +412,10 @@ void QgsMapRendererJob::cleanupJobs( LayerRenderJobs &jobs )
delete job.renderer;
job.renderer = nullptr;
}
}

if ( job.layer )
mLayerRenderingTime.insert( job.layer->id(), job.renderingTime );
}

jobs.clear();
}
@@ -199,9 +199,18 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
*/
void setCache( QgsMapRendererCache *cache );

//! Find out how long it took to finish the job (in milliseconds)
/**
* Returns the total time it took to finish the job (in milliseconds).
* \see layerRenderingTime()
*/
int renderingTime() const { return mRenderingTime; }

/**
* Returns the render time (in ms) per layer, by layer ID.
* \since QGIS 3.0
*/
QMap< QString, int > layerRenderingTime() const { return mLayerRenderingTime; }

/**
* Return map settings with which this job was started.
* \returns A QgsMapSettings instance with render settings
@@ -239,6 +248,9 @@ class CORE_EXPORT QgsMapRendererJob : public QObject

int mRenderingTime = 0;

//! Render time (in ms) per layer, by layer ID
QMap< QString, int > mLayerRenderingTime;

/**
* Prepares the cache for storing the result of labeling. Returns false if
* the render cannot use cached labels and should not cache the result.
@@ -270,10 +270,6 @@ void QgsMapRendererParallelJob::renderLayerStatic( LayerRenderJob &job )
QgsDebugMsg( "Caught unhandled unknown exception" );
}
job.renderingTime = t.elapsed();
if ( job.layer )
{
job.layer->setLastRenderingTime( job.renderingTime );
}
QgsDebugMsgLevel( QString( "job %1 end [%2 ms] (layer %3)" ).arg( reinterpret_cast< quint64 >( &job ), 0, 16 ).arg( job.renderingTime ).arg( job.layer ? job.layer->id() : QString() ), 2 );
}

@@ -611,6 +611,8 @@ void QgsMapCanvas::rendererJobFinished()
p.end();

mMap->setContent( img, imageRect( img, mSettings ) );

mLastLayerRenderTime = mJob->layerRenderingTime();
if ( mUsePreviewJobs )
startPreviewJobs();
}
@@ -2268,6 +2270,21 @@ void QgsMapCanvas::startPreviewJob( int number )
jobSettings.setFlag( QgsMapSettings::DrawLabeling, false );
jobSettings.setFlag( QgsMapSettings::RenderPreviewJob, true );

// truncate preview layers to fast layers
const QList<QgsMapLayer *> layers = jobSettings.layers();
QList< QgsMapLayer * > previewLayers;
for ( QgsMapLayer *layer : layers )
{
if ( !layer->dataProvider()->renderInPreview( mLastLayerRenderTime.value( layer->id() ), MAXIMUM_LAYER_PREVIEW_TIME_MS ) )
{
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;
}

previewLayers << layer;
}
jobSettings.setLayers( previewLayers );

QgsMapRendererQImageJob *job = new QgsMapRendererSequentialJob( jobSettings );
mPreviewJobs.append( job );
connect( job, &QgsMapRendererJob::finished, this, &QgsMapCanvas::previewJobFinished );
@@ -1000,6 +1000,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView

bool mUsePreviewJobs = false;

QMap< QString, int > mLastLayerRenderTime;

/**
* Force a resize of the map canvas item
* \since QGIS 2.16

0 comments on commit 16a1bd7

Please sign in to comment.
You can’t perform that action at this time.