Skip to content
Permalink
Browse files

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
  • Loading branch information
nyalldawson committed May 19, 2015
1 parent 7c6f01d commit b3d11c75c0a4af007b9b3feb342bc792f9fc6e03
@@ -85,6 +85,12 @@ bool QgsPointDisplacementRenderer::renderFeature( QgsFeature& feature, QgsRender
if ( !feature.geometry() )
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
QgsGeometry* geom = feature.geometry();
QGis::WkbType geomType = geom->wkbType();
@@ -103,7 +109,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 );
@@ -117,15 +123,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;
@@ -137,9 +143,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
@@ -413,7 +418,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() ) );
@@ -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*/

0 comments on commit b3d11c7

Please sign in to comment.
You can’t perform that action at this time.