Skip to content

Commit

Permalink
Merge pull request #2853 from ahuarte47/Rendering_DrawingMarkersFaster
Browse files Browse the repository at this point in the history
[Improvement] Draw markers faster
  • Loading branch information
m-kuhn committed Mar 2, 2016
2 parents b766ac1 + c0f0bd5 commit 1cdffd3
Showing 1 changed file with 64 additions and 20 deletions.
84 changes: 64 additions & 20 deletions src/core/symbology-ng/qgssymbolv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,9 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, 1 );
}

// Collection of markers to paint
QPolygonF markers;

switch ( QgsWKBTypes::flatType( segmentizedGeometry->geometry()->wkbType() ) )
{
case QgsWKBTypes::Point:
Expand All @@ -760,6 +763,11 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
context.painter()->setBrush( QColor( 255, 0, 0, 100 ) );
context.painter()->drawRect( static_cast<QgsMarkerSymbolV2*>( this )->bounds( pt, context ) );
}

if ( drawVertexMarker )
{
markers << pt;
}
}
break;
case QgsWKBTypes::LineString:
Expand All @@ -772,6 +780,11 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
}
_getLineString( pts, context, QgsConstWkbPtr( segmentizedGeometry->asWkb(), segmentizedGeometry->wkbSize() ), !tileMapRendering && clipFeaturesToExtent() );
static_cast<QgsLineSymbolV2*>( this )->renderPolyline( pts, &feature, context, layer, selected );

if ( drawVertexMarker )
{
markers = pts;
}
}
break;
case QgsWKBTypes::Polygon:
Expand All @@ -785,6 +798,16 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
}
_getPolygon( pts, holes, context, QgsConstWkbPtr( segmentizedGeometry->asWkb(), segmentizedGeometry->wkbSize() ), !tileMapRendering && clipFeaturesToExtent() );
static_cast<QgsFillSymbolV2*>( this )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : nullptr ), &feature, context, layer, selected );

if ( drawVertexMarker )
{
markers = pts;

Q_FOREACH ( const QPolygonF& hole, holes )
{
markers << hole;
}
}
}
break;

Expand All @@ -800,13 +823,23 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co

QgsMultiPointV2* mp = static_cast< QgsMultiPointV2* >( segmentizedGeometry->geometry() );

if ( drawVertexMarker )
{
markers.reserve( mp->numGeometries() );
}

for ( int i = 0; i < mp->numGeometries(); ++i )
{
mSymbolRenderContext->expressionContextScope()->setVariable( QgsExpressionContext::EXPR_GEOMETRY_PART_NUM, i + 1 );

const QgsPointV2* point = static_cast< const QgsPointV2* >( mp->geometryN( i ) );
_getPoint( pt, context, point );
static_cast<QgsMarkerSymbolV2*>( this )->renderPoint( pt, &feature, context, layer, selected );

if ( drawVertexMarker )
{
markers.append( pt );
}
}
}
break;
Expand Down Expand Up @@ -840,6 +873,18 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
}
wkbPtr = _getLineString( pts, context, wkbPtr, !tileMapRendering && clipFeaturesToExtent() );
static_cast<QgsLineSymbolV2*>( this )->renderPolyline( pts, &feature, context, layer, selected );

if ( drawVertexMarker )
{
if ( i == 0 )
{
markers = pts;
}
else
{
markers << pts;
}
}
}
}
break;
Expand Down Expand Up @@ -875,6 +920,23 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co

wkbPtr = _getPolygon( pts, holes, context, wkbPtr, !tileMapRendering && clipFeaturesToExtent() );
static_cast<QgsFillSymbolV2*>( this )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : nullptr ), &feature, context, layer, selected );

if ( drawVertexMarker )
{
if ( i == 0 )
{
markers = pts;
}
else
{
markers << pts;
}

Q_FOREACH ( const QPolygonF& hole, holes )
{
markers << hole;
}
}
}
break;
}
Expand Down Expand Up @@ -903,27 +965,9 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co

if ( drawVertexMarker )
{
const QgsCoordinateTransform* ct = context.coordinateTransform();
const QgsMapToPixel& mtp = context.mapToPixel();

QgsPointV2 vertexPoint;
QgsVertexId vertexId;
double x, y, z;
QPointF mapPoint;
while ( geom->geometry()->nextVertex( vertexId, vertexPoint ) )
Q_FOREACH ( QPointF marker, markers )
{
//transform
x = vertexPoint.x();
y = vertexPoint.y();
z = vertexPoint.z();
if ( ct )
{
ct->transformInPlace( x, y, z );
}
mapPoint.setX( x );
mapPoint.setY( y );
mtp.transformInPlace( mapPoint.rx(), mapPoint.ry() );
QgsVectorLayer::drawVertexMarker( mapPoint.x(), mapPoint.y(), *context.painter(),
QgsVectorLayer::drawVertexMarker( marker.x(), marker.y(), *context.painter(),
static_cast< QgsVectorLayer::VertexMarkerType >( currentVertexMarkerType ),
currentVertexMarkerSize );
}
Expand Down

0 comments on commit 1cdffd3

Please sign in to comment.