Skip to content

Commit a6f96ba

Browse files
committedJun 16, 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
1 parent 5458d64 commit a6f96ba

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
@@ -157,13 +157,15 @@ void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, Qg
157157

158158
//get list of labels and symbols
159159
QStringList labelAttributeList;
160-
QList<QgsMarkerSymbolV2*> symbolList;
160+
QList< QgsMarkerSymbolV2* > symbolList;
161+
QgsFeatureList featureList;
161162

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

@@ -212,7 +214,7 @@ void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, Qg
212214
}
213215

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

624-
void QgsPointDisplacementRenderer::drawSymbols( const QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected )
626+
void QgsPointDisplacementRenderer::drawSymbols( const QgsFeatureList& features, QgsRenderContext& context,
627+
const QList< QgsMarkerSymbolV2* >& symbolList, const QList<QPointF>& symbolPositions, bool selected )
625628
{
626629
QList<QPointF>::const_iterator symbolPosIt = symbolPositions.constBegin();
627630
QList<QgsMarkerSymbolV2*>::const_iterator symbolIt = symbolList.constBegin();
628-
for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd(); ++symbolPosIt, ++symbolIt )
631+
QgsFeatureList::const_iterator featIt = features.constBegin();
632+
for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd() && featIt != features.constEnd();
633+
++symbolPosIt, ++symbolIt, ++featIt )
629634
{
630635
if ( *symbolIt )
631636
{
632-
( *symbolIt )->renderPoint( *symbolPosIt, &f, context, -1, selected );
637+
context.expressionContext().setFeature( *featIt );
638+
( *symbolIt )->startRender( context );
639+
( *symbolIt )->renderPoint( *symbolPosIt, &( *featIt ), context, -1, selected );
640+
( *symbolIt )->stopRender( context );
633641
}
634642
}
635643
}

‎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.