Skip to content

Commit 68532c2

Browse files
author
mhugent
committedNov 5, 2010
Better handling of relative / absolute pathes for fill symbol layer. Fixes bug #3154
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14515 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

1 file changed

+40
-38
lines changed

1 file changed

+40
-38
lines changed
 

‎src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "qgsfillsymbollayerv2.h"
2+
#include "qgsmarkersymbollayerv2.h"
23
#include "qgssymbollayerv2utils.h"
34

4-
#include "qgsapplication.h"
55
#include "qgsrendercontext.h"
66
#include "qgsproject.h"
77

@@ -10,7 +10,7 @@
1010
#include <QSvgRenderer>
1111

1212
QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2( QColor color, Qt::BrushStyle style, QColor borderColor, Qt::PenStyle borderStyle, double borderWidth )
13-
: mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth )
13+
: mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth )
1414
{
1515
mColor = color;
1616
}
@@ -25,17 +25,17 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props
2525
double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH;
2626
QPointF offset;
2727

28-
if ( props.contains( "color" ) )
28+
if( props.contains( "color" ) )
2929
color = QgsSymbolLayerV2Utils::decodeColor( props["color"] );
30-
if ( props.contains( "style" ) )
30+
if( props.contains( "style" ) )
3131
style = QgsSymbolLayerV2Utils::decodeBrushStyle( props["style"] );
32-
if ( props.contains( "color_border" ) )
32+
if( props.contains( "color_border" ) )
3333
borderColor = QgsSymbolLayerV2Utils::decodeColor( props["color_border"] );
34-
if ( props.contains( "style_border" ) )
34+
if( props.contains( "style_border" ) )
3535
borderStyle = QgsSymbolLayerV2Utils::decodePenStyle( props["style_border"] );
36-
if ( props.contains( "width_border" ) )
36+
if( props.contains( "width_border" ) )
3737
borderWidth = props["width_border"].toDouble();
38-
if ( props.contains( "offset" ) )
38+
if( props.contains( "offset" ) )
3939
offset = QgsSymbolLayerV2Utils::decodePoint( props["offset"] );
4040

4141
QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( color, style, borderColor, borderStyle, borderWidth );
@@ -56,15 +56,15 @@ void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context
5656

5757
// scale brush content for printout
5858
double rasterScaleFactor = context.renderContext().rasterScaleFactor();
59-
if ( rasterScaleFactor != 1.0 )
59+
if( rasterScaleFactor != 1.0 )
6060
{
6161
mBrush.setMatrix( QMatrix().scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor ) );
6262
}
6363

6464
QColor selColor = context.selectionColor();
6565
// selColor.setAlphaF( context.alpha() );
6666
mSelBrush = QBrush( selColor );
67-
if ( selectFillStyle ) mSelBrush.setStyle( mBrushStyle );
67+
if( selectFillStyle ) mSelBrush.setStyle( mBrushStyle );
6868
mBorderColor.setAlphaF( context.alpha() );
6969
mPen = QPen( mBorderColor );
7070
mPen.setStyle( mBorderStyle );
@@ -78,20 +78,20 @@ void QgsSimpleFillSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
7878
void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
7979
{
8080
QPainter* p = context.renderContext().painter();
81-
if ( !p )
81+
if( !p )
8282
{
8383
return;
8484
}
8585

8686
p->setBrush( context.selected() ? mSelBrush : mBrush );
8787
p->setPen( mPen );
8888

89-
if ( !mOffset.isNull() )
89+
if( !mOffset.isNull() )
9090
p->translate( mOffset );
9191

9292
_renderPolygon( p, points, rings );
9393

94-
if ( !mOffset.isNull() )
94+
if( !mOffset.isNull() )
9595
p->translate( -mOffset );
9696
}
9797

