Skip to content

Commit 54d8d11

Browse files
authored
Merge pull request #4092 from nyalldawson/maprenderer_api
Make protected members in QgsMapRendererJob not part of public API
2 parents 9fcc130 + 7550686 commit 54d8d11

12 files changed

+39
-113
lines changed

doc/api_break.dox

+2
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,8 @@ be returned instead of a null pointer if no transformation is required.
13391339
QgsMapRendererJob {#qgis_api_break_3_0_QgsMapRendererJob}
13401340
-----------------
13411341

1342+
- All protected members are now considered private, and are no longer exposed to the Python bindings. QgsMapRendererJob
1343+
and subclasses are not designed to be subclassed in PyQGIS.
13421344
- reprojectToLayerExtent() now takes a QgsCoordinateTransform reference, not a pointer. An invalid QgsCoordinateTransform should
13431345
be used instead of a null pointer if no transformation is required.
13441346
- prepareJobs() and drawLabeling() (neither available in PyQGIS) do not take QgsPalLabeling parameter anymore. All drawing of labels is done by QgsLabelingEngine.

python/core/qgsmaprenderercustompainterjob.sip

-8
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,4 @@ class QgsMapRendererCustomPainterJob : QgsMapRendererJob
5151
*/
5252
void renderSynchronously();
5353

54-
protected slots:
55-
void futureFinished();
56-
57-
protected:
58-
static void staticRender( QgsMapRendererCustomPainterJob* self ); // function to be used within the thread
59-
60-
// these methods are called within worker thread
61-
void doRender();
6254
};

python/core/qgsmaprendererjob.sip

-63
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,3 @@
1-
2-
struct LayerRenderJob
3-
{
4-
QgsRenderContext context;
5-
QImage* img; // may be null if it is not necessary to draw to separate image (e.g. sequential rendering)
6-
QgsMapLayerRenderer* renderer; // must be deleted
7-
QPainter::CompositionMode blendMode;
8-
bool cached; // if true, img already contains cached image from previous rendering
9-
QString layerId;
10-
};
11-
12-
typedef QList<LayerRenderJob> LayerRenderJobs;
13-
14-
15-
/**
16-
* Abstract base class for map rendering implementations.
17-
*
18-
* The API is designed in a way that rendering is done asynchronously, therefore
19-
* the caller is not blocked while the rendering is in progress. Non-blocking
20-
* operation is quite important because the rendering can take considerable
21-
* amount of time.
22-
*
23-
* Common use case:
24-
* 0. prepare QgsMapSettings with rendering configuration (extent, layer, map size, ...)
25-
* 1. create QgsMapRendererJob subclass with QgsMapSettings instance
26-
* 2. connect to job's finished() signal
27-
* 3. call start(). Map rendering will start in background, the function immediately returns
28-
* 4. at some point, slot connected to finished() signal is called, map rendering is done
29-
*
30-
* It is possible to cancel the rendering job while it is active by calling cancel() function.
31-
*
32-
* The following subclasses are available:
33-
* - QgsMapRendererSequentialJob - renders map in one background thread to an image
34-
* - QgsMapRendererParallelJob - renders map in multiple background threads to an image
35-
* - QgsMapRendererCustomPainterJob - renders map with given QPainter in one background thread
36-
*
37-
* @note added in 2.4
38-
*/
391
class QgsMapRendererJob : QObject
402
{
413
%TypeHeaderCode
@@ -122,31 +84,6 @@ class QgsMapRendererJob : QObject
12284
//! emitted when asynchronous rendering is finished (or canceled).
12385
void finished();
12486

125-
protected:
126-
127-
/** Convenience function to project an extent into the layer source
128-
* CRS, but also split it into two extents if it crosses
129-
* the +/- 180 degree line. Modifies the given extent to be in the
130-
* source CRS coordinates, and if it was split, returns true, and
131-
* also sets the contents of the r2 parameter
132-
*/
133-
static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform& ct, QgsRectangle &extent, QgsRectangle &r2 );
134-
135-
//! @note not available in python bindings
136-
// LayerRenderJobs prepareJobs( QPainter* painter, QgsLabelingEngine* labelingEngine2 );
137-
138-
//! @note not available in python bindings
139-
// void cleanupJobs( LayerRenderJobs& jobs );
140-
141-
static QImage composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs );
142-
143-
bool needTemporaryImage( QgsMapLayer* ml );
144-
145-
//! @note not available in Python bindings
146-
// static void drawLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsLabelingEngine* labelingEngine2, QPainter* painter );
147-
148-
//! called when rendering has finished to update all layers' geometry caches
149-
void updateLayerGeometryCaches();
15087
};
15188

