Skip to content

Commit

Permalink
When DD rotation fails to evaluate, fallback to static value
Browse files Browse the repository at this point in the history
The old behavior was to always fall back to 0 in case of a failing expression. Which made it hard to create a proper legend in some cases.

E.g. if you had two symbol layers with the following expressions for their rotation

    "orientation"

And

    90 + "orientation"

which would be two orthogonal symbol layers (e.g. denote a right angle), rotated by an orientation field.

Now in the legend (and symbol preview), both layers would be shown with a rotation of 0, because there is no associated feature with a field orientation.

The new behavior is to fallback to the static, configured values which makes it very intuitive to configure the legend for these cases.
  • Loading branch information
m-kuhn committed Dec 8, 2019
1 parent fc5c95c commit 348d216
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/core/symbology/qgsmarkersymbollayer.cpp
Expand Up @@ -648,15 +648,17 @@ void QgsSimpleMarkerSymbolLayerBase::calculateOffsetAndRotation( QgsSymbolRender
//angle
bool ok = true;
angle = mAngle + mLineAngle;
bool usingDataDefinedRotation = false;
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyAngle ) )
{
context.setOriginalValueVariable( angle );
angle = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyAngle, context.renderContext().expressionContext(), mAngle, &ok ) + mLineAngle;
usingDataDefinedRotation = ok;

// If the expression evaluation was not successful, fallback to static value
if ( !ok )
angle = mAngle + mLineAngle;
}

hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || usingDataDefinedRotation;
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation;
if ( hasDataDefinedRotation )
{
// For non-point markers, "dataDefinedRotation" means following the
Expand Down Expand Up @@ -3083,15 +3085,17 @@ void QgsFontMarkerSymbolLayer::calculateOffsetAndRotation( QgsSymbolRenderContex
//angle
bool ok = true;
angle = mAngle + mLineAngle;
bool usingDataDefinedRotation = false;
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyAngle ) )
{
context.setOriginalValueVariable( angle );
angle = mDataDefinedProperties.valueAsDouble( QgsSymbolLayer::PropertyAngle, context.renderContext().expressionContext(), mAngle, &ok ) + mLineAngle;
usingDataDefinedRotation = ok;

// If the expression evaluation was not successful, fallback to static value
if ( !ok )
angle = mAngle + mLineAngle;
}

hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation || usingDataDefinedRotation;
hasDataDefinedRotation = context.renderHints() & QgsSymbol::DynamicRotation;
if ( hasDataDefinedRotation )
{
// For non-point markers, "dataDefinedRotation" means following the
Expand Down

0 comments on commit 348d216

Please sign in to comment.