Skip to content
Permalink
Browse files

Fix ellipse symbol layer doesn't reflect feature selection state

Fixes #37893
  • Loading branch information
nyalldawson committed Jul 22, 2020
1 parent c8c0dcd commit ee4797973d2044ff0adc64b5f00b850e281864b0
@@ -183,6 +183,7 @@ void QgsEllipseSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext &
{
width = context.renderContext().convertToPainterUnits( width, mStrokeWidthUnit, mStrokeWidthMapUnitScale );
mPen.setWidthF( width );
mSelPen.setWidthF( width );
}
}

@@ -191,13 +192,15 @@ void QgsEllipseSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext &
if ( exprVal.isValid() )
{
mPen.setStyle( QgsSymbolLayerUtils::decodePenStyle( exprVal.toString() ) );
mSelPen.setStyle( mPen.style() );
}

context.setOriginalValueVariable( QgsSymbolLayerUtils::encodePenJoinStyle( mPenJoinStyle ) );
exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyJoinStyle, context.renderContext().expressionContext() );
if ( exprVal.isValid() )
{
mPen.setJoinStyle( QgsSymbolLayerUtils::decodePenJoinStyle( exprVal.toString() ) );
mSelPen.setJoinStyle( mPen.joinStyle() );
}

context.setOriginalValueVariable( QgsSymbolLayerUtils::encodeColor( mColor ) );
@@ -238,8 +241,8 @@ void QgsEllipseSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext &
transform.rotate( angle );
}

p->setPen( mPen );
p->setBrush( mBrush );
p->setPen( context.selected() ? mSelPen : mPen );
p->setBrush( context.selected() ? mSelBrush : mBrush );
p->drawPath( transform.map( mPainterPath ) );
}

@@ -308,6 +311,18 @@ void QgsEllipseSymbolLayer::startRender( QgsSymbolRenderContext &context )
mPen.setJoinStyle( mPenJoinStyle );
mPen.setWidthF( context.renderContext().convertToPainterUnits( mStrokeWidth, mStrokeWidthUnit, mStrokeWidthMapUnitScale ) );
mBrush.setColor( mColor );

QColor selBrushColor = context.renderContext().selectionColor();
QColor selPenColor = selBrushColor == mColor ? selBrushColor : mStrokeColor;
if ( context.opacity() < 1 && !SELECTION_IS_OPAQUE )
{
selBrushColor.setAlphaF( context.opacity() );
selPenColor.setAlphaF( context.opacity() );
}
mSelBrush = QBrush( selBrushColor );
mSelPen = QPen( selPenColor );
mSelPen.setStyle( mStrokeStyle );
mSelPen.setWidthF( context.renderContext().convertToPainterUnits( mStrokeWidth, mStrokeWidthUnit, mStrokeWidthMapUnitScale ) );
}

void QgsEllipseSymbolLayer::stopRender( QgsSymbolRenderContext & )
@@ -159,6 +159,10 @@ class CORE_EXPORT QgsEllipseSymbolLayer: public QgsMarkerSymbolLayer

QPen mPen;
QBrush mBrush;
//! QPen to use as stroke of selected symbols
QPen mSelPen;
//! QBrush to use as fill of selected symbols
QBrush mSelBrush;

/**
* Setup mPainterPath
@@ -58,6 +58,7 @@ class TestQgsEllipseMarkerSymbol : public QObject
void ellipseMarkerSymbolBevelJoin();
void ellipseMarkerSymbolMiterJoin();
void ellipseMarkerSymbolRoundJoin();
void selected();
void bounds();

private:
@@ -195,6 +196,22 @@ void TestQgsEllipseMarkerSymbol::ellipseMarkerSymbolRoundJoin()
QVERIFY( imageCheck( "ellipsemarker_roundjoin" ) );
}

void TestQgsEllipseMarkerSymbol::selected()
{
mEllipseMarkerLayer->setFillColor( Qt::blue );
mEllipseMarkerLayer->setStrokeColor( Qt::black );
mEllipseMarkerLayer->setSymbolName( QStringLiteral( "triangle" ) );
mEllipseMarkerLayer->setSymbolHeight( 25 );
mEllipseMarkerLayer->setSymbolWidth( 20 );
mEllipseMarkerLayer->setStrokeWidth( 3 );
mEllipseMarkerLayer->setPenJoinStyle( Qt::RoundJoin );

mpPointsLayer->selectAll();
const bool res = imageCheck( "ellipsemarker_selected" );
mpPointsLayer->removeSelection();
QVERIFY( res );
}

void TestQgsEllipseMarkerSymbol::bounds()
{
mEllipseMarkerLayer->setFillColor( Qt::blue );
Binary file not shown.

0 comments on commit ee47979

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