Skip to content

Commit

Permalink
Draw vertices of unsegmentized geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed May 23, 2016
1 parent d2b2189 commit 71712ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 66 deletions.
91 changes: 25 additions & 66 deletions src/core/symbology-ng/qgssymbolv2.cpp
Expand Up @@ -744,9 +744,6 @@ 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 @@ -769,11 +766,6 @@ 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, feature ) );
}

if ( drawVertexMarker )
{
markers << pt;
}
}
break;
case QgsWKBTypes::LineString:
Expand All @@ -786,11 +778,6 @@ 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 @@ -804,16 +791,6 @@ 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 @@ -829,11 +806,6 @@ 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->setGeometryPartNum( i + 1 );
Expand All @@ -842,11 +814,6 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co
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 @@ -881,18 +848,6 @@ 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 @@ -929,23 +884,6 @@ 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 @@ -974,11 +912,27 @@ void QgsSymbolV2::renderFeature( const QgsFeature& feature, QgsRenderContext& co

if ( drawVertexMarker )
{
Q_FOREACH ( QPointF marker, markers )
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 ) )
{
QgsVectorLayer::drawVertexMarker( marker.x(), marker.y(), *context.painter(),
static_cast< QgsVectorLayer::VertexMarkerType >( currentVertexMarkerType ),
currentVertexMarkerSize );
//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, currentVertexMarkerType, currentVertexMarkerSize );
}
}

Expand All @@ -996,6 +950,11 @@ QgsSymbolV2RenderContext* QgsSymbolV2::symbolRenderContext()
return mSymbolRenderContext;
}

void QgsSymbolV2::renderVertexMarker( QPointF& pt, QgsRenderContext& context, int currentVertexMarkerType, int currentVertexMarkerSize )
{
QgsVectorLayer::drawVertexMarker( pt.x(), pt.y(), *context.painter(), static_cast< QgsVectorLayer::VertexMarkerType >( currentVertexMarkerType ), currentVertexMarkerSize );
}

////////////////////


Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgssymbolv2.h
Expand Up @@ -315,6 +315,9 @@ class CORE_EXPORT QgsSymbolV2
//! @deprecated since 2.14, use QgsSymbolLayerV2::isCompatibleWithSymbol instead
Q_DECL_DEPRECATED bool isSymbolLayerCompatible( SymbolType layerType );

//! render editing vertex marker at specified point
void renderVertexMarker( QPointF& pt, QgsRenderContext& context, int currentVertexMarkerType, int currentVertexMarkerSize );

SymbolType mType;
QgsSymbolLayerV2List mLayers;

Expand Down

5 comments on commit 71712ac

@ahuarte47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mhugent, about this change, the "_getLineString" and "_getPolygon" methods return the simplified point array of the original geometry. It will be faster use them to paint the markers. Sorry, what is the reason about this change? Can I restore the original code?

Kind regards
Alvaro

@mhugent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, what is the reason about this change? Can I restore the original code?

The reason is that we see the real vertices for curved geometries (not the segmented vertices). Please don't restore the original code. It is important to see the correct geometry vertices for editing (where the markers are shown).

@ahuarte47
Copy link
Contributor

@ahuarte47 ahuarte47 commented on 71712ac May 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks, I see it. I would like to propose this pull ( #3155 ). Do you agree?

@mhugent
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, looks good to me.

@ahuarte47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, thanks @mhugent

Please sign in to comment.