Skip to content

Commit 81f4e44

Browse files
committed
Fix point displacement renderer not ignoring features with no symbol
Previously, the renderer would incorrectly draw circles and displace features which were proximal to features with no symbols. This caused issues with the rule based renderer, were some features should not be drawn.
1 parent 27f1d9f commit 81f4e44

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/core/symbology-ng/qgspointdisplacementrenderer.cpp

+12-7
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
8787
if ( !feature.constGeometry() )
8888
return false;
8989

90+
QgsSymbolV2* symbol = firstSymbolForFeature( mRenderer, feature );
91+
92+
//if the feature has no symbol (eg, no matching rule in a rule-based renderer), skip it
93+
if ( !symbol )
94+
return false;
95+
9096
//point position in screen coords
9197
const QgsGeometry* geom = feature.constGeometry();
9298
QGis::WkbType geomType = geom->wkbType();
@@ -105,7 +111,7 @@ bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
105111
mSpatialIndex->insertFeature( feature );
106112
// create new group
107113
DisplacementGroup newGroup;
108-
newGroup.insert( feature.id(), feature );
114+
newGroup.insert( feature.id(), qMakePair( feature, symbol ) );
109115
mDisplacementGroups.push_back( newGroup );
110116
// add to group index
111117
mGroupIndex.insert( feature.id(), mDisplacementGroups.count() - 1 );
@@ -119,15 +125,15 @@ bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
119125
DisplacementGroup& group = mDisplacementGroups[groupIdx];
120126

121127
// add to a group
122-
group.insert( feature.id(), feature );
128+
group.insert( feature.id(), qMakePair( feature, symbol ) );
123129
// add to group index
124130
mGroupIndex.insert( feature.id(), groupIdx );
125131
return true;
126132
}
127133

128134
void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, QgsRenderContext& context )
129135
{
130-
const QgsFeature& feature = group.begin().value();
136+
const QgsFeature& feature = group.begin().value().first;
131137
bool selected = mSelectedFeatures.contains( feature.id() ); // maybe we should highlight individual features instead of the whole group?
132138

133139
QPointF pt;
@@ -139,9 +145,8 @@ void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, Qg
139145

140146
for ( DisplacementGroup::const_iterator attIt = group.constBegin(); attIt != group.constEnd(); ++attIt )
141147
{
142-
labelAttributeList << ( mDrawLabels ? getLabel( attIt.value() ) : QString() );
143-
QgsFeature& f = const_cast<QgsFeature&>( attIt.value() ); // other parts of API use non-const ref to QgsFeature :-/
144-
symbolList << dynamic_cast<QgsMarkerSymbolV2*>( firstSymbolForFeature( mRenderer, f ) );
148+
labelAttributeList << ( mDrawLabels ? getLabel( attIt.value().first ) : QString() );
149+
symbolList << dynamic_cast<QgsMarkerSymbolV2*>( attIt.value().second );
145150
}
146151

147152
//draw symbol
@@ -419,7 +424,7 @@ void QgsPointDisplacementRenderer::printInfoDisplacementGroups()
419424
for ( int i = 0; i < nGroups; ++i )
420425
{
421426
QgsDebugMsg( "***************displacement group " + QString::number( i ) );
422-
QMap<QgsFeatureId, QgsFeature>::const_iterator it = mDisplacementGroups.at( i ).constBegin();
427+
DisplacementGroup::const_iterator it = mDisplacementGroups.at( i ).constBegin();
423428
for ( ; it != mDisplacementGroups.at( i ).constEnd(); ++it )
424429
{
425430
QgsDebugMsg( FID_TO_STRING( it.key() ) );

src/core/symbology-ng/qgspointdisplacementrenderer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
143143
/**Maximum scale denominator for label display. Negative number means no scale limitation*/
144144
double mMaxLabelScaleDenominator;
145145

146-
typedef QMap<QgsFeatureId, QgsFeature> DisplacementGroup;
146+
typedef QMap<QgsFeatureId, QPair< QgsFeature, QgsSymbolV2* > > DisplacementGroup;
147147
/**Groups of features that have the same position*/
148148
QList<DisplacementGroup> mDisplacementGroups;
149149
/**Mapping from feature ID to its group index*/

0 commit comments

Comments
 (0)