@@ -206,6 +206,7 @@ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QString& svgFilePath, double
206
206
setSvgFilePath ( svgFilePath );
207
207
mOutlineWidth = 0.3 ;
208
208
mAngle = angle;
209
+ setDefaultSvgParams ();
209
210
}
210
211
211
212
QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer ( const QByteArray& svgData, double width, double angle ): QgsImageFillSymbolLayer(), mPatternWidth( width ),
@@ -215,6 +216,7 @@ QgsSVGFillSymbolLayer::QgsSVGFillSymbolLayer( const QByteArray& svgData, double
215
216
mOutlineWidth = 0.3 ;
216
217
mAngle = angle;
217
218
setSubSymbol ( new QgsLineSymbolV2 () );
219
+ setDefaultSvgParams ();
218
220
}
219
221
220
222
QgsSVGFillSymbolLayer::~QgsSVGFillSymbolLayer ()
@@ -228,9 +230,11 @@ void QgsSVGFillSymbolLayer::setSvgFilePath( const QString& svgPath )
228
230
if ( svgFile.open ( QFile::ReadOnly ) )
229
231
{
230
232
mSvgData = svgFile.readAll ();
233
+
231
234
storeViewBox ();
232
235
}
233
236
mSvgFilePath = svgPath;
237
+ setDefaultSvgParams ();
234
238
}
235
239
236
240
QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create ( const QgsStringMap& properties )
@@ -240,7 +244,6 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
240
244
QString svgFilePath;
241
245
double angle = 0.0 ;
242
246
243
-
244
247
if ( properties.contains ( " width" ) )
245
248
{
246
249
width = properties[" width" ].toDouble ();
@@ -256,19 +259,36 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::create( const QgsStringMap& properties
256
259
angle = properties[" angle" ].toDouble ();
257
260
}
258
261
262
+ QgsSVGFillSymbolLayer* symbolLayer = 0 ;
259
263
if ( !svgFilePath.isEmpty () )
260
264
{
261
- return new QgsSVGFillSymbolLayer ( svgFilePath, width, angle );
265
+ symbolLayer = new QgsSVGFillSymbolLayer ( svgFilePath, width, angle );
262
266
}
263
267
else
264
268
{
265
269
if ( properties.contains ( " data" ) )
266
270
{
267
271
data = QByteArray::fromHex ( properties[" data" ].toLocal8Bit () );
268
272
}
273
+ symbolLayer = new QgsSVGFillSymbolLayer ( data, width, angle );
274
+ }
269
275
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 () );
271
288
}
289
+
290
+
291
+ return symbolLayer;
272
292
}
273
293
274
294
QString QgsSVGFillSymbolLayer::layerType () const
@@ -283,11 +303,8 @@ void QgsSVGFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
283
303
return ;
284
304
}
285
305
286
- QColor fillColor ( Qt::black );
287
- QColor outlineColor ( Qt::black );
288
- double outlineWidth = 1 ;
289
306
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 ,
291
308
context.renderContext ().scaleFactor (), context.renderContext ().rasterScaleFactor () );
292
309
QTransform brushTransform;
293
310
brushTransform.scale ( 1.0 / context.renderContext ().rasterScaleFactor (), 1.0 / context.renderContext ().rasterScaleFactor () );
@@ -331,6 +348,12 @@ QgsStringMap QgsSVGFillSymbolLayer::properties() const
331
348
332
349
map.insert ( " width" , QString::number ( mPatternWidth ) );
333
350
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
+
334
357
return map;
335
358
}
336
359
@@ -340,6 +363,10 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::clone() const
340
363
if ( !mSvgFilePath .isEmpty () )
341
364
{
342
365
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 );
343
370
}
344
371
else
345
372
{
@@ -369,6 +396,38 @@ void QgsSVGFillSymbolLayer::storeViewBox()
369
396
return ;
370
397
}
371
398
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
+
372
431
QgsLinePatternFillSymbolLayer::QgsLinePatternFillSymbolLayer (): QgsImageFillSymbolLayer()
373
432
{
374
433
}
0 commit comments