Skip to content

Commit

Permalink
Fix point displacement renderer not ignoring features with no symbol
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nyalldawson committed May 19, 2015
1 parent 27f1d9f commit 81f4e44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions src/core/symbology-ng/qgspointdisplacementrenderer.cpp
Expand Up @@ -87,6 +87,12 @@ bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
if ( !feature.constGeometry() )
return false;

QgsSymbolV2* symbol = firstSymbolForFeature( mRenderer, feature );

//if the feature has no symbol (eg, no matching rule in a rule-based renderer), skip it
if ( !symbol )
return false;

//point position in screen coords
const QgsGeometry* geom = feature.constGeometry();
QGis::WkbType geomType = geom->wkbType();
Expand All @@ -105,7 +111,7 @@ bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
mSpatialIndex->insertFeature( feature );
// create new group
DisplacementGroup newGroup;
newGroup.insert( feature.id(), feature );
newGroup.insert( feature.id(), qMakePair( feature, symbol ) );
mDisplacementGroups.push_back( newGroup );
// add to group index
mGroupIndex.insert( feature.id(), mDisplacementGroups.count() - 1 );
Expand All @@ -119,15 +125,15 @@ bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
DisplacementGroup& group = mDisplacementGroups[groupIdx];

// add to a group
group.insert( feature.id(), feature );
group.insert( feature.id(), qMakePair( feature, symbol ) );
// add to group index
mGroupIndex.insert( feature.id(), groupIdx );
return true;
}

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

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

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

//draw symbol
Expand Down Expand Up @@ -419,7 +424,7 @@ void QgsPointDisplacementRenderer::printInfoDisplacementGroups()
for ( int i = 0; i < nGroups; ++i )
{
QgsDebugMsg( "***************displacement group " + QString::number( i ) );
QMap<QgsFeatureId, QgsFeature>::const_iterator it = mDisplacementGroups.at( i ).constBegin();
DisplacementGroup::const_iterator it = mDisplacementGroups.at( i ).constBegin();
for ( ; it != mDisplacementGroups.at( i ).constEnd(); ++it )
{
QgsDebugMsg( FID_TO_STRING( it.key() ) );
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgspointdisplacementrenderer.h
Expand Up @@ -143,7 +143,7 @@ class CORE_EXPORT QgsPointDisplacementRenderer: public QgsFeatureRendererV2
/**Maximum scale denominator for label display. Negative number means no scale limitation*/
double mMaxLabelScaleDenominator;

typedef QMap<QgsFeatureId, QgsFeature> DisplacementGroup;
typedef QMap<QgsFeatureId, QPair< QgsFeature, QgsSymbolV2* > > DisplacementGroup;
/**Groups of features that have the same position*/
QList<DisplacementGroup> mDisplacementGroups;
/**Mapping from feature ID to its group index*/
Expand Down

0 comments on commit 81f4e44

Please sign in to comment.