Skip to content

Commit

Permalink
Fix ellipse symbol layer doesn't reflect feature selection state
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Jul 22, 2020
1 parent b37158a commit 4bfd9a3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/core/symbology/qgsellipsesymbollayer.cpp
Expand Up @@ -183,6 +183,7 @@ void QgsEllipseSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext &
{
width = context.renderContext().convertToPainterUnits( width, mStrokeWidthUnit, mStrokeWidthMapUnitScale );
mPen.setWidthF( width );
mSelPen.setWidthF( width );
}
}

Expand All @@ -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 ) );
Expand Down Expand Up @@ -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 ) );
}

Expand Down Expand Up @@ -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 & )
Expand Down
4 changes: 4 additions & 0 deletions src/core/symbology/qgsellipsesymbollayer.h
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/src/core/testqgsellipsemarker.cpp
Expand Up @@ -58,6 +58,7 @@ class TestQgsEllipseMarkerSymbol : public QObject
void ellipseMarkerSymbolBevelJoin();
void ellipseMarkerSymbolMiterJoin();
void ellipseMarkerSymbolRoundJoin();
void selected();
void bounds();

private:
Expand Down Expand Up @@ -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 );
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4bfd9a3

Please sign in to comment.