Skip to content
Permalink
Browse files

[symbology] Add a semi arc and arrow sign to ellipse markers

  • Loading branch information
nirvn committed Mar 17, 2021
1 parent b3d27aa commit 01f1f0c78abb4eae3f9debfd81a4a778e41e1bd8
@@ -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 );


@@ -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 )
@@ -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 );
@@ -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 ) ) );

0 comments on commit 01f1f0c

Please sign in to comment.