Skip to content
Permalink
Browse files

Correctly resolve paths for raster image fill symbol layers

  • Loading branch information
nyalldawson committed Jan 29, 2018
1 parent ec22411 commit da4d937758263e6eeb186eae3d6b2bc87e020df2
@@ -760,6 +760,14 @@ class QgsRasterFillSymbolLayer: QgsImageFillSymbolLayer

static QgsSymbolLayer *create( const QgsStringMap &properties = QgsStringMap() ) /Factory/;

static void resolvePaths( QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving );
%Docstring
Turns relative paths in properties map to absolute when reading and vice versa when writing.
Used internally when reading/writing symbols.

.. versionadded:: 3.0
%End

virtual QString layerType() const;

virtual void renderPolygon( const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolRenderContext &context );
@@ -3622,6 +3622,18 @@ QgsSymbolLayer *QgsRasterFillSymbolLayer::create( const QgsStringMap &properties
return symbolLayer;
}

void QgsRasterFillSymbolLayer::resolvePaths( QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving )
{
QgsStringMap::iterator it = properties.find( QStringLiteral( "imageFile" ) );
if ( it != properties.end() )
{
if ( saving )
it.value() = pathResolver.writePath( it.value() );
else
it.value() = pathResolver.readPath( it.value() );
}
}

bool QgsRasterFillSymbolLayer::setSubSymbol( QgsSymbol *symbol )
{
Q_UNUSED( symbol );
@@ -3770,7 +3782,7 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext
if ( hasFileExpression )
{
context.setOriginalValueVariable( mImageFilePath );
file = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyFile, context.renderContext().expressionContext(), file );
file = context.renderContext().pathResolver().readPath( mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyFile, context.renderContext().expressionContext(), file ) );
}
applyPattern( mBrush, file, width, opacity, context );
}
@@ -693,6 +693,13 @@ class CORE_EXPORT QgsRasterFillSymbolLayer: public QgsImageFillSymbolLayer

static QgsSymbolLayer *create( const QgsStringMap &properties = QgsStringMap() ) SIP_FACTORY;

/**
* Turns relative paths in properties map to absolute when reading and vice versa when writing.
* Used internally when reading/writing symbols.
* \since QGIS 3.0
*/
static void resolvePaths( QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving );

// implemented from base classes
QString layerType() const override;
void renderPolygon( const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolRenderContext &context ) override;
@@ -52,7 +52,7 @@ QgsSymbolLayerRegistry::QgsSymbolLayerRegistry()
addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "ShapeburstFill" ), QObject::tr( "Shapeburst fill" ), QgsSymbol::Fill,
QgsShapeburstFillSymbolLayer::create ) );
addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "RasterFill" ), QObject::tr( "Raster image fill" ), QgsSymbol::Fill,
QgsRasterFillSymbolLayer::create ) );
QgsRasterFillSymbolLayer::create, nullptr, QgsRasterFillSymbolLayer::resolvePaths ) );
addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SVGFill" ), QObject::tr( "SVG fill" ), QgsSymbol::Fill,
QgsSVGFillSymbolLayer::create, QgsSVGFillSymbolLayer::createFromSld, QgsSVGFillSymbolLayer::resolvePaths ) );
addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "CentroidFill" ), QObject::tr( "Centroid fill" ), QgsSymbol::Fill,

0 comments on commit da4d937

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