Skip to content
Permalink
Browse files

Expose project QgsPathResolver to render context

So that it can be used when resolving paths to data defined
file-based settings, e.g. svg marker paths.

Fixes #17364
  • Loading branch information
nyalldawson committed Jan 29, 2018
1 parent cf3014c commit ec224117debaa31ac76bdbc73c3158edb8175e27
@@ -327,6 +327,26 @@ from a source to destination coordinate reference system.
.. versionadded:: 3.0

.. seealso:: :py:func:`transformContext`
%End

const QgsPathResolver &pathResolver() const;
%Docstring
Returns the path resolver for conversion between relative and absolute paths
during rendering operations, e.g. for resolving relative symbol paths.

.. versionadded:: 3.0

.. seealso:: :py:func:`setPathResolver`
%End

void setPathResolver( const QgsPathResolver &resolver );
%Docstring
Sets the path ``resolver`` for conversion between relative and absolute paths
during rendering operations, e.g. for resolving relative symbol paths.

.. versionadded:: 3.0

.. seealso:: :py:func:`pathResolver`
%End

const QgsMapToPixel &mapToPixel() const;
@@ -465,6 +485,8 @@ Returns global configuration of the labeling engine





void updateDerived();
};

@@ -131,6 +131,26 @@ from a source to destination coordinate reference system.
.. versionadded:: 3.0

.. seealso:: :py:func:`transformContext`
%End

const QgsPathResolver &pathResolver() const;
%Docstring
Returns the path resolver for conversion between relative and absolute paths
during rendering operations, e.g. for resolving relative symbol paths.

.. versionadded:: 3.0

.. seealso:: :py:func:`setPathResolver`
%End

void setPathResolver( const QgsPathResolver &resolver );
%Docstring
Sets the path ``resolver`` for conversion between relative and absolute paths
during rendering operations, e.g. for resolving relative symbol paths.

.. versionadded:: 3.0

.. seealso:: :py:func:`pathResolver`
%End

const QgsRectangle &extent() const;
@@ -106,6 +106,24 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
*/
void setTransformContext( const QgsCoordinateTransformContext &context );

/**
* Returns the path resolver for conversion between relative and absolute paths
* during rendering operations, e.g. for resolving relative symbol paths.
*
* \since QGIS 3.0
* \see setPathResolver()
*/
const QgsPathResolver &pathResolver() const { return mPathResolver; }

/**
* Sets the path \a resolver for conversion between relative and absolute paths
* during rendering operations, e.g. for resolving relative symbol paths.
*
* \since QGIS 3.0
* \see pathResolver()
*/
void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }

//! Sets background color of the 3D map view
void setBackgroundColor( const QColor &color );
//! Returns background color of the 3D map view
@@ -259,6 +277,7 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject
QString mSkyboxFileExtension; //!< Extension part of the files with skybox textures
//! Coordinate transform context
QgsCoordinateTransformContext mTransformContext;
QgsPathResolver mPathResolver;
};


@@ -133,6 +133,7 @@ QgsMapSettings QgsTerrainTextureGenerator::baseMapSettings()
mapSettings.setBackgroundColor( mMap.backgroundColor() );
mapSettings.setFlag( QgsMapSettings::DrawLabeling, mMap.showLabels() );
mapSettings.setTransformContext( mMap.transformContext() );
mapSettings.setPathResolver( mMap.pathResolver() );
return mapSettings;
}

