Skip to content
Permalink
Browse files

Address review

  • Loading branch information
nirvn committed May 4, 2021
1 parent 672d53e commit 65ba35921a66c8194ff260c84929f6d1f377d47d
@@ -150,7 +150,7 @@ the background settings.

.. note::

This is only used when the :py:func:`~QgsTextBackgroundSettings.type` is QgsTextBackgroundSettings.ShapeRectangle .
This is only used when the :py:func:`~QgsTextBackgroundSettings.type` is QgsTextBackgroundSettings.ShapeRectangle,
QgsTextBackgroundSettings.ShapeSquare, QgsTextBackgroundSettings.ShapeCircle or
QgsTextBackgroundSettings.ShapeEllipse

@@ -166,7 +166,7 @@ to the background settings.

.. note::

This is only used when the :py:func:`~QgsTextBackgroundSettings.type` is QgsTextBackgroundSettings.ShapeRectangle .
This is only used when the :py:func:`~QgsTextBackgroundSettings.type` is QgsTextBackgroundSettings.ShapeRectangle,
QgsTextBackgroundSettings.ShapeSquare, QgsTextBackgroundSettings.ShapeCircle or
QgsTextBackgroundSettings.ShapeEllipse

@@ -677,12 +677,6 @@ Updates the format by evaluating current values of data defined properties.
.. versionadded:: 3.10
%End

void upgradeDataDefinedProperties( QgsPropertyCollection &properties );
%Docstring
Upgrade data defined properties when reading a project file saved in QGIS prior to version 3.20.

.. versionadded:: 3.20
%End

QSet<QString> referencedFields( const QgsRenderContext &context ) const;
%Docstring
@@ -304,7 +304,7 @@ void QgsTextBackgroundSettings::setFillColor( const QColor &color )
d->fillColor = color;
if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QStringLiteral( "SimpleFill" ) )
{
static_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setColor( color );
qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setColor( color );
}
}

@@ -318,7 +318,7 @@ void QgsTextBackgroundSettings::setStrokeColor( const QColor &color )
d->strokeColor = color;
if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QStringLiteral( "SimpleFill" ) )
{
static_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeColor( color );
qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeColor( color );
}
}

@@ -332,7 +332,7 @@ void QgsTextBackgroundSettings::setStrokeWidth( double width )
d->strokeWidth = width;
if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QStringLiteral( "SimpleFill" ) )
{
QgsSimpleFillSymbolLayer *fill = static_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) );
QgsSimpleFillSymbolLayer *fill = qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) );
fill->setStrokeWidth( width );
fill->setStrokeStyle( !qgsDoubleNear( width, 0.0 ) ? Qt::SolidLine : Qt::NoPen );
}
@@ -348,7 +348,7 @@ void QgsTextBackgroundSettings::setStrokeWidthUnit( QgsUnitTypes::RenderUnit uni
d->strokeWidthUnits = units;
if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QStringLiteral( "SimpleFill" ) )
{
static_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeWidthUnit( units );
qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeWidthUnit( units );
}
}

@@ -362,7 +362,7 @@ void QgsTextBackgroundSettings::setStrokeWidthMapUnitScale( const QgsMapUnitScal
d->strokeWidthMapUnitScale = scale;
if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QStringLiteral( "SimpleFill" ) )
{
static_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeWidthMapUnitScale( scale );
qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setStrokeWidthMapUnitScale( scale );
}
}

@@ -376,7 +376,7 @@ void QgsTextBackgroundSettings::setJoinStyle( Qt::PenJoinStyle style )
d->joinStyle = style;
if ( d->fillSymbol && d->fillSymbol->symbolLayers().at( 0 )->layerType() == QStringLiteral( "SimpleFill" ) )
{
static_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setPenJoinStyle( style );
qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) )->setPenJoinStyle( style );
}
}

@@ -722,7 +722,7 @@ void QgsTextBackgroundSettings::upgradeDataDefinedProperties( QgsPropertyCollect
{
if ( !d->fillSymbol || d->fillSymbol->symbolLayers().at( 0 )->layerType() != QStringLiteral( "SimpleFill" ) )
return;
QgsSimpleFillSymbolLayer *fill = static_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) );
QgsSimpleFillSymbolLayer *fill = qgis::down_cast< QgsSimpleFillSymbolLayer * >( d->fillSymbol->symbolLayers().at( 0 ) );

