Skip to content

Commit

Permalink
Tweak API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 4, 2017
1 parent be95458 commit 38cca6c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
6 changes: 0 additions & 6 deletions python/core/qgsmaprendererjob.sip
Expand Up @@ -142,12 +142,6 @@ List of errors that happened during the rendering job - available when the rende
:rtype: int
%End

QMap< QString, int > perLayerRenderingTime() 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
Expand Down
13 changes: 12 additions & 1 deletion src/core/qgsmaprendererjob.cpp
Expand Up @@ -64,6 +64,17 @@ void QgsMapRendererJob::setCache( QgsMapRendererCache *cache )
mCache = cache;
}

QHash<QgsMapLayer *, int> QgsMapRendererJob::perLayerRenderingTime() const
{
QHash<QgsMapLayer *, int> result;
for ( auto it = mPerLayerRenderingTime.constBegin(); it != mPerLayerRenderingTime.constEnd(); ++it )
{
if ( it.key() )
result.insert( it.key(), it.value() );
}
return result;
}

const QgsMapSettings &QgsMapRendererJob::mapSettings() const
{
return mSettings;
Expand Down Expand Up @@ -414,7 +425,7 @@ void QgsMapRendererJob::cleanupJobs( LayerRenderJobs &jobs )
}

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

jobs.clear();
Expand Down
7 changes: 4 additions & 3 deletions src/core/qgsmaprendererjob.h
Expand Up @@ -206,10 +206,11 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
int renderingTime() const { return mRenderingTime; }

/**
* Returns the render time (in ms) per layer, by layer ID.
* Returns the render time (in ms) per layer.
* \note Not available in Python bindings.
* \since QGIS 3.0
*/
QMap< QString, int > perLayerRenderingTime() const { return mPerLayerRenderingTime; }
QHash< QgsMapLayer *, int > perLayerRenderingTime() const SIP_SKIP;

/**
* Return map settings with which this job was started.
Expand Down Expand Up @@ -249,7 +250,7 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
int mRenderingTime = 0;

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

/**
* Prepares the cache for storing the result of labeling. Returns false if
Expand Down
9 changes: 7 additions & 2 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -612,7 +612,12 @@ void QgsMapCanvas::rendererJobFinished()

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

mLastLayerRenderTime = mJob->perLayerRenderingTime();
mLastLayerRenderTime.clear();
const auto times = mJob->perLayerRenderingTime();
for ( auto it = times.constBegin(); it != times.constEnd(); ++it )
{
mLastLayerRenderTime.insert( it.key()->id(), it.value() );
}
if ( mUsePreviewJobs )
startPreviewJobs();
}
Expand Down Expand Up @@ -2284,7 +2289,7 @@ void QgsMapCanvas::startPreviewJob( int number )
context.maxRenderingTimeMs = MAXIMUM_LAYER_PREVIEW_TIME_MS;
for ( QgsMapLayer *layer : layers )
{
context.lastRenderingTimeMs = mLastLayerRenderTime.value( layer->id() );
context.lastRenderingTimeMs = mLastLayerRenderTime.value( layer->id(), 0 );
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 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvas.h
Expand Up @@ -1000,7 +1000,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView

bool mUsePreviewJobs = false;

QMap< QString, int > mLastLayerRenderTime;
QHash< QString, int > mLastLayerRenderTime;

/**
* Force a resize of the map canvas item
Expand Down

0 comments on commit 38cca6c

Please sign in to comment.