@@ -10300,6 +10300,7 @@ void QgisApp::new3DMapCanvas()
map->setBackgroundColor( mMapCanvas->canvasColor() );
map->setLayers( mMapCanvas->layers() );
map->setTransformContext( QgsProject::instance()->transformContext() );
map->setPathResolver( QgsProject::instance()->pathResolver() );
connect( QgsProject::instance(), &QgsProject::transformContextChanged, map, [map]
{
map->setTransformContext( QgsProject::instance()->transformContext() );
@@ -296,6 +296,7 @@ void QgsMapSaveDialog::applyMapSettings( QgsMapSettings &mapSettings )
mapSettings.setRotation( mMapCanvas->rotation() );
mapSettings.setLayers( mMapCanvas->layers() );
mapSettings.setTransformContext( QgsProject::instance()->transformContext() );
mapSettings.setPathResolver( QgsProject::instance()->pathResolver() );

//build the expression context
QgsExpressionContext expressionContext;
@@ -1096,6 +1096,7 @@ QgsMapSettings QgsLayoutItemMap::mapSettings( const QgsRectangle &extent, QSizeF
jobMapSettings.setFlag( QgsMapSettings::DrawSelection, false );
jobMapSettings.setFlag( QgsMapSettings::UseAdvancedEffects, mLayout->renderContext().flags() & QgsLayoutRenderContext::FlagUseAdvancedEffects );
jobMapSettings.setTransformContext( mLayout->project()->transformContext() );
jobMapSettings.setPathResolver( mLayout->project()->pathResolver() );

jobMapSettings.setLabelingEngineSettings( mLayout->project()->labelingEngineSettings() );

@@ -287,6 +287,24 @@ class CORE_EXPORT QgsMapSettings
*/
void setTransformContext( const QgsCoordinateTransformContext &context );

/**
* Returns the path resolver for conversion between relative and absolute paths
* during rendering operations, e.g. for resolving relative symbol paths.
*
* \since QGIS 3.0
* \see setPathResolver()
*/
const QgsPathResolver &pathResolver() const { return mPathResolver; }

/**
* Sets the path \a resolver for conversion between relative and absolute paths
* during rendering operations, e.g. for resolving relative symbol paths.
*
* \since QGIS 3.0
* \see pathResolver()
*/
void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }

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

/**
@@ -423,6 +441,9 @@ class CORE_EXPORT QgsMapSettings
QgsMapToPixel mMapToPixel;

QgsCoordinateTransformContext mTransformContext;

QgsPathResolver mPathResolver;

#ifdef QGISDEBUG
bool mHasTransformContext = false;
#endif
@@ -2566,8 +2566,8 @@ void QgsPalLayerSettings::parseShapeBackground( QgsRenderContext &context )
QgsDebugMsgLevel( QString( "exprVal ShapeSVGFile:%1" ).arg( svgfile ), 4 );

// '' empty paths are allowed
svgPath = svgfile;
dataDefinedValues.insert( QgsPalLayerSettings::ShapeSVGFile, QVariant( svgfile ) );
svgPath = QgsSymbolLayerUtils::svgSymbolNameToPath( svgfile, context.pathResolver() );
dataDefinedValues.insert( QgsPalLayerSettings::ShapeSVGFile, QVariant( svgPath ) );
}

// data defined shape size type?
@@ -56,6 +56,7 @@ QgsRenderContext::QgsRenderContext( const QgsRenderContext &rh )
, mSegmentationTolerance( rh.mSegmentationTolerance )
, mSegmentationToleranceType( rh.mSegmentationToleranceType )
, mTransformContext( rh.mTransformContext )
, mPathResolver( rh.mPathResolver )
#ifdef QGISDEBUG
, mHasTransformContext( rh.mHasTransformContext )
#endif
@@ -82,6 +83,7 @@ QgsRenderContext &QgsRenderContext::operator=( const QgsRenderContext &rh )
mSegmentationToleranceType = rh.mSegmentationToleranceType;
mDistanceArea = rh.mDistanceArea;
mTransformContext = rh.mTransformContext;
mPathResolver = rh.mPathResolver;
#ifdef QGISDEBUG
mHasTransformContext = rh.mHasTransformContext;
#endif
@@ -169,6 +171,7 @@ QgsRenderContext QgsRenderContext::fromMapSettings( const QgsMapSettings &mapSet
ctx.mDistanceArea.setSourceCrs( mapSettings.destinationCrs(), mapSettings.transformContext() );
ctx.mDistanceArea.setEllipsoid( mapSettings.ellipsoid() );
ctx.setTransformContext( mapSettings.transformContext() );
ctx.setPathResolver( mapSettings.pathResolver() );
//this flag is only for stopping during the current rendering progress,
//so must be false at every new render operation
ctx.setRenderingStopped( false );
@@ -33,6 +33,7 @@
#include "qgsvectorsimplifymethod.h"
#include "qgsdistancearea.h"
#include "qgscoordinatetransformcontext.h"
#include "qgspathresolver.h"

class QPainter;
class QgsAbstractGeometry;
@@ -152,6 +153,24 @@ class CORE_EXPORT QgsRenderContext
*/
void setTransformContext( const QgsCoordinateTransformContext &context );

/**
* Returns the path resolver for conversion between relative and absolute paths
* during rendering operations, e.g. for resolving relative symbol paths.
*
* \since QGIS 3.0
* \see setPathResolver()
*/
const QgsPathResolver &pathResolver() const { return mPathResolver; }

/**
* Sets the path \a resolver for conversion between relative and absolute paths
* during rendering operations, e.g. for resolving relative symbol paths.
*
* \since QGIS 3.0
* \see pathResolver()
*/
void setPathResolver( const QgsPathResolver &resolver ) { mPathResolver = resolver; }

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

const QgsMapToPixel &mapToPixel() const {return mMapToPixel;}
@@ -420,6 +439,9 @@ class CORE_EXPORT QgsRenderContext
QgsAbstractGeometry::SegmentationToleranceType mSegmentationToleranceType = QgsAbstractGeometry::MaximumAngle;

QgsCoordinateTransformContext mTransformContext;

QgsPathResolver mPathResolver;

#ifdef QGISDEBUG
bool mHasTransformContext = false;
#endif
@@ -2188,7 +2188,8 @@ void QgsSVGFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext &co
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyFile ) )
{
context.setOriginalValueVariable( mSvgFilePath );
svgFile = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyFile, context.renderContext().expressionContext(), mSvgFilePath );
svgFile = QgsSymbolLayerUtils::svgSymbolNameToPath( mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyFile, context.renderContext().expressionContext(), mSvgFilePath ),
context.renderContext().pathResolver() );
}
QColor svgFillColor = mColor;
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyFillColor ) )
@@ -1978,7 +1978,8 @@ void QgsSvgMarkerSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyName ) )
{
context.setOriginalValueVariable( mPath );
path = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyName, context.renderContext().expressionContext(), mPath );
path = QgsSymbolLayerUtils::svgSymbolNameToPath( mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyName, context.renderContext().expressionContext(), mPath ),
context.renderContext().pathResolver() );
}

