Skip to content

Commit

Permalink
Reuse existing labeling results if cached labels were redrawn
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Feb 7, 2017
1 parent 33eb4bc commit 2b3805e
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 3 deletions.
2 changes: 2 additions & 0 deletions python/core/qgsmaprendererjob.sip
Expand Up @@ -24,6 +24,8 @@ class QgsMapRendererJob : QObject
//! Tell whether the rendering job is currently running in background.
virtual bool isActive() const = 0;

virtual bool usedCachedLabels() const = 0;

//! Get pointer to internal labeling engine (in order to get access to the results)
virtual QgsLabelingResults* takeLabelingResults() = 0 /Transfer/;

Expand Down
1 change: 1 addition & 0 deletions python/core/qgsmaprendererparalleljob.sip
Expand Up @@ -20,6 +20,7 @@ class QgsMapRendererParallelJob : QgsMapRendererQImageJob
virtual void cancel();
virtual void waitForFinished();
virtual bool isActive() const;
virtual bool usedCachedLabels() const;

virtual QgsLabelingResults* takeLabelingResults() /Transfer/;

Expand Down
1 change: 1 addition & 0 deletions python/core/qgsmaprenderersequentialjob.sip
Expand Up @@ -21,6 +21,7 @@ class QgsMapRendererSequentialJob : QgsMapRendererQImageJob
virtual void cancel();
virtual void waitForFinished();
virtual bool isActive() const;
virtual bool usedCachedLabels() const;

virtual QgsLabelingResults* takeLabelingResults() /Transfer/;

Expand Down
4 changes: 4 additions & 0 deletions src/core/qgsmaprenderercustompainterjob.cpp
Expand Up @@ -156,6 +156,10 @@ bool QgsMapRendererCustomPainterJob::isActive() const
return mActive;
}

bool QgsMapRendererCustomPainterJob::usedCachedLabels() const
{
return mLabelJob.cached;
}

QgsLabelingResults* QgsMapRendererCustomPainterJob::takeLabelingResults()
{
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsmaprenderercustompainterjob.h
Expand Up @@ -41,6 +41,7 @@ class CORE_EXPORT QgsMapRendererCustomPainterJob : public QgsMapRendererJob
virtual void cancel() override;
virtual void waitForFinished() override;
virtual bool isActive() const override;
virtual bool usedCachedLabels() const override;
virtual QgsLabelingResults* takeLabelingResults() override;

//! @note not available in python bindings
Expand Down
15 changes: 14 additions & 1 deletion src/core/qgsmaprendererjob.h
Expand Up @@ -125,7 +125,20 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
//! Tell whether the rendering job is currently running in background.
virtual bool isActive() const = 0;

//! Get pointer to internal labeling engine (in order to get access to the results)
/**
* Returns true if the render job was able to use a cached labeling solution.
* If so, any previously stored labeling results (see takeLabelingResults())
* should be retained.
* @see takeLabelingResults()
* @note added in QGIS 3.0
*/
virtual bool usedCachedLabels() const = 0;

/**
* Get pointer to internal labeling engine (in order to get access to the results).
* This should not be used if cached labeling was redrawn - see usedCachedLabels().
* @see usedCachedLabels()
*/
virtual QgsLabelingResults* takeLabelingResults() = 0;

//! @note Added in QGIS 3.0
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsmaprendererparalleljob.cpp
Expand Up @@ -153,6 +153,11 @@ bool QgsMapRendererParallelJob::isActive() const
return mStatus != Idle;
}

bool QgsMapRendererParallelJob::usedCachedLabels() const
{
return mLabelJob.cached;
}

QgsLabelingResults* QgsMapRendererParallelJob::takeLabelingResults()
{
if ( mLabelingEngineV2 )
Expand Down
1 change: 1 addition & 0 deletions src/core/qgsmaprendererparalleljob.h
Expand Up @@ -39,6 +39,7 @@ class CORE_EXPORT QgsMapRendererParallelJob : public QgsMapRendererQImageJob
virtual void waitForFinished() override;
virtual bool isActive() const override;

virtual bool usedCachedLabels() const override;
virtual QgsLabelingResults* takeLabelingResults() override;

// from QgsMapRendererJobWithPreview
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsmaprenderersequentialjob.cpp
Expand Up @@ -98,6 +98,11 @@ bool QgsMapRendererSequentialJob::isActive() const
return nullptr != mInternalJob;
}

bool QgsMapRendererSequentialJob::usedCachedLabels() const
{
return mUsedCachedLabels;
}

QgsLabelingResults* QgsMapRendererSequentialJob::takeLabelingResults()
{
QgsLabelingResults* tmp = mLabelingResults;
Expand Down Expand Up @@ -125,6 +130,7 @@ void QgsMapRendererSequentialJob::internalFinished()
mPainter = nullptr;

mLabelingResults = mInternalJob->takeLabelingResults();
mUsedCachedLabels = mInternalJob->usedCachedLabels();

mErrors = mInternalJob->errors();

Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsmaprenderersequentialjob.h
Expand Up @@ -41,6 +41,7 @@ class CORE_EXPORT QgsMapRendererSequentialJob : public QgsMapRendererQImageJob
virtual void waitForFinished() override;
virtual bool isActive() const override;

virtual bool usedCachedLabels() const override;
virtual QgsLabelingResults* takeLabelingResults() override;

// from QgsMapRendererJobWithPreview
Expand All @@ -56,6 +57,7 @@ class CORE_EXPORT QgsMapRendererSequentialJob : public QgsMapRendererQImageJob
QImage mImage;
QPainter* mPainter;
QgsLabelingResults* mLabelingResults;
bool mUsedCachedLabels = false;

};

Expand Down
7 changes: 5 additions & 2 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -546,8 +546,11 @@ void QgsMapCanvas::rendererJobFinished()
{
// take labeling results before emitting renderComplete, so labeling map tools
// connected to signal work with correct results
delete mLabelingResults;
mLabelingResults = mJob->takeLabelingResults();
if ( !mJob->usedCachedLabels() )
{
delete mLabelingResults;
mLabelingResults = mJob->takeLabelingResults();
}

QImage img = mJob->renderedImage();

Expand Down

0 comments on commit 2b3805e

Please sign in to comment.