@@ -206,6 +206,7 @@ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QString& svgFilePath, double
206206 setSvgFilePath ( svgFilePath );
207207 mOutlineWidth = 0.3 ;
208208 mAngle = angle;
209+ setDefaultSvgParams ();
209210}
210211
211212QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer ( const QByteArray& svgData, double width, double angle ): QgsImageFillSymbolLayer(), mPatternWidth( width ),
@@ -215,6 +216,7 @@ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QByteArray& svgData, double
215216 mOutlineWidth = 0.3 ;
216217 mAngle = angle;
217218 setSubSymbol ( new QgsLineSymbolV2 () );
219+ setDefaultSvgParams ();
218220}
219221
220222QgsSVGFillSymbolLayer::~QgsSVGFillSymbolLayer ()
@@ -228,9 +230,11 @@ void QgsSVGFillSymbolLayer::setSvgFilePath( const QString& svgPath )
228230 if ( svgFile.open ( QFile::ReadOnly ) )
229231 {
230232 mSvgData = svgFile.readAll ();
233+
231234 storeViewBox ();
232235 }
233236 mSvgFilePath = svgPath;
237+ setDefaultSvgParams ();
234238}
235239
236240QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create ( const QgsStringMap& properties )
@@ -240,7 +244,6 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
240244 QString svgFilePath;
241245 double angle = 0.0 ;
242246
243-
244247 if ( properties.contains ( " width" ) )
245248 {
246249 width = properties[" width" ].toDouble ();
@@ -256,19 +259,36 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
256259 angle = properties[" angle" ].toDouble ();
257260 }
258261
262+ QgsSVGFillSymbolLayer* symbolLayer = 0 ;
259263 if ( !svgFilePath.isEmpty () )
260264 {
261- return new QgsSVGFillSymbolLayer ( svgFilePath, width, angle );
265+ symbolLayer = new QgsSVGFillSymbolLayer ( svgFilePath, width, angle );
262266 }
263267 else
264268 {
265269 if ( properties.contains ( " data" ) )
266270 {
267271 data = QByteArray::fromHex ( properties[" data" ].toLocal8Bit () );
268272 }
273+ symbolLayer = new QgsSVGFillSymbolLayer ( data, width, angle );
274+ }
269275
270- return new QgsSVGFillSymbolLayer ( data, width, angle );
276+ // svg parameters
277+ if ( properties.contains ( " svgFillColor" ) )
278+ {
279+ symbolLayer->setSvgFillColor ( QColor ( properties[" svgFillColor" ] ) );
280+ }
281+ if ( properties.contains ( " svgOutlineColor" ) )
282+ {
283+ symbolLayer->setSvgOutlineColor ( QColor ( properties[" svgOutlineColor" ] ) );
284+ }
285+ if ( properties.contains ( " svgOutlineWidth" ) )
286+ {
287+ symbolLayer->setSvgOutlineWidth ( properties[" svgOutlineWidth" ].toDouble () );
271288 }
289+
290+
291+ return symbolLayer;
272292}
273293
274294QString QgsSVGFillSymbolLayer::layerType () const
@@ -283,11 +303,8 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
283303 return ;
284304 }
285305
286- QColor fillColor ( Qt::black );
287- QColor outlineColor ( Qt::black );
288- double outlineWidth = 1 ;
289306 int size = context.outputPixelSize ( mPatternWidth );
290- const QImage& patternImage = QgsSvgCache::instance ()->svgAsImage ( mSvgFilePath , size, fillColor, outlineColor, outlineWidth ,
307+ const QImage& patternImage = QgsSvgCache::instance ()->svgAsImage ( mSvgFilePath , size, mSvgFillColor , mSvgOutlineColor , mSvgOutlineWidth ,
291308 context.renderContext ().scaleFactor (), context.renderContext ().rasterScaleFactor () );
292309 QTransform brushTransform;
293310 brushTransform.scale ( 1.0 / context.renderContext ().rasterScaleFactor (), 1.0 / context.renderContext ().rasterScaleFactor () );
@@ -331,6 +348,12 @@ QgsStringMap QgsSVGFillSymbolLayer::properties() const
331348
332349 map.insert ( " width" , QString::number ( mPatternWidth ) );
333350 map.insert ( " angle" , QString::number ( mAngle ) );
351+
352+ // svg parameters
353+ map.insert ( " svgFillColor" , mSvgFillColor .name () );
354+ map.insert ( " svgOutlineColor" , mSvgOutlineColor .name () );
355+ map.insert ( " svgOutlineWidth" , QString::number ( mSvgOutlineWidth ) );
356+
334357 return map;
335358}
336359
@@ -340,6 +363,10 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
340363 if ( !mSvgFilePath .isEmpty () )
341364 {
342365 clonedLayer = new QgsSVGFillSymbolLayer ( mSvgFilePath , mPatternWidth , mAngle );
366+ QgsSVGFillSymbolLayer* sl = static_cast <QgsSVGFillSymbolLayer*>( clonedLayer );
367+ sl->setSvgFillColor ( mSvgFillColor );
368+ sl->setSvgOutlineColor ( mSvgOutlineColor );
369+ sl->setSvgOutlineWidth ( mSvgOutlineWidth );
343370 }
344371 else
345372 {
@@ -369,6 +396,38 @@ void QgsSVGFillSymbolLayer::storeViewBox()
369396 return ;
370397}
371398
399+ void QgsSVGFillSymbolLayer::setDefaultSvgParams ()
400+ {
401+ // default values
402+ mSvgFillColor = QColor ( 0 , 0 , 0 );
403+ mSvgOutlineColor = QColor ( 0 , 0 , 0 );
404+ mSvgOutlineWidth = 0.3 ;
405+
406+ if ( mSvgFilePath .isEmpty () )
407+ {
408+ return ;
409+ }
410+
411+ bool hasFillParam, hasOutlineParam, hasOutlineWidthParam;
412+ QColor defaultFillColor, defaultOutlineColor;
413+ double defaultOutlineWidth;
414+ QgsSvgCache::instance ()->containsParams ( mSvgFilePath , hasFillParam, defaultFillColor, hasOutlineParam, defaultOutlineColor, hasOutlineWidthParam,
415+ defaultOutlineWidth );
416+
417+ if ( hasFillParam )
418+ {
419+ mSvgFillColor = defaultFillColor;
420+ }
421+ if ( hasOutlineParam )
422+ {
423+ mSvgOutlineColor = defaultOutlineColor;
424+ }
425+ if ( hasOutlineWidthParam )
426+ {
427+ mSvgOutlineWidth = defaultOutlineWidth;
428+ }
429+ }
430+
372431QgsLinePatternFillSymbolLayer::QgsLinePatternFillSymbolLayer (): QgsImageFillSymbolLayer()
373432{
374433}
0 commit comments