@@ -140,7 +140,9 @@ void QgsPointDistanceRenderer::drawGroup( const ClusteredGroup& group, QgsRender
140
140
QgsGeometry centroid = groupGeom.centroid ();
141
141
QPointF pt = _getPoint ( context, *static_cast <QgsPointV2*>( centroid.geometry () ) );
142
142
143
+ context.expressionContext ().appendScope ( createGroupScope ( group ) );
143
144
drawGroup ( pt, context, group );
145
+ delete context.expressionContext ().popScope ();
144
146
}
145
147
146
148
void QgsPointDistanceRenderer::setEmbeddedRenderer ( QgsFeatureRenderer* r )
@@ -407,6 +409,48 @@ void QgsPointDistanceRenderer::drawLabels( QPointF centerPoint, QgsSymbolRenderC
407
409
}
408
410
}
409
411
412
+ QgsExpressionContextScope* QgsPointDistanceRenderer::createGroupScope ( const ClusteredGroup& group ) const
413
+ {
414
+ QgsExpressionContextScope* clusterScope = new QgsExpressionContextScope ();
415
+ if ( group.size () > 1 )
416
+ {
417
+ // scan through symbols to check color, eg if all clustered symbols are same color
418
+ QColor groupColor;
419
+ ClusteredGroup::const_iterator groupIt = group.constBegin ();
420
+ for ( ; groupIt != group.constEnd (); ++groupIt )
421
+ {
422
+ if ( !groupIt->symbol )
423
+ continue ;
424
+
425
+ if ( !groupColor.isValid () )
426
+ {
427
+ groupColor = groupIt->symbol ->color ();
428
+ }
429
+ else
430
+ {
431
+ if ( groupColor != groupIt->symbol ->color () )
432
+ {
433
+ groupColor = QColor ();
434
+ break ;
435
+ }
436
+ }
437
+ }
438
+
439
+ if ( groupColor.isValid () )
440
+ {
441
+ clusterScope->setVariable ( " cluster_color" , QgsSymbolLayerUtils::encodeColor ( groupColor ) );
442
+ }
443
+ else
444
+ {
445
+ // mixed colors
446
+ clusterScope->setVariable ( " cluster_color" , " " );
447
+ }
448
+
449
+ clusterScope->setVariable ( " cluster_size" , group.size () );
450
+ }
451
+ return clusterScope;
452
+ }
453
+
410
454
QgsMarkerSymbol* QgsPointDistanceRenderer::firstSymbolForFeature ( QgsFeature& feature, QgsRenderContext &context )
411
455
{
412
456
if ( !mRenderer )
0 commit comments