Skip to content

Commit 2b3805e

Browse files
committed
Reuse existing labeling results if cached labels were redrawn
1 parent 33eb4bc commit 2b3805e

11 files changed

+42
-3
lines changed

python/core/qgsmaprendererjob.sip

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class QgsMapRendererJob : QObject
2424
//! Tell whether the rendering job is currently running in background.
2525
virtual bool isActive() const = 0;
2626

27+
virtual bool usedCachedLabels() const = 0;
28+
2729
//! Get pointer to internal labeling engine (in order to get access to the results)
2830
virtual QgsLabelingResults* takeLabelingResults() = 0 /Transfer/;
2931

python/core/qgsmaprendererparalleljob.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class QgsMapRendererParallelJob : QgsMapRendererQImageJob
2020
virtual void cancel();
2121
virtual void waitForFinished();
2222
virtual bool isActive() const;
23+
virtual bool usedCachedLabels() const;
2324

2425
virtual QgsLabelingResults* takeLabelingResults() /Transfer/;
2526

python/core/qgsmaprenderersequentialjob.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class QgsMapRendererSequentialJob : QgsMapRendererQImageJob
2121
virtual void cancel();
2222
virtual void waitForFinished();
2323
virtual bool isActive() const;
24+
virtual bool usedCachedLabels() const;
2425

2526
virtual QgsLabelingResults* takeLabelingResults() /Transfer/;
2627

src/core/qgsmaprenderercustompainterjob.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ bool QgsMapRendererCustomPainterJob::isActive() const
156156
return mActive;
157157
}
158158

159+
bool QgsMapRendererCustomPainterJob::usedCachedLabels() const
160+
{
161+
return mLabelJob.cached;
162+
}
159163

160164
QgsLabelingResults* QgsMapRendererCustomPainterJob::takeLabelingResults()
161165
{

src/core/qgsmaprenderercustompainterjob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class CORE_EXPORT QgsMapRendererCustomPainterJob : public QgsMapRendererJob
4141
virtual void cancel() override;
4242
virtual void waitForFinished() override;
4343
virtual bool isActive() const override;
44+
virtual bool usedCachedLabels() const override;
4445
virtual QgsLabelingResults* takeLabelingResults() override;
4546

4647
//! @note not available in python bindings

src/core/qgsmaprendererjob.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,20 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
125125
//! Tell whether the rendering job is currently running in background.
126126
virtual bool isActive() const = 0;
127127

128-
//! Get pointer to internal labeling engine (in order to get access to the results)
128+
/**
129+
* Returns true if the render job was able to use a cached labeling solution.
130+
* If so, any previously stored labeling results (see takeLabelingResults())
131+
* should be retained.
132+
* @see takeLabelingResults()
133+
* @note added in QGIS 3.0
134+
*/
135+
virtual bool usedCachedLabels() const = 0;
136+
137+
/**
138+
* Get pointer to internal labeling engine (in order to get access to the results).
139+
* This should not be used if cached labeling was redrawn - see usedCachedLabels().
140+
* @see usedCachedLabels()
141+
*/
129142
virtual QgsLabelingResults* takeLabelingResults() = 0;
130143

131144
//! @note Added in QGIS 3.0

src/core/qgsmaprendererparalleljob.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ bool QgsMapRendererParallelJob::isActive() const
153153
return mStatus != Idle;
154154
}
155155

156+
bool QgsMapRendererParallelJob::usedCachedLabels() const
157+
{
158+
return mLabelJob.cached;
159+
}
160+
156161
QgsLabelingResults* QgsMapRendererParallelJob::takeLabelingResults()
157162
{
158163
if ( mLabelingEngineV2 )

src/core/qgsmaprendererparalleljob.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class CORE_EXPORT QgsMapRendererParallelJob : public QgsMapRendererQImageJob
3939
virtual void waitForFinished() override;
4040
virtual bool isActive() const override;
4141

42+
virtual bool usedCachedLabels() const override;
4243
virtual QgsLabelingResults* takeLabelingResults() override;
4344

4445
// from QgsMapRendererJobWithPreview

src/core/qgsmaprenderersequentialjob.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ bool QgsMapRendererSequentialJob::isActive() const
9898
return nullptr != mInternalJob;
9999
}
100100

101+
bool QgsMapRendererSequentialJob::usedCachedLabels() const
102+
{
103+
return mUsedCachedLabels;
104+
}
105+
101106
QgsLabelingResults* QgsMapRendererSequentialJob::takeLabelingResults()
102107
{
103108
QgsLabelingResults* tmp = mLabelingResults;
@@ -125,6 +130,7 @@ void QgsMapRendererSequentialJob::internalFinished()
125130
mPainter = nullptr;
126131

127132
mLabelingResults = mInternalJob->takeLabelingResults();
133+
mUsedCachedLabels = mInternalJob->usedCachedLabels();
128134

129135
mErrors = mInternalJob->errors();
130136

src/core/qgsmaprenderersequentialjob.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class CORE_EXPORT QgsMapRendererSequentialJob : public QgsMapRendererQImageJob
4141
virtual void waitForFinished() override;
4242
virtual bool isActive() const override;
4343

44+
virtual bool usedCachedLabels() const override;
4445
virtual QgsLabelingResults* takeLabelingResults() override;
4546

4647
// from QgsMapRendererJobWithPreview
@@ -56,6 +57,7 @@ class CORE_EXPORT QgsMapRendererSequentialJob : public QgsMapRendererQImageJob
5657
QImage mImage;
5758
QPainter* mPainter;
5859
QgsLabelingResults* mLabelingResults;
60+
bool mUsedCachedLabels = false;
5961

6062
};
6163

0 commit comments

Comments
 (0)