Skip to content

Commit 6afd9f4

Browse files
committedMar 15, 2013
Merge branch 'data_defined_symbology'
2 parents 1e30eb0 + af1bde9 commit 6afd9f4

33 files changed

+1990
-543
lines changed
 

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

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include <QDomDocument>
2424
#include <QDomElement>
2525

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 )
2828
{
2929
mPen.setColor( mOutlineColor );
3030
mPen.setWidth( 1.0 );
@@ -57,10 +57,18 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
5757
{
5858
layer->setSymbolWidth( properties["symbol_width"].toDouble() );
5959
}
60+
if ( properties.contains( "symbol_width_unit" ) )
61+
{
62+
layer->setSymbolWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["symbol_width_unit"] ) );
63+
}
6064
if ( properties.contains( "symbol_height" ) )
6165
{
6266
layer->setSymbolHeight( properties["symbol_height"].toDouble() );
6367
}
68+
if ( properties.contains( "symbol_height_unit" ) )
69+
{
70+
layer->setSymbolHeightUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["symbol_height_unit"] ) );
71+
}
6472
if ( properties.contains( "angle" ) )
6573
{
6674
layer->setAngle( properties["angle"].toDouble() );
@@ -69,6 +77,10 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
6977
{
7078
layer->setOutlineWidth( properties["outline_width"].toDouble() );
7179
}
80+
if ( properties.contains( "outline_width_unit" ) )
81+
{
82+
layer->setOutlineWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["outline_width_unit"] ) );
83+
}
7284
if ( properties.contains( "fill_color" ) )
7385
{
7486
layer->setFillColor( QgsSymbolLayerV2Utils::decodeColor( properties["fill_color"] ) );
@@ -119,7 +131,7 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
119131
{
120132
if ( mOutlineWidthIndex != -1 )
121133
{
122-
double width = context.outputLineWidth( f->attribute( mOutlineWidthIndex ).toDouble() );
134+
double width = f->attribute( mOutlineWidthIndex ).toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit );
123135
mPen.setWidthF( width );
124136
}
125137
if ( mFillColorIndex != -1 )
@@ -179,7 +191,7 @@ void QgsEllipseSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
179191
preparePath( mSymbolName, context );
180192
}
181193
mPen.setColor( mOutlineColor );
182-
mPen.setWidthF( context.outputLineWidth( mOutlineWidth ) );
194+
mPen.setWidthF( mOutlineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit ) );
183195
mBrush.setColor( mFillColor );
184196

185197
//resolve data defined attribute indices
@@ -319,12 +331,15 @@ QgsStringMap QgsEllipseSymbolLayerV2::properties() const
319331
QgsStringMap map;
320332
map["symbol_name"] = mSymbolName;
321333
map["symbol_width"] = QString::number( mSymbolWidth );
334+
map["symbol_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mSymbolWidthUnit );
322335
map["width_field"] = mWidthField;
323336
map["symbol_height"] = QString::number( mSymbolHeight );
337+
map["symbol_height_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mSymbolHeightUnit );
324338
map["height_field"] = mHeightField;
325339
map["angle"] = QString::number( mAngle );
326340
map["rotation_field"] = mRotationField;
327341
map["outline_width"] = QString::number( mOutlineWidth );
342+
map["outline_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOutlineWidthUnit );
328343
map["outline_width_field"] = mOutlineWidthField;
329344
map["fill_color"] = QgsSymbolLayerV2Utils::encodeColor( mFillColor );
330345
map["fill_color_field"] = mFillColorField;
@@ -343,34 +358,35 @@ bool QgsEllipseSymbolLayerV2::hasDataDefinedProperty() const
343358
void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV2RenderContext& context, const QgsFeature* f )
344359
{
345360
mPainterPath = QPainterPath();
361+
const QgsRenderContext& ct = context.renderContext();
346362

347363
double width = 0;
348364

349365
if ( f && mWidthIndex != -1 ) //1. priority: data defined setting on symbol layer level
350366
{
351-
width = context.outputLineWidth( f->attribute( mWidthIndex ).toDouble() );
367+
width = f->attribute( mWidthIndex ).toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolWidthUnit );
352368
}
353369
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
354370
{
355-
width = context.outputLineWidth( mSize );
371+
width = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolWidthUnit );
356372
}
357373
else //3. priority: global width setting
358374
{
359-
width = context.outputLineWidth( mSymbolWidth );
375+
width = mSymbolWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolWidthUnit );
360376
}
361377

362378
double height = 0;
363379
if ( f && mHeightIndex != -1 ) //1. priority: data defined setting on symbol layer level
364380
{
365-
height = context.outputLineWidth( f->attribute( mHeightIndex ).toDouble() );
381+
height = f->attribute( mHeightIndex ).toDouble() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolHeightUnit );
366382
}
367383
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
368384
{
369-
height = context.outputLineWidth( mSize );
385+
height = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolHeightUnit );
370386
}
371387
else //3. priority: global height setting
372388
{
373-
height = context.outputLineWidth( mSymbolHeight );
389+
height = mSymbolHeight * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ct, mSymbolHeightUnit );
374390
}
375391

376392
if ( symbolName == "circle" )
@@ -430,3 +446,20 @@ QSet<QString> QgsEllipseSymbolLayerV2::usedAttributes() const
430446
}
431447
return dataDefinedAttributes;
432448
}
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+
}

‎src/core/symbology-ng/qgsellipsesymbollayerv2.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,28 @@ class CORE_EXPORT QgsEllipseSymbolLayerV2: public QgsMarkerSymbolLayerV2
7979

8080
QSet<QString> usedAttributes() const;
8181

82+
void setSymbolWidthUnit( QgsSymbolV2::OutputUnit unit ) { mSymbolWidthUnit = unit; }
83+
QgsSymbolV2::OutputUnit symbolWidthUnit() const { return mSymbolWidthUnit; }
84+
85+
void setSymbolHeightUnit( QgsSymbolV2::OutputUnit unit ) { mSymbolHeightUnit = unit; }
86+
QgsSymbolV2::OutputUnit symbolHeightUnit() const { return mSymbolHeightUnit; }
87+
88+
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
89+
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
90+
91+
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
92+
QgsSymbolV2::OutputUnit outputUnit() const;
93+
8294
private:
8395
QString mSymbolName;
8496
double mSymbolWidth;
97+
QgsSymbolV2::OutputUnit mSymbolWidthUnit;
8598
double mSymbolHeight;
99+
QgsSymbolV2::OutputUnit mSymbolHeightUnit;
86100
QColor mFillColor;
87101
QColor mOutlineColor;
88102
double mOutlineWidth;
103+
QgsSymbolV2::OutputUnit mOutlineWidthUnit;
89104

90105
#if 0
91106
/**Take width from attribute (-1 if fixed width)*/

1 commit comments

Comments
 (1)

nirvn commented on Mar 19, 2013

@nirvn
Contributor

@mhugent this commit resulted in a regression for line pattern fill, see http://hub.qgis.org/issues/7389

Please sign in to comment.