Skip to content

Commit

Permalink
Correctly resolve paths for raster image fill symbol layers
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 29, 2018
1 parent ec22411 commit da4d937
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions python/core/symbology/qgsfillsymbollayer.sip.in
Expand Up @@ -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 );
Expand Down
14 changes: 13 additions & 1 deletion src/core/symbology/qgsfillsymbollayer.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
Expand Down
7 changes: 7 additions & 0 deletions src/core/symbology/qgsfillsymbollayer.h
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology/qgssymbollayerregistry.cpp
Expand Up @@ -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,
Expand Down

0 comments on commit da4d937

Please sign in to comment.