if ( d->type != QgsTextBackgroundSettings::ShapeSVG )
{
@@ -156,7 +156,7 @@ class CORE_EXPORT QgsTextBackgroundSettings
/**
* Returns the fill symbol to be rendered in the background. Ownership remains with
* the background settings.
* \note This is only used when the type() is QgsTextBackgroundSettings::ShapeRectangle .
* \note This is only used when the type() is QgsTextBackgroundSettings::ShapeRectangle,
* QgsTextBackgroundSettings::ShapeSquare, QgsTextBackgroundSettings::ShapeCircle or
* QgsTextBackgroundSettings::ShapeEllipse
* \see setFillSymbol()
@@ -167,7 +167,7 @@ class CORE_EXPORT QgsTextBackgroundSettings
/**
* Sets the current fill \a symbol for the background shape. Ownership is transferred
* to the background settings.
* \note This is only used when the type() is QgsTextBackgroundSettings::ShapeRectangle .
* \note This is only used when the type() is QgsTextBackgroundSettings::ShapeRectangle,
* QgsTextBackgroundSettings::ShapeSquare, QgsTextBackgroundSettings::ShapeCircle or
* QgsTextBackgroundSettings::ShapeEllipse
* \see fillSymbol()
@@ -555,7 +555,7 @@ class CORE_EXPORT QgsTextBackgroundSettings
* Upgrade data defined properties when reading a project file saved in QGIS prior to version 3.20.
* \since QGIS 3.20
*/
void upgradeDataDefinedProperties( QgsPropertyCollection &properties );
void upgradeDataDefinedProperties( QgsPropertyCollection &properties ) SIP_SKIP;

/**
* Returns all field names referenced by the configuration (e.g. from data defined properties).
@@ -920,7 +920,7 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer
renderedSymbol->setSizeUnit( QgsUnitTypes::RenderPixels );
}

renderedSymbol->setOpacity( background.opacity() );
renderedSymbol->setOpacity( renderedSymbol->opacity() * background.opacity() );

// draw the actual symbol
QgsScopedQPainterState painterState( p );
@@ -1009,6 +1009,13 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer
p->rotate( component.rotationOffset );

QPainterPath path;

// Paths with curves must be enlarged before conversion to QPolygonF, or
// the curves are approximated too much and appear jaggy
QTransform t = QTransform::fromScale( 10, 10 );
// inverse transform used to scale created polygons back to expected size
QTransform ti = t.inverted();

if ( background.type() == QgsTextBackgroundSettings::ShapeRectangle
|| background.type() == QgsTextBackgroundSettings::ShapeSquare )
{
@@ -1018,8 +1025,8 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer
}
else
{
double xRadius = context.convertToPainterUnits( background.radii().width(), background.radiiUnit(), background.radiiMapUnitScale() );
double yRadius = context.convertToPainterUnits( background.radii().height(), background.radiiUnit(), background.radiiMapUnitScale() );
const double xRadius = context.convertToPainterUnits( background.radii().width(), background.radiiUnit(), background.radiiMapUnitScale() );
const double yRadius = context.convertToPainterUnits( background.radii().height(), background.radiiUnit(), background.radiiMapUnitScale() );
path.addRoundedRect( rect, xRadius, yRadius );
}
}
@@ -1028,7 +1035,8 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer
{
path.addEllipse( rect );
}
QPolygonF polygon = path.toFillPolygon();
QPolygonF tempPolygon = path.toFillPolygon( t );
QPolygonF polygon = ti.map( tempPolygon );
QPicture shapePict;
QPainter *oldp = context.painter();
QPainter shapep;
@@ -1038,7 +1046,7 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer

std::unique_ptr< QgsFillSymbol > renderedSymbol;
renderedSymbol.reset( background.fillSymbol()->clone() );
renderedSymbol->setOpacity( background.opacity() );
renderedSymbol->setOpacity( renderedSymbol->opacity() * background.opacity() );

const QgsFeature f = context.expressionContext().feature();
renderedSymbol->startRender( context, context.expressionContext().fields() );
@@ -1051,7 +1059,7 @@ void QgsTextRenderer::drawBackground( QgsRenderContext &context, QgsTextRenderer
if ( format.shadow().enabled() && format.shadow().shadowPlacement() == QgsTextShadowSettings::ShadowShape )
{
component.picture = shapePict;
component.pictureBuffer = 2.0; // arbitrary
component.pictureBuffer = QgsSymbolLayerUtils::estimateMaxSymbolBleed( renderedSymbol.get(), context ) * 2;

component.size = rect.size();
component.offset = QPointF( rect.width() / 2, -rect.height() / 2 );
Binary file not shown.

0 comments on commit 65ba359

Please sign in to comment.