15289

python/core/qgsmaprendererparalleljob.sip

-10
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,4 @@ class QgsMapRendererParallelJob : QgsMapRendererQImageJob
2626
// from QgsMapRendererJobWithPreview
2727
virtual QImage renderedImage();
2828

29-
protected slots:
30-
//! layers are rendered, labeling is still pending
31-
void renderLayersFinished();
32-
//! all rendering is finished, including labeling
33-
void renderingFinished();
34-
35-
protected:
36-
37-
static void renderLayerStatic( LayerRenderJob& job );
38-
static void renderLabelsStatic( QgsMapRendererParallelJob* self );
3929
};

src/core/qgsmaprenderercustompainterjob.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include "qgsvectorlayer.h"
2525
#include "qgsrenderer.h"
2626

27-
2827
QgsMapRendererCustomPainterJob::QgsMapRendererCustomPainterJob( const QgsMapSettings& settings, QPainter* painter )
2928
: QgsMapRendererJob( settings )
3029
, mPainter( painter )

src/core/qgsmaprenderercustompainterjob.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,15 @@ class CORE_EXPORT QgsMapRendererCustomPainterJob : public QgsMapRendererJob
7171
*/
7272
void renderSynchronously();
7373

74-
protected slots:
74+
private slots:
7575
void futureFinished();
7676

77-
protected:
77+
private:
7878
static void staticRender( QgsMapRendererCustomPainterJob* self ); // function to be used within the thread
7979

8080
// these methods are called within worker thread
8181
void doRender();
8282

83-
private:
8483
QPainter* mPainter;
8584
QFuture<void> mFuture;
8685
QFutureWatcher<void> mFutureWatcher;
@@ -90,6 +89,7 @@ class CORE_EXPORT QgsMapRendererCustomPainterJob : public QgsMapRendererJob
9089
bool mActive;
9190
LayerRenderJobs mLayerJobs;
9291
bool mRenderSynchronously;
92+
9393
};
9494

9595

src/core/qgsmaprendererjob.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
#include "qgsvectorlayer.h"
3535
#include "qgscsexception.h"
3636

37+
///@cond PRIVATE
38+
3739
QgsMapRendererJob::QgsMapRendererJob( const QgsMapSettings& settings )
3840
: mSettings( settings )
3941
, mCache( nullptr )
@@ -388,3 +390,5 @@ void QgsMapRendererJob::logRenderingTime( const LayerRenderJobs& jobs )
388390
}
389391
QgsMessageLog::logMessage( QStringLiteral( "---" ), tr( "Rendering" ) );
390392
}
393+
394+
///@endcond PRIVATE

src/core/qgsmaprendererjob.h

+25-20
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ class QgsMapRendererCache;
3737
class QgsPalLabeling;
3838
class QgsFeatureFilterProvider;
3939

40+
/// @cond PRIVATE
4041

4142
/** \ingroup core
4243
* Structure keeping low-level rendering job information.
43-
* @note not part of public API!
4444
*/
4545
struct LayerRenderJob
4646
{
@@ -56,6 +56,7 @@ struct LayerRenderJob
5656

5757
typedef QList<LayerRenderJob> LayerRenderJobs;
5858

59+
///@endcond PRIVATE
5960

6061
/** \ingroup core
6162
* Abstract base class for map rendering implementations.
@@ -168,46 +169,50 @@ class CORE_EXPORT QgsMapRendererJob : public QObject
168169

169170
protected:
170171

171-
/** Convenience function to project an extent into the layer source
172-
* CRS, but also split it into two extents if it crosses
173-
* the +/- 180 degree line. Modifies the given extent to be in the
174-
* source CRS coordinates, and if it was split, returns true, and
175-
* also sets the contents of the r2 parameter
176-
*/
177-
static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
172+
QgsMapSettings mSettings;
173+
QTime mRenderingStart;
174+
Errors mErrors;
175+
176+
QgsMapRendererCache* mCache = nullptr;
177+
178+
int mRenderingTime = 0;
178179

179180
//! @note not available in python bindings
180181
LayerRenderJobs prepareJobs( QPainter* painter, QgsLabelingEngine* labelingEngine2 );
181182

182183
//! @note not available in python bindings
183-
void cleanupJobs( LayerRenderJobs& jobs );
184+
static QImage composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs );
184185

