Skip to content

Commit

Permalink
Symbol creates geometry instead of the renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 10, 2015
1 parent 29a3c64 commit 68b5209
Show file tree
Hide file tree
Showing 3 changed files with 573 additions and 310 deletions.
195 changes: 1 addition & 194 deletions src/core/symbology-ng/qgsrendererv2.cpp
Expand Up @@ -278,200 +278,7 @@ bool QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext&

void QgsFeatureRendererV2::renderFeatureWithSymbol( QgsFeature& feature, QgsSymbolV2* symbol, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
{
QgsSymbolV2::SymbolType symbolType = symbol->type();


const QgsGeometry* geom = feature.constGeometry();
if ( !geom || !geom->geometry() )
{
return;
}

const QgsGeometry* segmentizedGeometry = geom;
bool deleteSegmentizedGeometry = false;
context.setGeometry( geom->geometry() );

//convert curve types to normal point/line/polygon ones
switch ( QgsWKBTypes::flatType( geom->geometry()->wkbType() ) )
{
case QgsWKBTypes::CurvePolygon:
case QgsWKBTypes::CircularString:
case QgsWKBTypes::CompoundCurve:
case QgsWKBTypes::MultiSurface:
case QgsWKBTypes::MultiCurve:
{
QgsAbstractGeometryV2* g = geom->geometry()->segmentize();
if ( !g )
{
return;
}
segmentizedGeometry = new QgsGeometry( g );
deleteSegmentizedGeometry = true;
break;
}

default:
break;
}

switch ( QgsWKBTypes::flatType( segmentizedGeometry->geometry()->wkbType() ) )
{
case QgsWKBTypes::Point:
{
if ( symbolType != QgsSymbolV2::Marker )
{
QgsDebugMsg( "point can be drawn only with marker symbol!" );
break;
}
QPointF pt;
_getPoint( pt, context, segmentizedGeometry->asWkb() );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
if ( context.testFlag( QgsRenderContext::DrawSymbolBounds ) )
{
//draw debugging rect
context.painter()->setPen( Qt::red );
context.painter()->setBrush( QColor( 255, 0, 0, 100 ) );
context.painter()->drawRect((( QgsMarkerSymbolV2* )symbol )->bounds( pt, context ) );
}
}
break;
case QgsWKBTypes::LineString:
{
if ( symbolType != QgsSymbolV2::Line )
{
QgsDebugMsg( "linestring can be drawn only with line symbol!" );
break;
}
QPolygonF pts;
_getLineString( pts, context, segmentizedGeometry->asWkb(), symbol->clipFeaturesToExtent() );
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
}
break;
case QgsWKBTypes::Polygon:
{
if ( symbolType != QgsSymbolV2::Fill )
{
QgsDebugMsg( "polygon can be drawn only with fill symbol!" );
break;
}
QPolygonF pts;
QList<QPolygonF> holes;
_getPolygon( pts, holes, context, segmentizedGeometry->asWkb(), symbol->clipFeaturesToExtent() );
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : NULL ), &feature, context, layer, selected );
}
break;

case QgsWKBTypes::MultiPoint:
{
if ( symbolType != QgsSymbolV2::Marker )
{
QgsDebugMsg( "multi-point can be drawn only with marker symbol!" );
break;
}

QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
QPointF pt;

for ( unsigned int i = 0; i < num; ++i )
{
ptr = QgsConstWkbPtr( _getPoint( pt, context, ptr ) );
(( QgsMarkerSymbolV2* )symbol )->renderPoint( pt, &feature, context, layer, selected );
}
}
break;

case QgsWKBTypes::MultiCurve:
case QgsWKBTypes::MultiLineString:
{
if ( symbolType != QgsSymbolV2::Line )
{
QgsDebugMsg( "multi-linestring can be drawn only with line symbol!" );
break;
}

QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
QPolygonF pts;

const QgsGeometryCollectionV2* geomCollection = dynamic_cast<const QgsGeometryCollectionV2*>( geom->geometry() );

for ( unsigned int i = 0; i < num; ++i )
{
if ( geomCollection )
{
context.setGeometry( geomCollection->geometryN( i ) );
}
ptr = QgsConstWkbPtr( _getLineString( pts, context, ptr, symbol->clipFeaturesToExtent() ) );
(( QgsLineSymbolV2* )symbol )->renderPolyline( pts, &feature, context, layer, selected );
}
}
break;

case QgsWKBTypes::MultiSurface:
case QgsWKBTypes::MultiPolygon:
{
if ( symbolType != QgsSymbolV2::Fill )
{
QgsDebugMsg( "multi-polygon can be drawn only with fill symbol!" );
break;
}

QgsConstWkbPtr wkbPtr( segmentizedGeometry->asWkb() + 1 + sizeof( int ) );
unsigned int num;
wkbPtr >> num;
const unsigned char* ptr = wkbPtr;
QPolygonF pts;
QList<QPolygonF> holes;

const QgsGeometryCollectionV2* geomCollection = dynamic_cast<const QgsGeometryCollectionV2*>( geom->geometry() );

for ( unsigned int i = 0; i < num; ++i )
{
if ( geomCollection )
{
context.setGeometry( geomCollection->geometryN( i ) );
}
ptr = _getPolygon( pts, holes, context, ptr, symbol->clipFeaturesToExtent() );
(( QgsFillSymbolV2* )symbol )->renderPolygon( pts, ( !holes.isEmpty() ? &holes : NULL ), &feature, context, layer, selected );
}
break;
}
default:
QgsDebugMsg( QString( "feature %1: unsupported wkb type 0x%2 for rendering" ).arg( feature.id() ).arg( geom->wkbType(), 0, 16 ) );
}

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 ) )
{
//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() );
renderVertexMarker( mapPoint, context );
}
}

if ( deleteSegmentizedGeometry )
{
delete segmentizedGeometry;
}
symbol->renderFeature( feature, context, layer, selected, drawVertexMarker, mCurrentVertexMarkerType, mCurrentVertexMarkerSize );
}

QString QgsFeatureRendererV2::dump() const
Expand Down

0 comments on commit 68b5209

Please sign in to comment.