Skip to content

Commit c33b7ad

Browse files
committedJul 1, 2016
Fix displacement symbols with data defined properties (fix #9601)
Previously only the attributes of the first feature were being used to render the points inside a group (cherry-picked from a6f96ba)
1 parent 2872495 commit c33b7ad

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed
 

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, Qg
156156

157157
//get list of labels and symbols
158158
QStringList labelAttributeList;
159-
QList<QgsMarkerSymbolV2*> symbolList;
159+
QList< QgsMarkerSymbolV2* > symbolList;
160+
QgsFeatureList featureList;
160161

161162
QgsMultiPointV2* groupMultiPoint = new QgsMultiPointV2();
162163
for ( DisplacementGroup::const_iterator attIt = group.constBegin(); attIt != group.constEnd(); ++attIt )
163164
{
164165
labelAttributeList << ( mDrawLabels ? getLabel( attIt.value().first ) : QString() );
165166
symbolList << dynamic_cast<QgsMarkerSymbolV2*>( attIt.value().second );
167+
featureList << attIt.value().first;
166168
groupMultiPoint->addGeometry( attIt.value().first.constGeometry()->geometry()->clone() );
167169
}
168170

@@ -210,7 +212,7 @@ void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, Qg
210212
}
211213

212214
//draw symbols on the circle
213-
drawSymbols( feature, context, symbolList, symbolPositions, selected );
215+
drawSymbols( featureList, context, symbolList, symbolPositions, selected );
214216
//and also the labels
215217
drawLabels( pt, symbolContext, labelPositions, labelAttributeList );
216218
}
@@ -619,15 +621,21 @@ void QgsPointDisplacementRenderer::drawCircle( double radiusPainterUnits, QgsSym
619621
p->drawArc( QRectF( centerPoint.x() - radiusPainterUnits, centerPoint.y() - radiusPainterUnits, 2 * radiusPainterUnits, 2 * radiusPainterUnits ), 0, 5760 );
620622
}
621623

622-
void QgsPointDisplacementRenderer::drawSymbols( const QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected )
624+
void QgsPointDisplacementRenderer::drawSymbols( const QgsFeatureList& features, QgsRenderContext& context,
625+
const QList< QgsMarkerSymbolV2* >& symbolList, const QList<QPointF>& symbolPositions, bool selected )
623626
{
624627
QList<QPointF>::const_iterator symbolPosIt = symbolPositions.constBegin();
625628
QList<QgsMarkerSymbolV2*>::const_iterator symbolIt = symbolList.constBegin();
626-
for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd(); ++symbolPosIt, ++symbolIt )
629+
QgsFeatureList::const_iterator featIt = features.constBegin();
630+
for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd() && featIt != features.constEnd();
631+
++symbolPosIt, ++symbolIt, ++featIt )
627632
{
628633
if ( *symbolIt )
629634
{
630-
( *symbolIt )->renderPoint( *symbolPosIt, &f, context, -1, selected );
635+
context.expressionContext().setFeature( *featIt );
636+
( *symbolIt )->startRender( context );
637+
( *symbolIt )->renderPoint( *symbolPosIt, &( *featIt ), context, -1, selected );
638+
( *symbolIt )->stopRender( context );
631639
}
632640
}
633641
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
235235
QMap<QgsFeatureId, int> mGroupIndex;
236236
/** Spatial index for fast lookup of close points*/
237237
QgsSpatialIndex* mSpatialIndex;
238-
/** Keeps trask which features are selected */
238+
/** Keeps track which features are selected */
239239
QSet<QgsFeatureId> mSelectedFeatures;
240240

241241
/** Creates a search rectangle with specified distance tolerance */
@@ -254,7 +254,7 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
254254
void calculateSymbolAndLabelPositions( QgsSymbolV2RenderContext &symbolContext, QPointF centerPoint, int nPosition, double symbolDiagonal, QList<QPointF>& symbolPositions, QList<QPointF>& labelShifts , double &circleRadius ) const;
255255
void drawGroup( const DisplacementGroup& group, QgsRenderContext& context );
256256
void drawCircle( double radiusPainterUnits, QgsSymbolV2RenderContext& context, QPointF centerPoint, int nSymbols );
257-
void drawSymbols( const QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
257+
void drawSymbols( const QgsFeatureList& features, QgsRenderContext& context, const QList< QgsMarkerSymbolV2* >& symbolList, const QList<QPointF>& symbolPositions, bool selected = false );
258258
void drawLabels( QPointF centerPoint, QgsSymbolV2RenderContext& context, const QList<QPointF>& labelShifts, const QStringList& labelList );
259259
/** Returns first symbol for feature or 0 if none*/
260260
QgsSymbolV2* firstSymbolForFeature( QgsFeatureRendererV2* r, QgsFeature& f, QgsRenderContext& context );

0 commit comments

Comments
 (0)
Please sign in to comment.