From 01f1f0c78abb4eae3f9debfd81a4a778e41e1bd8 Mon Sep 17 00:00:00 2001 From: nirvn Date: Wed, 17 Mar 2021 15:18:08 +0700 Subject: [PATCH] [symbology] Add a semi arc and arrow sign to ellipse markers --- .../symbology/qgsellipsesymbollayer.sip.in | 11 ++++++++ src/core/symbology/qgsellipsesymbollayer.cpp | 28 +++++++++++++++++-- src/core/symbology/qgsellipsesymbollayer.h | 8 ++++++ .../symbology/qgsellipsesymbollayerwidget.cpp | 2 +- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/python/core/auto_generated/symbology/qgsellipsesymbollayer.sip.in b/python/core/auto_generated/symbology/qgsellipsesymbollayer.sip.in index bf5b79062865..ea8092620595 100644 --- a/python/core/auto_generated/symbology/qgsellipsesymbollayer.sip.in +++ b/python/core/auto_generated/symbology/qgsellipsesymbollayer.sip.in @@ -51,6 +51,17 @@ Creates the symbol layer void setSymbolName( const QString &name ); QString symbolName() const; + bool shapeIsFilled( const QString &symbolName ) const; +%Docstring +Returns ``True`` if a shape has a fill. + +:param symbolName: name of shape to test + +:return: ``True`` if shape uses a fill, or ``False`` if shape uses lines only + +.. versionadded:: 3.20 +%End + virtual void setSize( double size ); diff --git a/src/core/symbology/qgsellipsesymbollayer.cpp b/src/core/symbology/qgsellipsesymbollayer.cpp index 357f87054e80..7f699512f953 100644 --- a/src/core/symbology/qgsellipsesymbollayer.cpp +++ b/src/core/symbology/qgsellipsesymbollayer.cpp @@ -280,8 +280,16 @@ void QgsEllipseSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext & transform.rotate( angle ); } - p->setPen( context.selected() ? mSelPen : mPen ); - p->setBrush( context.selected() ? mSelBrush : mBrush ); + if ( shapeIsFilled( mSymbolName ) ) + { + p->setPen( context.selected() ? mSelPen : mPen ); + p->setBrush( context.selected() ? mSelBrush : mBrush ); + } + else + { + p->setPen( context.selected() ? mSelPen : mPen ); + p->setBrush( QBrush() ); + } p->drawPath( transform.map( mPainterPath ) ); } @@ -627,6 +635,17 @@ void QgsEllipseSymbolLayer::preparePath( const QString &symbolName, QgsSymbolRen mPainterPath.moveTo( -size.width() / 2.0, 0 ); mPainterPath.lineTo( size.width() / 2.0, 0 ); } + else if ( symbolName == QLatin1String( "arrow" ) ) + { + mPainterPath.moveTo( -size.width() / 2.0, size.height() / 2.0 ); + mPainterPath.lineTo( 0, -size.height() / 2.0 ); + mPainterPath.lineTo( size.width() / 2.0, size.height() / 2.0 ); + } + else if ( symbolName == QLatin1String( "semi_arc" ) ) + { + mPainterPath.moveTo( size.width() / 2.0, 0 ); + mPainterPath.arcTo( -size.width() / 2.0, -size.height() / 2.0, size.width(), size.height(), 0, 180 ); + } else if ( symbolName == QLatin1String( "triangle" ) ) { mPainterPath.moveTo( 0, -size.height() / 2.0 ); @@ -650,6 +669,11 @@ void QgsEllipseSymbolLayer::preparePath( const QString &symbolName, QgsSymbolRen } } +bool QgsEllipseSymbolLayer::shapeIsFilled( const QString &symbolName ) const +{ + return symbolName == QLatin1String( "cross" ) || symbolName == QLatin1String( "arrow" ) || symbolName == QLatin1String( "semi_arc" ) ? false : true; +} + void QgsEllipseSymbolLayer::setSize( double size ) { if ( mSymbolWidth >= mSymbolHeight ) diff --git a/src/core/symbology/qgsellipsesymbollayer.h b/src/core/symbology/qgsellipsesymbollayer.h index da4ce933eea1..9a8f93305dea 100644 --- a/src/core/symbology/qgsellipsesymbollayer.h +++ b/src/core/symbology/qgsellipsesymbollayer.h @@ -52,6 +52,14 @@ class CORE_EXPORT QgsEllipseSymbolLayer: public QgsMarkerSymbolLayer void setSymbolName( const QString &name ) { mSymbolName = name; } QString symbolName() const { return mSymbolName; } + /** + * Returns TRUE if a shape has a fill. + * \param symbolName name of shape to test + * \returns TRUE if shape uses a fill, or FALSE if shape uses lines only + * \since QGIS 3.20 + */ + bool shapeIsFilled( const QString &symbolName ) const; + void setSize( double size ) override; void setSymbolWidth( double w ); diff --git a/src/gui/symbology/qgsellipsesymbollayerwidget.cpp b/src/gui/symbology/qgsellipsesymbollayerwidget.cpp index 9a549854c45a..a49908a2fd98 100644 --- a/src/gui/symbology/qgsellipsesymbollayerwidget.cpp +++ b/src/gui/symbology/qgsellipsesymbollayerwidget.cpp @@ -66,7 +66,7 @@ QgsEllipseSymbolLayerWidget::QgsEllipseSymbolLayerWidget( QgsVectorLayer *vl, QW mRotationSpinBox->setClearValue( 0.0 ); QStringList names; - names << QStringLiteral( "circle" ) << QStringLiteral( "rectangle" ) << QStringLiteral( "diamond" ) << QStringLiteral( "cross" ) << QStringLiteral( "triangle" ) << QStringLiteral( "right_half_triangle" ) << QStringLiteral( "left_half_triangle" ) << QStringLiteral( "semi_circle" ); + names << QStringLiteral( "circle" ) << QStringLiteral( "rectangle" ) << QStringLiteral( "diamond" ) << QStringLiteral( "cross" ) << QStringLiteral( "arrow" ) << QStringLiteral( "semi_arc" ) << QStringLiteral( "triangle" ) << QStringLiteral( "right_half_triangle" ) << QStringLiteral( "left_half_triangle" ) << QStringLiteral( "semi_circle" ); int size = mShapeListWidget->iconSize().width(); size = std::max( 30, static_cast< int >( std::round( Qgis::UI_SCALE_FACTOR * fontMetrics().horizontalAdvance( 'X' ) * 3 ) ) );