Skip to content
Permalink
Browse files

Add transform context to QgsMapSettings and QgsRenderContext

And also throw warnings when the context isn't set for these objects
  • Loading branch information
nyalldawson committed Nov 6, 2017
1 parent cc424c9 commit fed8a6786ed96a4575f9f88b5978250b17b381e3
@@ -310,6 +310,27 @@ Return the distance in geographical coordinates that equals to one pixel in the
:rtype: QgsDatumTransformStore
%End

QgsCoordinateTransformContext transformContext() const;
%Docstring
Returns the coordinate transform context, which stores various
information regarding which datum transforms should be used when transforming points
from a source to destination coordinate reference system.

.. versionadded:: 3.0
.. seealso:: setTransformContext()
:rtype: QgsCoordinateTransformContext
%End

void setTransformContext( const QgsCoordinateTransformContext &context );
%Docstring
Sets the coordinate transform ``context``, which stores various
information regarding which datum transforms should be used when transforming points
from a source to destination coordinate reference system.

.. versionadded:: 3.0
.. seealso:: transformContext()
%End

const QgsMapToPixel &mapToPixel() const;
%Docstring
:rtype: QgsMapToPixel
@@ -442,6 +463,7 @@ Gets segmentation tolerance type (maximum angle or maximum difference between cu




void updateDerived();
};

@@ -110,6 +110,27 @@ class QgsRenderContext
:rtype: QgsDistanceArea
%End

QgsCoordinateTransformContext transformContext() const;
%Docstring
Returns the context's coordinate transform context, which stores various
information regarding which datum transforms should be used when transforming points
from a source to destination coordinate reference system.

.. versionadded:: 3.0
.. seealso:: setTransformContext()
:rtype: QgsCoordinateTransformContext
%End

void setTransformContext( const QgsCoordinateTransformContext &context );
%Docstring
Sets the context's coordinate transform ``context``, which stores various
information regarding which datum transforms should be used when transforming points
from a source to destination coordinate reference system.

.. versionadded:: 3.0
.. seealso:: transformContext()
%End

const QgsRectangle &extent() const;
%Docstring
:rtype: QgsRectangle
@@ -295,6 +295,7 @@ void QgsMapSaveDialog::applyMapSettings( QgsMapSettings &mapSettings )
mapSettings.setBackgroundColor( mMapCanvas->canvasColor() );
mapSettings.setRotation( mMapCanvas->rotation() );
mapSettings.setLayers( mMapCanvas->layers() );
mapSettings.setTransformContext( QgsProject::instance()->transformContext() );

//build the expression context
QgsExpressionContext expressionContext;
@@ -165,6 +165,7 @@ QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle &extent, QSizeF s
jobMapSettings.setBackgroundColor( Qt::transparent );
jobMapSettings.setRotation( mEvaluatedMapRotation );
jobMapSettings.setEllipsoid( mComposition->project()->ellipsoid() );
jobMapSettings.setTransformContext( mComposition->project()->transformContext() );

//set layers to render
QList<QgsMapLayer *> layers = layersToRender( &expressionContext );
@@ -362,6 +362,23 @@ double QgsMapSettings::scale() const
return mScale;
}

QgsCoordinateTransformContext QgsMapSettings::transformContext() const
{
#ifdef QGISDEBUG
if ( !mHasTransformContext )
qWarning( "No QgsCoordinateTransformContext context set for transform" );
#endif

return mTransformContext;
}

void QgsMapSettings::setTransformContext( const QgsCoordinateTransformContext &context )
{
mTransformContext = context;
#ifdef QGISDEBUG
mHasTransformContext = true;
#endif
}

QgsCoordinateTransform QgsMapSettings::layerTransform( const QgsMapLayer *layer ) const
{
@@ -274,6 +274,26 @@ class CORE_EXPORT QgsMapSettings
const QgsDatumTransformStore &datumTransformStore() const { return mDatumTransformStore; } SIP_SKIP
QgsDatumTransformStore &datumTransformStore() { return mDatumTransformStore; }

/**
* Returns the coordinate transform context, which stores various
* information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system.
*
* \since QGIS 3.0
* \see setTransformContext()
*/
QgsCoordinateTransformContext transformContext() const;

/**
* Sets the coordinate transform \a context, which stores various
* information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system.
*
* \since QGIS 3.0
* \see transformContext()
*/
void setTransformContext( const QgsCoordinateTransformContext &context );

const QgsMapToPixel &mapToPixel() const { return mMapToPixel; }

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

QgsCoordinateTransformContext mTransformContext;
#ifdef QGISDEBUG
bool mHasTransformContext = false;
#endif

void updateDerived();
};

@@ -95,6 +95,23 @@ QgsRenderContext QgsRenderContext::fromQPainter( QPainter *painter )
return context;
}

QgsCoordinateTransformContext QgsRenderContext::transformContext() const
{
#ifdef QGISDEBUG
if ( !mHasTransformContext )
qWarning( "No QgsCoordinateTransformContext context set for transform" );
#endif
return mTransformContext;
}

void QgsRenderContext::setTransformContext( const QgsCoordinateTransformContext &context )
{
mTransformContext = context;
#ifdef QGISDEBUG
mHasTransformContext = true;
#endif
}

void QgsRenderContext::setFlags( QgsRenderContext::Flags flags )
{
mFlags = flags;
@@ -142,6 +159,7 @@ QgsRenderContext QgsRenderContext::fromMapSettings( const QgsMapSettings &mapSet
ctx.setSegmentationToleranceType( mapSettings.segmentationToleranceType() );
ctx.mDistanceArea.setSourceCrs( mapSettings.destinationCrs() );
ctx.mDistanceArea.setEllipsoid( mapSettings.ellipsoid() );
ctx.setTransformContext( mapSettings.transformContext() );
//this flag is only for stopping during the current rendering progress,
//so must be false at every new render operation
ctx.setRenderingStopped( false );
@@ -32,6 +32,7 @@
#include "qgsrectangle.h"
#include "qgsvectorsimplifymethod.h"
#include "qgsdistancearea.h"
#include "qgscoordinatetransformcontext.h"

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

/**
* Returns the context's coordinate transform context, which stores various
* information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system.
*
* \since QGIS 3.0
* \see setTransformContext()
*/
QgsCoordinateTransformContext transformContext() const;

/**
* Sets the context's coordinate transform \a context, which stores various
* information regarding which datum transforms should be used when transforming points
* from a source to destination coordinate reference system.
*
* \since QGIS 3.0
* \see transformContext()
*/
void setTransformContext( const QgsCoordinateTransformContext &context );

const QgsRectangle &extent() const {return mExtent;}

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

QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType = QgsAbstractGeometry::MaximumAngle;

QgsCoordinateTransformContext mTransformContext;
#ifdef QGISDEBUG
bool mHasTransformContext = false;
#endif
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsRenderContext::Flags )
@@ -137,6 +137,12 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent )
{
mSettings.setEllipsoid( QgsProject::instance()->ellipsoid() );
} );
mSettings.setTransformContext( QgsProject::instance()->transformContext() );
connect( QgsProject::instance(), &QgsProject::transformContextChanged,
this, [ = ]
{
mSettings.setTransformContext( QgsProject::instance()->transformContext() );
} );

//segmentation parameters
QgsSettings settings;

0 comments on commit fed8a67

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