Skip to content

Commit fed8a67

Browse files
committed
Add transform context to QgsMapSettings and QgsRenderContext
And also throw warnings when the context isn't set for these objects
1 parent cc424c9 commit fed8a67

9 files changed

+137
-0
lines changed

python/core/qgsmapsettings.sip

+22
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,27 @@ Return the distance in geographical coordinates that equals to one pixel in the
310310
:rtype: QgsDatumTransformStore
311311
%End
312312

313+
QgsCoordinateTransformContext transformContext() const;
314+
%Docstring
315+
Returns the coordinate transform context, which stores various
316+
information regarding which datum transforms should be used when transforming points
317+
from a source to destination coordinate reference system.
318+
319+
.. versionadded:: 3.0
320+
.. seealso:: setTransformContext()
321+
:rtype: QgsCoordinateTransformContext
322+
%End
323+
324+
void setTransformContext( const QgsCoordinateTransformContext &context );
325+
%Docstring
326+
Sets the coordinate transform ``context``, which stores various
327+
information regarding which datum transforms should be used when transforming points
328+
from a source to destination coordinate reference system.
329+
330+
.. versionadded:: 3.0
331+
.. seealso:: transformContext()
332+
%End
333+
313334
const QgsMapToPixel &mapToPixel() const;
314335
%Docstring
315336
:rtype: QgsMapToPixel
@@ -442,6 +463,7 @@ Gets segmentation tolerance type (maximum angle or maximum difference between cu
442463

443464

444465

466+
445467
void updateDerived();
446468
};
447469

python/core/qgsrendercontext.sip

+21
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ class QgsRenderContext
110110
:rtype: QgsDistanceArea
111111
%End
112112

113+
QgsCoordinateTransformContext transformContext() const;
114+
%Docstring
115+
Returns the context's coordinate transform context, which stores various
116+
information regarding which datum transforms should be used when transforming points
117+
from a source to destination coordinate reference system.
118+
119+
.. versionadded:: 3.0
120+
.. seealso:: setTransformContext()
121+
:rtype: QgsCoordinateTransformContext
122+
%End
123+
124+
void setTransformContext( const QgsCoordinateTransformContext &context );
125+
%Docstring
126+
Sets the context's coordinate transform ``context``, which stores various
127+
information regarding which datum transforms should be used when transforming points
128+
from a source to destination coordinate reference system.
129+
130+
.. versionadded:: 3.0
131+
.. seealso:: transformContext()
132+
%End
133+
113134
const QgsRectangle &extent() const;
114135
%Docstring
115136
:rtype: QgsRectangle

src/app/qgsmapsavedialog.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ void QgsMapSaveDialog::applyMapSettings( QgsMapSettings &mapSettings )
295295
mapSettings.setBackgroundColor( mMapCanvas->canvasColor() );
296296
mapSettings.setRotation( mMapCanvas->rotation() );
297297
mapSettings.setLayers( mMapCanvas->layers() );
298+
mapSettings.setTransformContext( QgsProject::instance()->transformContext() );
298299

299300
//build the expression context
300301
QgsExpressionContext expressionContext;

src/core/composer/qgscomposermap.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle &extent, QSizeF s
165165
jobMapSettings.setBackgroundColor( Qt::transparent );
166166
jobMapSettings.setRotation( mEvaluatedMapRotation );
167167
jobMapSettings.setEllipsoid( mComposition->project()->ellipsoid() );
168+
jobMapSettings.setTransformContext( mComposition->project()->transformContext() );
168169

169170
//set layers to render
170171
QList<QgsMapLayer *> layers = layersToRender( &expressionContext );

src/core/qgsmapsettings.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,23 @@ double QgsMapSettings::scale() const
362362
return mScale;
363363
}
364364

365+
QgsCoordinateTransformContext QgsMapSettings::transformContext() const
366+
{
367+
#ifdef QGISDEBUG
368+
if ( !mHasTransformContext )
369+
qWarning( "No QgsCoordinateTransformContext context set for transform" );
370+
#endif
371+
372+
return mTransformContext;
373+
}
374+
375+
void QgsMapSettings::setTransformContext( const QgsCoordinateTransformContext &context )
376+
{
377+
mTransformContext = context;
378+
#ifdef QGISDEBUG
379+
mHasTransformContext = true;
380+
#endif
381+
}
365382

366383
QgsCoordinateTransform QgsMapSettings::layerTransform( const QgsMapLayer *layer ) const
367384
{

src/core/qgsmapsettings.h

+25
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,26 @@ class CORE_EXPORT QgsMapSettings
274274
const QgsDatumTransformStore &datumTransformStore() const { return mDatumTransformStore; } SIP_SKIP
275275
QgsDatumTransformStore &datumTransformStore() { return mDatumTransformStore; }
276276

277+
/**
278+
* Returns the coordinate transform context, which stores various
279+
* information regarding which datum transforms should be used when transforming points
280+
* from a source to destination coordinate reference system.
281+
*
282+
* \since QGIS 3.0
283+
* \see setTransformContext()
284+
*/
285+
QgsCoordinateTransformContext transformContext() const;
286+
287+
/**
288+
* Sets the coordinate transform \a context, which stores various
289+
* information regarding which datum transforms should be used when transforming points
290+
* from a source to destination coordinate reference system.
291+
*
292+
* \since QGIS 3.0
293+
* \see transformContext()
294+
*/
295+
void setTransformContext( const QgsCoordinateTransformContext &context );
296+
277297
const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }
278298