185186
//! @note not available in python bindings
186187
void logRenderingTime( const LayerRenderJobs& jobs );
187188

188-
static QImage composeImage( const QgsMapSettings& settings, const LayerRenderJobs& jobs );
189-
190-
bool needTemporaryImage( QgsMapLayer* ml );
189+
//! @note not available in python bindings
190+
void cleanupJobs( LayerRenderJobs& jobs );
191191

192192
//! @note not available in Python bindings
193193
static void drawLabeling( const QgsMapSettings& settings, QgsRenderContext& renderContext, QgsLabelingEngine* labelingEngine2, QPainter* painter );
194194

195+
private:
196+
197+
/** Convenience function to project an extent into the layer source
198+
* CRS, but also split it into two extents if it crosses
199+
* the +/- 180 degree line. Modifies the given extent to be in the
200+
* source CRS coordinates, and if it was split, returns true, and
201+
* also sets the contents of the r2 parameter
202+
*/
203+
static bool reprojectToLayerExtent( const QgsMapLayer *ml, const QgsCoordinateTransform &ct, QgsRectangle &extent, QgsRectangle &r2 );
204+
205+
bool needTemporaryImage( QgsMapLayer* ml );
206+
195207
//! called when rendering has finished to update all layers' geometry caches
196208
void updateLayerGeometryCaches();
197-
QgsMapSettings mSettings;
198-
Errors mErrors;
199-
200-
QgsMapRendererCache* mCache;
201209

202210
//! list of layer IDs for which the geometry cache should be updated
203211
QStringList mRequestedGeomCacheForLayers;
204212
//! map of geometry caches
205213
QMap<QString, QgsGeometryCache> mGeometryCaches;
206214

207-
QTime mRenderingStart;
208-
int mRenderingTime;
209-
210-
const QgsFeatureFilterProvider *mFeatureFilterProvider;
215+
const QgsFeatureFilterProvider *mFeatureFilterProvider = nullptr;
211216
};
212217

213218

src/core/qgsmaprendererparalleljob.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
#include <QtConcurrentMap>
2626

27-
2827
QgsMapRendererParallelJob::QgsMapRendererParallelJob( const QgsMapSettings& settings )
2928
: QgsMapRendererQImageJob( settings )
3029
, mStatus( Idle )

src/core/qgsmaprendererparalleljob.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,17 @@ class CORE_EXPORT QgsMapRendererParallelJob : public QgsMapRendererQImageJob
4444
// from QgsMapRendererJobWithPreview
4545
virtual QImage renderedImage() override;
4646

47-
protected slots:
47+
private slots:
4848
//! layers are rendered, labeling is still pending
4949
void renderLayersFinished();
5050
//! all rendering is finished, including labeling
5151
void renderingFinished();
5252

53-
protected:
53+
private:
5454

5555
static void renderLayerStatic( LayerRenderJob& job );
5656
static void renderLabelsStatic( QgsMapRendererParallelJob* self );
5757

58-
protected:
59-
6058
QImage mFinalImage;
6159

6260
//! @note not available in Python bindings
@@ -72,6 +70,7 @@ class CORE_EXPORT QgsMapRendererParallelJob : public QgsMapRendererQImageJob
7270
QgsRenderContext mLabelingRenderContext;
7371
QFuture<void> mLabelingFuture;
7472
QFutureWatcher<void> mLabelingFutureWatcher;
73+
7574
};
7675

7776

src/core/qgsmaprenderersequentialjob.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "qgsmaprenderercustompainterjob.h"
2020
#include "qgspallabeling.h"
2121

22-
2322
QgsMapRendererSequentialJob::QgsMapRendererSequentialJob( const QgsMapSettings& settings )
2423
: QgsMapRendererQImageJob( settings )
2524
, mInternalJob( nullptr )
@@ -138,4 +137,3 @@ void QgsMapRendererSequentialJob::internalFinished()
138137

139138
emit finished();
140139
}
141-

src/core/qgsmaprenderersequentialjob.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,13 @@ class CORE_EXPORT QgsMapRendererSequentialJob : public QgsMapRendererQImageJob
5050

5151
void internalFinished();
5252

53-
protected:
53+
private:
5454

5555
QgsMapRendererCustomPainterJob* mInternalJob;
5656
QImage mImage;
5757
QPainter* mPainter;
5858
QgsLabelingResults* mLabelingResults;
59+
5960
};
6061

6162

0 commit comments

Comments
 (0)