@@ -138,7 +138,7 @@ QgsSVGFillSymbolLayer::~QgsSVGFillSymbolLayer()
138138
void QgsSVGFillSymbolLayer::setSvgFilePath( const QString& svgPath )
139139
{
140140
QFile svgFile( svgPath );
141-
if ( svgFile.open( QFile::ReadOnly ) )
141+
if( svgFile.open( QFile::ReadOnly ) )
142142
{
143143
mSvgData = svgFile.readAll();
144144
storeViewBox();
@@ -153,22 +153,24 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
153153
QString svgFilePath;
154154

155155

156-
if ( properties.contains( "width" ) )
156+
if( properties.contains( "width" ) )
157157
{
158158
width = properties["width"].toDouble();
159159
}
160-
if ( properties.contains( "svgFile" ) )
160+
if( properties.contains( "svgFile" ) )
161161
{
162-
svgFilePath = QgsApplication::relativePathToAbsolutePath( properties["svgFile"], QgsApplication::svgPath() );
162+
QString svgName = properties["svgFile"];
163+
QString savePath = QgsSvgMarkerSymbolLayerV2::symbolNameToPath( svgName );
164+
svgFilePath = ( savePath.isEmpty() ? svgName : savePath );
163165
}
164166

165-
if ( !svgFilePath.isEmpty() )
167+
if( !svgFilePath.isEmpty() )
166168
{
167169
return new QgsSVGFillSymbolLayer( svgFilePath, width );
168170
}
169171
else
170172
{
171-
if ( properties.contains( "data" ) )
173+
if( properties.contains( "data" ) )
172174
{
173175
data = QByteArray::fromHex( properties["data"].toLocal8Bit() );
174176
}
@@ -184,7 +186,7 @@ QString QgsSVGFillSymbolLayer::layerType() const
184186

185187
void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
186188
{
187-
if ( mSvgViewBox.isNull() )
189+
if( mSvgViewBox.isNull() )
188190
{
189191
return;
190192
}
@@ -199,13 +201,13 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
199201
//rasterise byte array to image
200202
QPainter p( &textureImage );
201203
QSvgRenderer r( mSvgData );
202-
if ( !r.isValid() )
204+
if( !r.isValid() )
203205
{
204206
return;
205207
}
206208
r.render( &p );
207209

208-
if ( context.alpha() < 1.0 )
210+
if( context.alpha() < 1.0 )
209211
{
210212
QgsSymbolLayerV2Utils::multiplyImageOpacity( &textureImage, context.alpha() );
211213
}
@@ -215,15 +217,15 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
215217
mBrush.setTextureImage( textureImage );
216218
mBrush.setTransform( brushTransform );
217219

218-
if ( mOutline )
220+
if( mOutline )
219221
{
220222
mOutline->startRender( context.renderContext() );
221223
}
222224
}
223225

224226
void QgsSVGFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
225227
{
226-
if ( mOutline )
228+
if( mOutline )
227229
{
228230
mOutline->stopRender( context.renderContext() );
229231
}
@@ -232,27 +234,27 @@ void QgsSVGFillSymbolLayer::stopRender( QgsSymbolV2RenderContext& context )
232234
void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolygonF>* rings, QgsSymbolV2RenderContext& context )
233235
{
234236
QPainter* p = context.renderContext().painter();
235-
if ( !p )
237+
if( !p )
236238
{
237239
return;
238240
}
239241
p->setPen( QPen( Qt::NoPen ) );
240-
if ( context.selected() )
242+
if( context.selected() )
241243
{
242244
QColor selColor = context.selectionColor();
243-
if ( ! selectionIsOpaque ) selColor.setAlphaF( context.alpha() );
245+
if( ! selectionIsOpaque ) selColor.setAlphaF( context.alpha() );
244246
p->setBrush( QBrush( selColor ) );
245247
_renderPolygon( p, points, rings );
246248
}
247249
p->setBrush( mBrush );
248250
_renderPolygon( p, points, rings );
249-
if ( mOutline )
251+
if( mOutline )
250252
{
251253
mOutline->renderPolyline( points, context.renderContext(), -1, selectFillBorder && context.selected() );
252-
if ( rings )
254+
if( rings )
253255
{
254256
QList<QPolygonF>::const_iterator ringIt = rings->constBegin();
255-
for ( ; ringIt != rings->constEnd(); ++ringIt )
257+
for( ; ringIt != rings->constEnd(); ++ringIt )
256258
{
257259
mOutline->renderPolyline( *ringIt, context.renderContext(), -1, selectFillBorder && context.selected() );
258260
}
@@ -263,9 +265,9 @@ void QgsSVGFillSymbolLayer::renderPolygon( const QPolygonF& points, QList<QPolyg
263265
QgsStringMap QgsSVGFillSymbolLayer::properties() const
264266
{
265267
QgsStringMap map;
266-
if ( !mSvgFilePath.isEmpty() )
268+
if( !mSvgFilePath.isEmpty() )
267269
{
268-
map.insert( "svgFile", QgsApplication::absolutePathToRelativePath( mSvgFilePath, QgsApplication::svgPath() ) );
270+
map.insert( "svgFile", QgsSvgMarkerSymbolLayerV2::symbolPathToName( mSvgFilePath ) );
269271
}
270272
else
271273
{
@@ -279,7 +281,7 @@ QgsStringMap QgsSVGFillSymbolLayer::properties() const
279281
QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
280282
{
281283
QgsSymbolLayerV2* clonedLayer = 0;
282-
if ( !mSvgFilePath.isEmpty() )
284+
if( !mSvgFilePath.isEmpty() )
283285
{
284286
clonedLayer = new QgsSVGFillSymbolLayer( mSvgFilePath, mPatternWidth );
285287
}
@@ -288,7 +290,7 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
288290
clonedLayer = new QgsSVGFillSymbolLayer( mSvgData, mPatternWidth );
289291
}
290292

291-
if ( mOutline )
293+
if( mOutline )
292294
{
293295
clonedLayer->setSubSymbol( mOutline->clone() );
294296
}
@@ -297,10 +299,10 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
297299

298300
void QgsSVGFillSymbolLayer::storeViewBox()
299301
{
300-
if ( !mSvgData.isEmpty() )
302+
if( !mSvgData.isEmpty() )
301303
{
302304
QSvgRenderer r( mSvgData );
303-
if ( r.isValid() )
305+
if( r.isValid() )
304306
{
305307
mSvgViewBox = r.viewBoxF();
306308
return;
@@ -313,14 +315,14 @@ void QgsSVGFillSymbolLayer::storeViewBox()
313315

314316
bool QgsSVGFillSymbolLayer::setSubSymbol( QgsSymbolV2* symbol )
315317
{
316-
if ( !symbol || symbol->type() != QgsSymbolV2::Line )
318+
if( !symbol || symbol->type() != QgsSymbolV2::Line )
317319
{
318320
delete symbol;
319321
return false;
320322
}
321323

322324
QgsLineSymbolV2* lineSymbol = dynamic_cast<QgsLineSymbolV2*>( symbol );
323-
if ( lineSymbol )
325+
if( lineSymbol )
324326
{
325327
delete mOutline;
326328
mOutline = lineSymbol;

0 commit comments

Comments
 (0)
Please sign in to comment.