Skip to content
Permalink
Browse files

Reuse existing labeling results if cached labels were redrawn

  • Loading branch information
nyalldawson committed Feb 7, 2017
1 parent 33eb4bc commit 2b3805eea5fc3bb89ff086f0ac2dc1f1f8453787
@@ -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/;

@@ -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/;

@@ -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/;

@@ -156,6 +156,10 @@ bool QgsMapRendererCustomPainterJob::isActive() const
return mActive;
}

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

QgsLabelingResults* QgsMapRendererCustomPainterJob::takeLabelingResults()
{
@@ -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
@@ -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
@@ -153,6 +153,11 @@ bool QgsMapRendererParallelJob::isActive() const
return mStatus != Idle;
}

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

QgsLabelingResults* QgsMapRendererParallelJob::takeLabelingResults()
{
if ( mLabelingEngineV2 )
@@ -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
@@ -98,6 +98,11 @@ bool QgsMapRendererSequentialJob::isActive() const
return nullptr != mInternalJob;
}

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

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

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

mErrors = mInternalJob->errors();

@@ -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
@@ -56,6 +57,7 @@ class CORE_EXPORT QgsMapRendererSequentialJob : public QgsMapRendererQImageJob
QImage mImage;
QPainter* mPainter;
QgsLabelingResults* mLabelingResults;
bool mUsedCachedLabels = false;

};

@@ -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();

0 comments on commit 2b3805e

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