Skip to content
Permalink
Browse files

Change point displacement renderer to work with new vector api

  • Loading branch information
mhugent committed Apr 10, 2013
1 parent fca5ee5 commit 212aea7c445d57e95b57c3754c44f11fda84c882
Showing with 25 additions and 12 deletions.
  1. +3 −5 src/core/qgsvectorlayer.cpp
  2. +2 −2 src/core/qgsvectorlayer.h
  3. +20 −5 src/core/symbology-ng/qgspointdisplacementrenderer.cpp
@@ -370,8 +370,6 @@ void QgsVectorLayer::drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext&
QSettings settings;
bool vertexMarkerOnlyForSelection = settings.value( "/qgis/digitizing/marker_only_for_selected", false ).toBool();

mRendererV2->startRender( rendererContext, this );

#ifndef Q_WS_MAC
int featureCount = 0;
#endif //Q_WS_MAC
@@ -465,9 +463,6 @@ void QgsVectorLayer::drawRendererV2Levels( QgsFeatureIterator &fit, QgsRenderCon
QSettings settings;
bool vertexMarkerOnlyForSelection = settings.value( "/qgis/digitizing/marker_only_for_selected", false ).toBool();

// startRender must be called before symbolForFeature() calls to make sure renderer is ready
mRendererV2->startRender( rendererContext, this );

QgsSingleSymbolRendererV2* selRenderer = NULL;
if ( !mSelectedFeatureIds.isEmpty() )
{
@@ -653,6 +648,9 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
//register label and diagram layer to the labeling engine
prepareLabelingAndDiagrams( rendererContext, attributes, labeling );

//do startRender before getFeatures to give renderers the possibility of querying features in the startRender method
mRendererV2->startRender( rendererContext, this );

QgsFeatureIterator fit = getFeatures( QgsFeatureRequest()
.setFilterRect( rendererContext.extent() )
.setSubsetOfAttributes( attributes ) );
@@ -347,12 +347,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
void setRendererV2( QgsFeatureRendererV2* r );

/** Draw layer with renderer V2.
/** Draw layer with renderer V2. QgsFeatureRenderer::startRender() needs to be called before using this method
* @note added in 1.4
*/
void drawRendererV2( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling );

/** Draw layer with renderer V2 using symbol levels.
/** Draw layer with renderer V2 using symbol levels. QgsFeatureRenderer::startRender() needs to be called before using this method
* @note added in 1.4
*/
void drawRendererV2Levels( QgsFeatureIterator &fit, QgsRenderContext& rendererContext, bool labeling );
@@ -364,6 +364,9 @@ void QgsPointDisplacementRenderer::createDisplacementGroups( QgsVectorLayer* vla
QgsFeature f;
QList<QgsFeatureId> intersectList;

//Because the new vector api does not allow querying features by id within a nextFeature loop, default constructed QgsFeature() is
//inserted first and the real features are created in a second loop

QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( viewExtent ).setSubsetOfAttributes( attList ) );
while ( fit.nextFeature( f ) )
{
@@ -389,7 +392,7 @@ void QgsPointDisplacementRenderer::createDisplacementGroups( QgsVectorLayer* vla
{
found = true;
QgsFeature feature;
it->insert( f.id(), f );
it->insert( f.id(), QgsFeature() );
mDisplacementIds.insert( f.id() );
break;
}
@@ -398,17 +401,29 @@ void QgsPointDisplacementRenderer::createDisplacementGroups( QgsVectorLayer* vla
if ( !found )//insert the already existing feature and the new one into a map
{
QMap<QgsFeatureId, QgsFeature> newMap;
QgsFeature existingFeature;
vlayer->getFeatures( QgsFeatureRequest().setFilterFid( existingEntry ) ).nextFeature( existingFeature );
newMap.insert( existingEntry, existingFeature );
newMap.insert( existingEntry, QgsFeature() );
mDisplacementIds.insert( existingEntry );
newMap.insert( f.id(), f );
newMap.insert( f.id(), QgsFeature() );
mDisplacementIds.insert( f.id() );
mDisplacementGroups.push_back( newMap );
}
}
}
}

//insert the real features into mDisplacementGroups
QList< QMap<QgsFeatureId, QgsFeature> >::iterator it = mDisplacementGroups.begin();
for ( ; it != mDisplacementGroups.end(); ++it )
{
QMap<QgsFeatureId, QgsFeature>::iterator mapIt = it->begin();
for ( ; mapIt != it->end(); ++mapIt )
{
QgsFeature fet;
vlayer->getFeatures( QgsFeatureRequest().setFilterFid( mapIt.key() ) ).nextFeature( fet );
mapIt.value() = fet;
}
}

}

QgsRectangle QgsPointDisplacementRenderer::searchRect( const QgsPoint& p ) const

0 comments on commit 212aea7

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