double strokeWidth = mStrokeWidth;
@@ -2408,7 +2409,8 @@ bool QgsSvgMarkerSymbolLayer::writeDxf( QgsDxfExport &e, double mmMapUnitScaleFa
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyName ) )
{
context.setOriginalValueVariable( mPath );
path = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyName, context.renderContext().expressionContext(), mPath );
path = QgsSymbolLayerUtils::svgSymbolNameToPath( mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyName, context.renderContext().expressionContext(), mPath ),
context.renderContext().pathResolver() );
}

double strokeWidth = mStrokeWidth;
@@ -2484,7 +2486,8 @@ QRectF QgsSvgMarkerSymbolLayer::bounds( QPointF point, QgsSymbolRenderContext &c
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyName ) )
{
context.setOriginalValueVariable( mPath );
path = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyName, context.renderContext().expressionContext(), mPath );
path = QgsSymbolLayerUtils::svgSymbolNameToPath( mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyName, context.renderContext().expressionContext(), mPath ),
context.renderContext().pathResolver() );
}

double strokeWidth = mStrokeWidth;
@@ -503,6 +503,7 @@ void QgsMapCanvas::refreshMap()
<< new QgsExpressionContextScope( mExpressionContextScope );

mSettings.setExpressionContext( expressionContext );
mSettings.setPathResolver( QgsProject::instance()->pathResolver() );

if ( !mTheme.isEmpty() )
{

0 comments on commit ec22411

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