Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[symbology] Add a semi arc and arrow sign to ellipse markers
  • Loading branch information
nirvn committed Mar 17, 2021
1 parent b3d27aa commit 01f1f0c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
11 changes: 11 additions & 0 deletions python/core/auto_generated/symbology/qgsellipsesymbollayer.sip.in
Expand Up @@ -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 );


Expand Down
28 changes: 26 additions & 2 deletions src/core/symbology/qgsellipsesymbollayer.cpp
Expand Up @@ -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 ) );
}

Expand Down Expand Up @@ -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 );
Expand All @@ -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 )
Expand Down
8 changes: 8 additions & 0 deletions src/core/symbology/qgsellipsesymbollayer.h
Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/gui/symbology/qgsellipsesymbollayerwidget.cpp
Expand Up @@ -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 ) ) );
Expand Down

0 comments on commit 01f1f0c

Please sign in to comment.