23
23
#include < QDomDocument>
24
24
#include < QDomElement>
25
25
26
- QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2 (): mSymbolName( " circle" ), mSymbolWidth( 4 ), mSymbolHeight( 3 ),
27
- mFillColor( Qt::black ), mOutlineColor( Qt::white ), mOutlineWidth( 0 )
26
+ QgsEllipseSymbolLayerV2::QgsEllipseSymbolLayerV2 (): mSymbolName( " circle" ), mSymbolWidth( 4 ), mSymbolWidthUnit( QgsSymbolV2::MM ), mSymbolHeight( 3 ),
27
+ mSymbolHeightUnit( QgsSymbolV2::MM ), mFillColor( Qt::black ), mOutlineColor( Qt::white ), mOutlineWidth( 0 ), mOutlineWidthUnit( QgsSymbolV2::MM )
28
28
{
29
29
mPen .setColor ( mOutlineColor );
30
30
mPen .setWidth ( 1.0 );
@@ -57,10 +57,18 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
57
57
{
58
58
layer->setSymbolWidth ( properties[" symbol_width" ].toDouble () );
59
59
}
60
+ if ( properties.contains ( " symbol_width_unit" ) )
61
+ {
62
+ layer->setSymbolWidthUnit ( QgsSymbolLayerV2Utils::decodeOutputUnit ( properties[" symbol_width_unit" ] ) );
63
+ }
60
64
if ( properties.contains ( " symbol_height" ) )
61
65
{
62
66
layer->setSymbolHeight ( properties[" symbol_height" ].toDouble () );
63
67
}
68
+ if ( properties.contains ( " symbol_height_unit" ) )
69
+ {
70
+ layer->setSymbolHeightUnit ( QgsSymbolLayerV2Utils::decodeOutputUnit ( properties[" symbol_height_unit" ] ) );
71
+ }
64
72
if ( properties.contains ( " angle" ) )
65
73
{
66
74
layer->setAngle ( properties[" angle" ].toDouble () );
@@ -69,6 +77,10 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
69
77
{
70
78
layer->setOutlineWidth ( properties[" outline_width" ].toDouble () );
71
79
}
80
+ if ( properties.contains ( " outline_width_unit" ) )
81
+ {
82
+ layer->setOutlineWidthUnit ( QgsSymbolLayerV2Utils::decodeOutputUnit ( properties[" outline_width_unit" ] ) );
83
+ }
72
84
if ( properties.contains ( " fill_color" ) )
73
85
{
74
86
layer->setFillColor ( QgsSymbolLayerV2Utils::decodeColor ( properties[" fill_color" ] ) );
@@ -119,7 +131,7 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
119
131
{
120
132
if ( mOutlineWidthIndex != -1 )
121
133
{
122
- double width = context. outputLineWidth ( f->attribute ( mOutlineWidthIndex ).toDouble () );
134
+ double width = f->attribute ( mOutlineWidthIndex ).toDouble () * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context. renderContext (), mOutlineWidthUnit );
123
135
mPen .setWidthF ( width );
124
136
}
125
137
if ( mFillColorIndex != -1 )
@@ -179,7 +191,7 @@ void QgsEllipseSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
179
191
preparePath ( mSymbolName , context );
180
192
}
181
193
mPen .setColor ( mOutlineColor );
182
- mPen .setWidthF ( context.outputLineWidth ( mOutlineWidth ) );
194
+ mPen .setWidthF ( mOutlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( context.renderContext (), mOutlineWidthUnit ) );
183
195
mBrush .setColor ( mFillColor );
184
196
185
197
// resolve data defined attribute indices
@@ -319,12 +331,15 @@ QgsStringMap QgsEllipseSymbolLayerV2::properties() const
319
331
QgsStringMap map;
320
332
map[" symbol_name" ] = mSymbolName ;
321
333
map[" symbol_width" ] = QString::number ( mSymbolWidth );
334
+ map[" symbol_width_unit" ] = QgsSymbolLayerV2Utils::encodeOutputUnit ( mSymbolWidthUnit );
322
335
map[" width_field" ] = mWidthField ;
323
336
map[" symbol_height" ] = QString::number ( mSymbolHeight );
337
+ map[" symbol_height_unit" ] = QgsSymbolLayerV2Utils::encodeOutputUnit ( mSymbolHeightUnit );
324
338
map[" height_field" ] = mHeightField ;
325
339
map[" angle" ] = QString::number ( mAngle );
326
340
map[" rotation_field" ] = mRotationField ;
327
341
map[" outline_width" ] = QString::number ( mOutlineWidth );
342
+ map[" outline_width_unit" ] = QgsSymbolLayerV2Utils::encodeOutputUnit ( mOutlineWidthUnit );
328
343
map[" outline_width_field" ] = mOutlineWidthField ;
329
344
map[" fill_color" ] = QgsSymbolLayerV2Utils::encodeColor ( mFillColor );
330
345
map[" fill_color_field" ] = mFillColorField ;
@@ -343,34 +358,35 @@ bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty() const
343
358
void QgsEllipseSymbolLayerV2::preparePath ( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f )
344
359
{
345
360
mPainterPath = QPainterPath ();
361
+ const QgsRenderContext& ct = context.renderContext ();
346
362
347
363
double width = 0 ;
348
364
349
365
if ( f && mWidthIndex != -1 ) // 1. priority: data defined setting on symbol layer level
350
366
{
351
- width = context. outputLineWidth ( f->attribute ( mWidthIndex ).toDouble () );
367
+ width = f->attribute ( mWidthIndex ).toDouble () * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( ct, mSymbolWidthUnit );
352
368
}
353
369
else if ( context.renderHints () & QgsSymbolV2::DataDefinedSizeScale ) // 2. priority: is data defined size on symbol level
354
370
{
355
- width = context. outputLineWidth ( mSize );
371
+ width = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( ct, mSymbolWidthUnit );
356
372
}
357
373
else // 3. priority: global width setting
358
374
{
359
- width = context. outputLineWidth ( mSymbolWidth );
375
+ width = mSymbolWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( ct, mSymbolWidthUnit );
360
376
}
361
377
362
378
double height = 0 ;
363
379
if ( f && mHeightIndex != -1 ) // 1. priority: data defined setting on symbol layer level
364
380
{
365
- height = context. outputLineWidth ( f->attribute ( mHeightIndex ).toDouble () );
381
+ height = f->attribute ( mHeightIndex ).toDouble () * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( ct, mSymbolHeightUnit );
366
382
}
367
383
else if ( context.renderHints () & QgsSymbolV2::DataDefinedSizeScale ) // 2. priority: is data defined size on symbol level
368
384
{
369
- height = context. outputLineWidth ( mSize );
385
+ height = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( ct, mSymbolHeightUnit );
370
386
}
371
387
else // 3. priority: global height setting
372
388
{
373
- height = context. outputLineWidth ( mSymbolHeight );
389
+ height = mSymbolHeight * QgsSymbolLayerV2Utils::lineWidthScaleFactor ( ct, mSymbolHeightUnit );
374
390
}
375
391
376
392
if ( symbolName == " circle" )
@@ -430,3 +446,20 @@ QSet<QString> QgsEllipseSymbolLayerV2::usedAttributes() const
430
446
}
431
447
return dataDefinedAttributes;
432
448
}
449
+
450
+ void QgsEllipseSymbolLayerV2::setOutputUnit ( QgsSymbolV2::OutputUnit unit )
451
+ {
452
+ mSymbolWidthUnit = unit;
453
+ mSymbolHeightUnit = unit;
454
+ mOutlineWidthUnit = unit;
455
+ }
456
+
457
+ QgsSymbolV2::OutputUnit QgsEllipseSymbolLayerV2::outputUnit () const
458
+ {
459
+ QgsSymbolV2::OutputUnit unit = mSymbolWidthUnit ;
460
+ if ( mSymbolHeightUnit != unit || mOutlineWidthUnit != unit )
461
+ {
462
+ return QgsSymbolV2::Mixed;
463
+ }
464
+ return unit;
465
+ }
1 commit comments
nirvn commentedon Mar 19, 2013
@mhugent this commit resulted in a regression for line pattern fill, see http://hub.qgis.org/issues/7389