@@ -952,6 +952,9 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineInterval( const QPolygonF& points
952
952
QgsRenderContext& rc = context.renderContext ();
953
953
double interval = mInterval ;
954
954
955
+ QgsExpressionContextScope* scope = new QgsExpressionContextScope ();
956
+ context.renderContext ().expressionContext ().appendScope ( scope );
957
+
955
958
if ( hasDataDefinedProperty ( QgsSymbolLayerV2::EXPR_INTERVAL ) )
956
959
{
957
960
context.setOriginalValueVariable ( mInterval );
@@ -971,6 +974,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineInterval( const QPolygonF& points
971
974
double painterUnitInterval = QgsSymbolLayerV2Utils::convertToPainterUnits ( rc, interval, mIntervalUnit , mIntervalMapUnitScale );
972
975
lengthLeft = painterUnitInterval - QgsSymbolLayerV2Utils::convertToPainterUnits ( rc, offsetAlongLine, mIntervalUnit , mIntervalMapUnitScale );
973
976
977
+ int pointNum = 0 ;
974
978
for ( int i = 1 ; i < points.count (); ++i )
975
979
{
976
980
const QPointF& pt = points[i];
@@ -1001,12 +1005,15 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineInterval( const QPolygonF& points
1001
1005
// "c" is 1 for regular point or in interval (0,1] for begin of line segment
1002
1006
lastPt += c * diff;
1003
1007
lengthLeft -= painterUnitInterval;
1008
+ scope->setVariable ( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, ++pointNum );
1004
1009
mMarker ->renderPoint ( lastPt, context.feature (), rc, -1 , context.selected () );
1005
1010
c = 1 ; // reset c (if wasn't 1 already)
1006
1011
}
1007
1012
1008
1013
lastPt = pt;
1009
1014
}
1015
+
1016
+ delete context.renderContext ().expressionContext ().popScope ();
1010
1017
}
1011
1018
1012
1019
static double _averageAngle ( QPointF prevPt, QPointF pt, QPointF nextPt )
@@ -1030,6 +1037,10 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points,
1030
1037
int i, maxCount;
1031
1038
bool isRing = false ;
1032
1039
1040
+ QgsExpressionContextScope* scope = new QgsExpressionContextScope ();
1041
+ context.renderContext ().expressionContext ().appendScope ( scope );
1042
+ scope->setVariable ( QgsExpressionContext::EXPR_GEOMETRY_POINT_COUNT, points.size () );
1043
+
1033
1044
double offsetAlongLine = mOffsetAlongLine ;
1034
1045
if ( hasDataDefinedProperty ( QgsSymbolLayerV2::EXPR_OFFSET_ALONG_LINE ) )
1035
1046
{
@@ -1052,8 +1063,11 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points,
1052
1063
QgsPointV2 vPoint;
1053
1064
double x, y, z;
1054
1065
QPointF mapPoint;
1066
+ int pointNum = 0 ;
1055
1067
while ( context.renderContext ().geometry ()->nextVertex ( vId, vPoint ) )
1056
1068
{
1069
+ scope->setVariable ( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, ++pointNum );
1070
+
1057
1071
if (( placement == Vertex && vId.type == QgsVertexId::SegmentVertex )
1058
1072
|| ( placement == CurvePoint && vId.type == QgsVertexId::CurveVertex ) )
1059
1073
{
@@ -1075,6 +1089,8 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points,
1075
1089
mMarker ->renderPoint ( mapPoint, context.feature (), rc, -1 , context.selected () );
1076
1090
}
1077
1091
}
1092
+
1093
+ delete context.renderContext ().expressionContext ().popScope ();
1078
1094
return ;
1079
1095
}
1080
1096
@@ -1097,6 +1113,7 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points,
1097
1113
}
1098
1114
else
1099
1115
{
1116
+ delete context.renderContext ().expressionContext ().popScope ();
1100
1117
return ;
1101
1118
}
1102
1119
@@ -1107,11 +1124,16 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points,
1107
1124
renderOffsetVertexAlongLine ( points, i, distance, context );
1108
1125
// restore original rotation
1109
1126
mMarker ->setAngle ( origAngle );
1127
+
1128
+ delete context.renderContext ().expressionContext ().popScope ();
1110
1129
return ;
1111
1130
}
1112
1131
1132
+ int pointNum = 0 ;
1113
1133
for ( ; i < maxCount; ++i )
1114
1134
{
1135
+ scope->setVariable ( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, ++pointNum );
1136
+
1115
1137
if ( isRing && placement == Vertex && i == points.count () - 1 )
1116
1138
{
1117
1139
continue ; // don't draw the last marker - it has been drawn already
@@ -1128,6 +1150,8 @@ void QgsMarkerLineSymbolLayerV2::renderPolylineVertex( const QPolygonF& points,
1128
1150
1129
1151
// restore original rotation
1130
1152
mMarker ->setAngle ( origAngle );
1153
+
1154
+ delete context.renderContext ().expressionContext ().popScope ();
1131
1155
}
1132
1156
1133
1157
double QgsMarkerLineSymbolLayerV2::markerAngle ( const QPolygonF& points, bool isRing, int vertex )
0 commit comments