Skip to content

Commit

Permalink
Add transform context to QgsMapSettings and QgsRenderContext
Browse files Browse the repository at this point in the history
And also throw warnings when the context isn't set for these objects
  • Loading branch information
nyalldawson committed Dec 15, 2017
1 parent cc424c9 commit fed8a67
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 0 deletions.
22 changes: 22 additions & 0 deletions python/core/qgsmapsettings.sip
Expand Up @@ -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
Expand Down Expand Up @@ -442,6 +463,7 @@ Gets segmentation tolerance type (maximum angle or maximum difference between cu




void updateDerived();
};

Expand Down
21 changes: 21 additions & 0 deletions python/core/qgsrendercontext.sip
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsmapsavedialog.cpp
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -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 );
Expand Down
17 changes: 17 additions & 0 deletions src/core/qgsmapsettings.cpp
Expand Up @@ -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
{
Expand Down
25 changes: 25 additions & 0 deletions src/core/qgsmapsettings.h
Expand Up @@ -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; }

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

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

void updateDerived();
};

Expand Down
18 changes: 18 additions & 0 deletions src/core/qgsrendercontext.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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 );
Expand Down
26 changes: 26 additions & 0 deletions src/core/qgsrendercontext.h
Expand Up @@ -32,6 +32,7 @@
#include "qgsrectangle.h"
#include "qgsvectorsimplifymethod.h"
#include "qgsdistancearea.h"
#include "qgscoordinatetransformcontext.h"

class QPainter;
class QgsAbstractGeometry;
Expand Down Expand Up @@ -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;}
Expand Down Expand Up @@ -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 )
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit fed8a67

Please sign in to comment.