Skip to content

Commit da4d937

Browse files
committedJan 29, 2018
Correctly resolve paths for raster image fill symbol layers
1 parent ec22411 commit da4d937

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed
 

‎python/core/symbology/qgsfillsymbollayer.sip.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,14 @@ class QgsRasterFillSymbolLayer: QgsImageFillSymbolLayer
760760

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

763+
static void resolvePaths( QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving );
764+
%Docstring
765+
Turns relative paths in properties map to absolute when reading and vice versa when writing.
766+
Used internally when reading/writing symbols.
767+
768+
.. versionadded:: 3.0
769+
%End
770+
763771
virtual QString layerType() const;
764772

765773
virtual void renderPolygon( const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolRenderContext &context );

‎src/core/symbology/qgsfillsymbollayer.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3622,6 +3622,18 @@ QgsSymbolLayer *QgsRasterFillSymbolLayer::create( const QgsStringMap &properties
36223622
return symbolLayer;
36233623
}
36243624

3625+
void QgsRasterFillSymbolLayer::resolvePaths( QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving )
3626+
{
3627+
QgsStringMap::iterator it = properties.find( QStringLiteral( "imageFile" ) );
3628+
if ( it != properties.end() )
3629+
{
3630+
if ( saving )
3631+
it.value() = pathResolver.writePath( it.value() );
3632+
else
3633+
it.value() = pathResolver.readPath( it.value() );
3634+
}
3635+
}
3636+
36253637
bool QgsRasterFillSymbolLayer::setSubSymbol( QgsSymbol *symbol )
36263638
{
36273639
Q_UNUSED( symbol );
@@ -3770,7 +3782,7 @@ void QgsRasterFillSymbolLayer::applyDataDefinedSettings( QgsSymbolRenderContext
37703782
if ( hasFileExpression )
37713783
{
37723784
context.setOriginalValueVariable( mImageFilePath );
3773-
file = mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyFile, context.renderContext().expressionContext(), file );
3785+
file = context.renderContext().pathResolver().readPath( mDataDefinedProperties.valueAsString( QgsSymbolLayer::PropertyFile, context.renderContext().expressionContext(), file ) );
37743786
}
37753787
applyPattern( mBrush, file, width, opacity, context );
37763788
}

‎src/core/symbology/qgsfillsymbollayer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,13 @@ class CORE_EXPORT QgsRasterFillSymbolLayer: public QgsImageFillSymbolLayer
693693

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

696+
/**
697+
* Turns relative paths in properties map to absolute when reading and vice versa when writing.
698+
* Used internally when reading/writing symbols.
699+
* \since QGIS 3.0
700+
*/
701+
static void resolvePaths( QgsStringMap &properties, const QgsPathResolver &pathResolver, bool saving );
702+
696703
// implemented from base classes
697704
QString layerType() const override;
698705
void renderPolygon( const QPolygonF &points, QList<QPolygonF> *rings, QgsSymbolRenderContext &context ) override;

‎src/core/symbology/qgssymbollayerregistry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ QgsSymbolLayerRegistry::QgsSymbolLayerRegistry()
5252
addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "ShapeburstFill" ), QObject::tr( "Shapeburst fill" ), QgsSymbol::Fill,
5353
QgsShapeburstFillSymbolLayer::create ) );
5454
addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "RasterFill" ), QObject::tr( "Raster image fill" ), QgsSymbol::Fill,
55-
QgsRasterFillSymbolLayer::create ) );
55+
QgsRasterFillSymbolLayer::create, nullptr, QgsRasterFillSymbolLayer::resolvePaths ) );
5656
addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "SVGFill" ), QObject::tr( "SVG fill" ), QgsSymbol::Fill,
5757
QgsSVGFillSymbolLayer::create, QgsSVGFillSymbolLayer::createFromSld, QgsSVGFillSymbolLayer::resolvePaths ) );
5858
addSymbolLayerType( new QgsSymbolLayerMetadata( QStringLiteral( "CentroidFill" ), QObject::tr( "Centroid fill" ), QgsSymbol::Fill,

0 commit comments

Comments
 (0)
Please sign in to comment.