Skip to content
Permalink
Browse files
Fix data defined properties which bind to a field can have incorrect
values when the linked field has a null value
  • Loading branch information
nyalldawson committed Jun 7, 2021
1 parent a690609 commit 4e25c6bcf413c8d93a09839696dbc93ae0e55f64
@@ -1300,7 +1300,7 @@ void QgsDxfExport::writeText( const QString &layer, const QString &text, pal::La
if ( props.isActive( QgsPalLayerSettings::OffsetQuad ) )
{
const QVariant exprVal = props.value( QgsPalLayerSettings::OffsetQuad, expressionContext );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
offsetQuad = static_cast<QgsPalLayerSettings::QuadrantPosition>( exprVal.toInt() );
}
@@ -1358,7 +1358,7 @@ void QgsDxfExport::writeText( const QString &layer, const QString &text, pal::La

hali = HAlign::HLeft;
QVariant exprVal = props.value( QgsPalLayerSettings::Hali, expressionContext );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
const QString haliString = exprVal.toString();
if ( haliString.compare( QLatin1String( "Center" ), Qt::CaseInsensitive ) == 0 )
@@ -1377,7 +1377,7 @@ void QgsDxfExport::writeText( const QString &layer, const QString &text, pal::La
{
vali = VAlign::VBottom;
QVariant exprVal = props.value( QgsPalLayerSettings::Vali, expressionContext );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
const QString valiString = exprVal.toString();
if ( valiString.compare( QLatin1String( "Bottom" ), Qt::CaseInsensitive ) != 0 )
@@ -34,7 +34,7 @@ void QgsLabelObstacleSettings::updateDataDefinedProperties( const QgsPropertyCol
{
context.setOriginalValueVariable( mObstacleFactor );
QVariant exprVal = properties.value( QgsPalLayerSettings::ObstacleFactor, context );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
bool ok;
double factorD = exprVal.toDouble( &ok );
@@ -1776,7 +1776,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
// data defined font units?
QgsUnitTypes::RenderUnit fontunits = mFormat.sizeUnit();
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::FontSizeUnit, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString units = exprVal.toString();
if ( !units.isEmpty() )
@@ -1885,7 +1885,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::FontCase ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::FontCase, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString fcase = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal FontCase:%1" ).arg( fcase ), 4 );
@@ -1990,7 +1990,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::CentroidWhole ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::CentroidWhole, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString str = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal CentroidWhole:%1" ).arg( str ), 4 );
@@ -2051,7 +2051,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::PolygonLabelOutside ) )
{
const QVariant dataDefinedOutside = mDataDefinedProperties.value( QgsPalLayerSettings::PolygonLabelOutside, context.expressionContext() );
if ( dataDefinedOutside.isValid() )
if ( !dataDefinedOutside.isNull() )
{
if ( dataDefinedOutside.type() == QVariant::String )
{
@@ -2215,7 +2215,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
{
context.expressionContext().setOriginalValueVariable( static_cast< int >( quadOff ) );
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::OffsetQuad, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
bool ok;
int quadInt = exprVal.toInt( &ok );
@@ -2287,7 +2287,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::OffsetUnits ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::OffsetUnits, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString units = exprVal.toString().trimmed();
if ( !units.isEmpty() )
@@ -2322,7 +2322,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
{
context.expressionContext().setOriginalValueVariable( angleOffset );
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::LabelRotation, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
bool ok;
double rotD = exprVal.toDouble( &ok );
@@ -2340,15 +2340,15 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionX ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::PositionX, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
if ( !exprVal.isNull() )
xPos = exprVal.toDouble( &ddXPos );

if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::PositionY ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::PositionY, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
//data defined position. But field values could be NULL -> positions will be generated by PAL
if ( !exprVal.isNull() )
@@ -2367,7 +2367,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::Hali ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::Hali, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString haliString = exprVal.toString();
if ( haliString.compare( QLatin1String( "Center" ), Qt::CaseInsensitive ) == 0 )
@@ -2385,7 +2385,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::Vali ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::Vali, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString valiString = exprVal.toString();
if ( valiString.compare( QLatin1String( "Bottom" ), Qt::CaseInsensitive ) != 0 )
@@ -2474,7 +2474,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::RepeatDistanceUnit ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::RepeatDistanceUnit, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString units = exprVal.toString().trimmed();
if ( !units.isEmpty() )
@@ -2606,7 +2606,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::DistanceUnits ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::DistanceUnits, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString units = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal DistanceUnits:%1" ).arg( units ), 4 );
@@ -2669,7 +2669,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
{
context.expressionContext().setOriginalValueVariable( priority );
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::Priority, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
bool ok;
double priorityD = exprVal.toDouble( &ok );
@@ -2777,7 +2777,7 @@ bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,

context.setOriginalValueVariable( originalValue );
exprVal = mDataDefinedProperties.value( p, context );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
switch ( valType )
{
@@ -2965,7 +2965,7 @@ void QgsPalLayerSettings::parseTextStyle( QFont &labelFont,
{
context.expressionContext().setOriginalValueVariable( labelFont.family() );
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::Family, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString family = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal Font family:%1" ).arg( family ), 4 );
@@ -2987,7 +2987,7 @@ void QgsPalLayerSettings::parseTextStyle( QFont &labelFont,
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::FontStyle ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::FontStyle, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString fontstyle = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal Font style:%1" ).arg( fontstyle ), 4 );
@@ -3258,7 +3258,7 @@ void QgsPalLayerSettings::parseTextFormatting( QgsRenderContext &context )
{
context.expressionContext().setOriginalValueVariable( mFormat.lineHeight() );
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::MultiLineAlignment, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString str = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal MultiLineAlignment:%1" ).arg( str ), 4 );
@@ -3295,7 +3295,7 @@ void QgsPalLayerSettings::parseTextFormatting( QgsRenderContext &context )
const QString encoded = QgsTextRendererUtils::encodeTextOrientation( mFormat.orientation() );
context.expressionContext().setOriginalValueVariable( encoded );
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::TextOrientation, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString str = exprVal.toString().trimmed();
if ( !str.isEmpty() )
@@ -3320,7 +3320,7 @@ void QgsPalLayerSettings::parseTextFormatting( QgsRenderContext &context )

// data defined direction symbol placement?
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::DirSymbPlacement, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString str = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal DirSymbPlacement:%1" ).arg( str ), 4 );
@@ -3388,7 +3388,7 @@ void QgsPalLayerSettings::parseShapeBackground( QgsRenderContext &context )
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::ShapeKind ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::ShapeKind, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString skind = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal ShapeKind:%1" ).arg( skind ), 4 );
@@ -3407,7 +3407,7 @@ void QgsPalLayerSettings::parseShapeBackground( QgsRenderContext &context )
{
context.expressionContext().setOriginalValueVariable( svgPath );
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::ShapeSVGFile, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString svgfile = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal ShapeSVGFile:%1" ).arg( svgfile ), 4 );
@@ -3423,7 +3423,7 @@ void QgsPalLayerSettings::parseShapeBackground( QgsRenderContext &context )
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::ShapeSizeType ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::ShapeSizeType, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString stype = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal ShapeSizeType:%1" ).arg( stype ), 4 );
@@ -3494,7 +3494,7 @@ void QgsPalLayerSettings::parseShapeBackground( QgsRenderContext &context )
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::ShapeRotationType ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::ShapeRotationType, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString rotstr = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal ShapeRotationType:%1" ).arg( rotstr ), 4 );
@@ -3597,7 +3597,7 @@ void QgsPalLayerSettings::parseDropShadow( QgsRenderContext &context )
if ( mDataDefinedProperties.isActive( QgsPalLayerSettings::ShadowUnder ) )
{
exprVal = mDataDefinedProperties.value( QgsPalLayerSettings::ShadowUnder, context.expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
QString str = exprVal.toString().trimmed();
QgsDebugMsgLevel( QStringLiteral( "exprVal ShadowUnder:%1" ).arg( str ), 4 );
@@ -630,40 +630,52 @@ void QgsArrowSymbolLayer::_resolveDataDefined( QgsSymbolRenderContext &context )
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyArrowWidth ) )
{
exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyArrowWidth, context.renderContext().expressionContext() );
double w = exprVal.toDouble( &ok );
if ( ok )
if ( !exprVal.isNull() )
{
mScaledArrowWidth = context.renderContext().convertToPainterUnits( w, arrowWidthUnit(), arrowWidthUnitScale() );
double w = exprVal.toDouble( &ok );
if ( ok )
{
mScaledArrowWidth = context.renderContext().convertToPainterUnits( w, arrowWidthUnit(), arrowWidthUnitScale() );
}
}
}
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyArrowStartWidth ) )
{
context.setOriginalValueVariable( arrowStartWidth() );
exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyArrowStartWidth, context.renderContext().expressionContext() );
double w = exprVal.toDouble( &ok );
if ( ok )
if ( !exprVal.isNull() )
{
mScaledArrowStartWidth = context.renderContext().convertToPainterUnits( w, arrowStartWidthUnit(), arrowStartWidthUnitScale() );
double w = exprVal.toDouble( &ok );
if ( ok )
{
mScaledArrowStartWidth = context.renderContext().convertToPainterUnits( w, arrowStartWidthUnit(), arrowStartWidthUnitScale() );
}
}
}
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyArrowHeadLength ) )
{
context.setOriginalValueVariable( headLength() );
exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyArrowHeadLength, context.renderContext().expressionContext() );
double w = exprVal.toDouble( &ok );
if ( ok )
if ( !exprVal.isNull() )
{
mScaledHeadLength = context.renderContext().convertToPainterUnits( w, headLengthUnit(), headLengthUnitScale() );
double w = exprVal.toDouble( &ok );
if ( ok )
{
mScaledHeadLength = context.renderContext().convertToPainterUnits( w, headLengthUnit(), headLengthUnitScale() );
}
}
}
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyArrowHeadThickness ) )
{
context.setOriginalValueVariable( headThickness() );
exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyArrowHeadThickness, context.renderContext().expressionContext() );
double w = exprVal.toDouble( &ok );
if ( ok )
if ( !exprVal.isNull() )
{
mScaledHeadThickness = context.renderContext().convertToPainterUnits( w, headThicknessUnit(), headThicknessUnitScale() );
double w = exprVal.toDouble( &ok );
if ( ok )
{
mScaledHeadThickness = context.renderContext().convertToPainterUnits( w, headThicknessUnit(), headThicknessUnitScale() );
}
}
}
if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyOffset ) )
@@ -681,21 +693,27 @@ void QgsArrowSymbolLayer::_resolveDataDefined( QgsSymbolRenderContext &context )
{
context.setOriginalValueVariable( headType() );
exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyArrowHeadType, context.renderContext().expressionContext() );
HeadType h = QgsSymbolLayerUtils::decodeArrowHeadType( exprVal, &ok );
if ( ok )
if ( !exprVal.isNull() )
{
mComputedHeadType = h;
HeadType h = QgsSymbolLayerUtils::decodeArrowHeadType( exprVal, &ok );
if ( ok )
{
mComputedHeadType = h;
}
}
}

if ( mDataDefinedProperties.isActive( QgsSymbolLayer::PropertyArrowType ) )
{
context.setOriginalValueVariable( arrowType() );
exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyArrowType, context.renderContext().expressionContext() );
ArrowType h = QgsSymbolLayerUtils::decodeArrowType( exprVal, &ok );
if ( ok )
if ( !exprVal.isNull() )
{
mComputedArrowType = h;
ArrowType h = QgsSymbolLayerUtils::decodeArrowType( exprVal, &ok );
if ( ok )
{
mComputedArrowType = h;
}
}
}
}

0 comments on commit 4e25c6b

Please sign in to comment.