Skip to content

Commit 83af61b

Browse files
committed
More data defined symbology for svg marker symbol layer
1 parent ef35c8b commit 83af61b

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,15 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
10531053
}
10541054

10551055
p->save();
1056-
double offsetX = mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
1057-
double offsetY = mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
1056+
1057+
QPointF offset = mOffset;
1058+
if ( mOffsetExpression )
1059+
{
1060+
QString offsetString = mOffsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
1061+
offset = QgsSymbolLayerV2Utils::decodePoint( offsetString );
1062+
}
1063+
double offsetX = offset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
1064+
double offsetY = offset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
10581065
QPointF outputOffset( offsetX, offsetY );
10591066

10601067
double angle = mAngle;
@@ -1071,13 +1078,40 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
10711078
if ( rotated )
10721079
p->rotate( angle );
10731080

1081+
QString path = mPath;
1082+
if ( mNameExpression )
1083+
{
1084+
path = mNameExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
1085+
}
1086+
1087+
double outlineWidth = mOutlineWidth;
1088+
if ( mOutlineWidthExpression )
1089+
{
1090+
outlineWidth = mOutlineWidthExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toDouble();
1091+
}
1092+
1093+
QColor fillColor = mFillColor;
1094+
if ( mFillExpression )
1095+
{
1096+
QString colorString = mFillExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
1097+
fillColor = QgsSymbolLayerV2Utils::decodeColor( colorString );
1098+
}
1099+
1100+
QColor outlineColor = mOutlineColor;
1101+
if ( mOutlineExpression )
1102+
{
1103+
QString colorString = mOutlineExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
1104+
outlineColor = QgsSymbolLayerV2Utils::decodeColor( colorString );
1105+
}
1106+
1107+
10741108
bool fitsInCache = true;
10751109
bool usePict = true;
10761110
double hwRatio = 1.0;
10771111
if ( drawOnScreen && !rotated )
10781112
{
10791113
usePict = false;
1080-
const QImage& img = QgsSvgCache::instance()->svgAsImage( mPath, size, mFillColor, mOutlineColor, mOutlineWidth,
1114+
const QImage& img = QgsSvgCache::instance()->svgAsImage( path, size, fillColor, outlineColor, outlineWidth,
10811115
context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor(), fitsInCache );
10821116
if ( fitsInCache && img.width() > 1 )
10831117
{
@@ -1100,7 +1134,7 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
11001134
if ( usePict || !fitsInCache )
11011135
{
11021136
p->setOpacity( context.alpha() );
1103-
const QPicture& pct = QgsSvgCache::instance()->svgAsPicture( mPath, size, mFillColor, mOutlineColor, mOutlineWidth,
1137+
const QPicture& pct = QgsSvgCache::instance()->svgAsPicture( path, size, fillColor, outlineColor, outlineWidth,
11041138
context.renderContext().scaleFactor(), context.renderContext().rasterScaleFactor() );
11051139

11061140
if ( pct.width() > 1 )

0 commit comments

Comments
 (0)