Skip to content

Commit

Permalink
Fix displacement symbols with data defined properties (fix #9601)
Browse files Browse the repository at this point in the history
Previously only the attributes of the first feature were being
used to render the points inside a group

(cherry-picked from a6f96ba)
  • Loading branch information
nyalldawson committed Jul 1, 2016
1 parent 2872495 commit c33b7ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions src/core/symbology-ng/qgspointdisplacementrenderer.cpp
Expand Up @@ -156,13 +156,15 @@ void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, Qg

//get list of labels and symbols
QStringList labelAttributeList;
QList<QgsMarkerSymbolV2*> symbolList;
QList< QgsMarkerSymbolV2* > symbolList;
QgsFeatureList featureList;

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

Expand Down Expand Up @@ -210,7 +212,7 @@ void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, Qg
}

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

void QgsPointDisplacementRenderer::drawSymbols( const QgsFeature& f, QgsRenderContext& context, const QList<QgsMarkerSymbolV2*>& symbolList, const QList<QPointF>& symbolPositions, bool selected )
void QgsPointDisplacementRenderer::drawSymbols( const QgsFeatureList& features, QgsRenderContext& context,
const QList< QgsMarkerSymbolV2* >& symbolList, const QList<QPointF>& symbolPositions, bool selected )
{
QList<QPointF>::const_iterator symbolPosIt = symbolPositions.constBegin();
QList<QgsMarkerSymbolV2*>::const_iterator symbolIt = symbolList.constBegin();
for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd(); ++symbolPosIt, ++symbolIt )
QgsFeatureList::const_iterator featIt = features.constBegin();
for ( ; symbolPosIt != symbolPositions.constEnd() && symbolIt != symbolList.constEnd() && featIt != features.constEnd();
++symbolPosIt, ++symbolIt, ++featIt )
{
if ( *symbolIt )
{
( *symbolIt )->renderPoint( *symbolPosIt, &f, context, -1, selected );
context.expressionContext().setFeature( *featIt );
( *symbolIt )->startRender( context );
( *symbolIt )->renderPoint( *symbolPosIt, &( *featIt ), context, -1, selected );
( *symbolIt )->stopRender( context );
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgspointdisplacementrenderer.h
Expand Up @@ -235,7 +235,7 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
QMap<QgsFeatureId, int> mGroupIndex;
/** Spatial index for fast lookup of close points*/
QgsSpatialIndex* mSpatialIndex;
/** Keeps trask which features are selected */
/** Keeps track which features are selected */
QSet<QgsFeatureId> mSelectedFeatures;

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

0 comments on commit c33b7ad

Please sign in to comment.