279299
/**
@@ -410,6 +430,11 @@ class CORE_EXPORT QgsMapSettings
410430
QgsScaleCalculator mScaleCalculator;
411431
QgsMapToPixel mMapToPixel;
412432

433+
QgsCoordinateTransformContext mTransformContext;
434+
#ifdef QGISDEBUG
435+
bool mHasTransformContext = false;
436+
#endif
437+
413438
void updateDerived();
414439
};
415440

src/core/qgsrendercontext.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,23 @@ QgsRenderContext QgsRenderContext::fromQPainter( QPainter *painter )
9595
return context;
9696
}
9797

98+
QgsCoordinateTransformContext QgsRenderContext::transformContext() const
99+
{
100+
#ifdef QGISDEBUG
101+
if ( !mHasTransformContext )
102+
qWarning( "No QgsCoordinateTransformContext context set for transform" );
103+
#endif
104+
return mTransformContext;
105+
}
106+
107+
void QgsRenderContext::setTransformContext( const QgsCoordinateTransformContext &context )
108+
{
109+
mTransformContext = context;
110+
#ifdef QGISDEBUG
111+
mHasTransformContext = true;
112+
#endif
113+
}
114+
98115
void QgsRenderContext::setFlags( QgsRenderContext::Flags flags )
99116
{
100117
mFlags = flags;
@@ -142,6 +159,7 @@ QgsRenderContext QgsRenderContext::fromMapSettings( const QgsMapSettings &mapSet
142159
ctx.setSegmentationToleranceType( mapSettings.segmentationToleranceType() );
143160
ctx.mDistanceArea.setSourceCrs( mapSettings.destinationCrs() );
144161
ctx.mDistanceArea.setEllipsoid( mapSettings.ellipsoid() );
162+
ctx.setTransformContext( mapSettings.transformContext() );
145163
//this flag is only for stopping during the current rendering progress,
146164
//so must be false at every new render operation
147165
ctx.setRenderingStopped( false );

src/core/qgsrendercontext.h

+26
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "qgsrectangle.h"
3333
#include "qgsvectorsimplifymethod.h"
3434
#include "qgsdistancearea.h"
35+
#include "qgscoordinatetransformcontext.h"
3536

3637
class QPainter;
3738
class QgsAbstractGeometry;
@@ -131,6 +132,26 @@ class CORE_EXPORT QgsRenderContext
131132
*/
132133
const QgsDistanceArea &distanceArea() const { return mDistanceArea; }
133134

135+
/**
136+
* Returns the context's coordinate transform context, which stores various
137+
* information regarding which datum transforms should be used when transforming points
138+
* from a source to destination coordinate reference system.
139+
*
140+
* \since QGIS 3.0
141+
* \see setTransformContext()
142+
*/
143+
QgsCoordinateTransformContext transformContext() const;
144+
145+
/**
146+
* Sets the context's coordinate transform \a context, which stores various
147+
* information regarding which datum transforms should be used when transforming points
148+
* from a source to destination coordinate reference system.
149+
*
150+
* \since QGIS 3.0
151+
* \see transformContext()
152+
*/
153+
void setTransformContext( const QgsCoordinateTransformContext &context );
154+
134155
const QgsRectangle &extent() const {return mExtent;}
135156

136157
const QgsMapToPixel &mapToPixel() const {return mMapToPixel;}
@@ -397,6 +418,11 @@ class CORE_EXPORT QgsRenderContext
397418
double mSegmentationTolerance = M_PI_2 / 90;
398419

399420
QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType = QgsAbstractGeometry::MaximumAngle;
421+
422+
QgsCoordinateTransformContext mTransformContext;
423+
#ifdef QGISDEBUG
424+
bool mHasTransformContext = false;
425+
#endif
400426
};
401427

402428
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRenderContext::Flags )

src/gui/qgsmapcanvas.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
137137
{
138138
mSettings.setEllipsoid( QgsProject::instance()->ellipsoid() );
139139
} );
140+
mSettings.setTransformContext( QgsProject::instance()->transformContext() );
141+
connect( QgsProject::instance(), &QgsProject::transformContextChanged,
142+
this, [ = ]
143+
{
144+
mSettings.setTransformContext( QgsProject::instance()->transformContext() );
145+
} );
140146

141147
//segmentation parameters
142148
QgsSettings settings;

0 commit comments

Comments
 (0)