Skip to content

Commit b3d11c7

Browse files
committedJun 24, 2015
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. cherry-picked from 81f4e44
1 parent 7c6f01d commit b3d11c7

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed
 

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
8585
if ( !feature.geometry() )
8686
return false;
8787

88+
QgsSymbolV2* symbol = firstSymbolForFeature( mRenderer, feature );
89+
90+
//if the feature has no symbol (eg, no matching rule in a rule-based renderer), skip it
91+
if ( !symbol )
92+
return false;
93+
8894
//point position in screen coords
8995
QgsGeometry* geom = feature.geometry();
9096
QGis::WkbType geomType = geom->wkbType();
@@ -103,7 +109,7 @@ bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
103109
mSpatialIndex->insertFeature( feature );
104110
// create new group
105111
DisplacementGroup newGroup;
106-
newGroup.insert( feature.id(), feature );
112+
newGroup.insert( feature.id(), qMakePair( feature, symbol ) );
107113
mDisplacementGroups.push_back( newGroup );
108114
// add to group index
109115
mGroupIndex.insert( feature.id(), mDisplacementGroups.count() - 1 );
@@ -117,15 +123,15 @@ bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
117123
DisplacementGroup& group = mDisplacementGroups[groupIdx];
118124

119125
// add to a group
120-
group.insert( feature.id(), feature );
126+
group.insert( feature.id(), qMakePair( feature, symbol ) );
121127
// add to group index
122128
mGroupIndex.insert( feature.id(), groupIdx );
123129
return true;
124130
}
125131

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

131137
QPointF pt;
@@ -137,9 +143,8 @@ void QgsPointDisplacementRenderer::drawGroup( const DisplacementGroup& group, Qg
137143

138144
for ( DisplacementGroup::const_iterator attIt = group.constBegin(); attIt != group.constEnd(); ++attIt )
139145
{
140-
labelAttributeList << ( mDrawLabels ? getLabel( attIt.value() ) : QString() );
141-
QgsFeature& f = const_cast<QgsFeature&>( attIt.value() ); // other parts of API use non-const ref to QgsFeature :-/
142-
symbolList << dynamic_cast<QgsMarkerSymbolV2*>( firstSymbolForFeature( mRenderer, f ) );
146+
labelAttributeList << ( mDrawLabels ? getLabel( attIt.value().first ) : QString() );
147+
symbolList << dynamic_cast<QgsMarkerSymbolV2*>( attIt.value().second );
143148
}
144149

145150
//draw symbol
@@ -413,7 +418,7 @@ void QgsPointDisplacementRenderer::printInfoDisplacementGroups()
413418
for ( int i = 0; i < nGroups; ++i )
414419
{
415420
QgsDebugMsg( "***************displacement group " + QString::number( i ) );
416-
QMap<QgsFeatureId, QgsFeature>::const_iterator it = mDisplacementGroups.at( i ).constBegin();
421+
DisplacementGroup::const_iterator it = mDisplacementGroups.at( i ).constBegin();
417422
for ( ; it != mDisplacementGroups.at( i ).constEnd(); ++it )
418423
{
419424
QgsDebugMsg( FID_TO_STRING( it.key() ) );

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

Lines changed: 1 addition & 1 deletion
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)
Please sign in to comment.