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

(cherry picked from commit bb131c5)
  • Loading branch information
nyalldawson committed Jun 8, 2021
1 parent 08e7b27 commit 2a3bcc365d901c3d69270fd9c4a9a2165c2cbd31
@@ -1288,7 +1288,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() );
}
@@ -1346,7 +1346,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 )
@@ -1365,7 +1365,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 );
@@ -1751,7 +1751,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() )
@@ -1860,7 +1860,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 );
@@ -1965,7 +1965,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 );
@@ -2026,7 +2026,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 )
{
@@ -2165,7 +2165,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 );
@@ -2237,7 +2237,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() )
@@ -2272,7 +2272,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 );
@@ -2290,15 +2290,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() )
@@ -2317,7 +2317,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 )
@@ -2335,7 +2335,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 )
@@ -2424,7 +2424,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() )
@@ -2537,7 +2537,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 );
@@ -2600,7 +2600,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 );
@@ -2701,7 +2701,7 @@ bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType,

context.setOriginalValueVariable( originalValue );
exprVal = mDataDefinedProperties.value( p, context );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
switch ( valType )
{
@@ -2889,7 +2889,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 );
@@ -2911,7 +2911,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 );
@@ -3177,7 +3177,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 );
@@ -3214,7 +3214,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() )
@@ -3239,7 +3239,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 );
@@ -3307,7 +3307,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 );
@@ -3326,7 +3326,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 );
@@ -3342,7 +3342,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 );
@@ -3413,7 +3413,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 );
@@ -3516,7 +3516,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 );
@@ -621,40 +621,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 ) )
@@ -672,21 +684,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;
}
}
}
}
@@ -184,7 +184,7 @@ void QgsEllipseSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext &
bool ok;
context.setOriginalValueVariable( mStrokeWidth );
QVariant exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyStrokeWidth, context.renderContext().expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
double width = exprVal.toDouble( &ok );
if ( ok )
@@ -197,15 +197,15 @@ void QgsEllipseSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext &

context.setOriginalValueVariable( QgsSymbolLayerUtils::encodePenStyle( mStrokeStyle ) );
exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyStrokeStyle, context.renderContext().expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
mPen.setStyle( QgsSymbolLayerUtils::decodePenStyle( exprVal.toString() ) );
mSelPen.setStyle( mPen.style() );
}

context.setOriginalValueVariable( QgsSymbolLayerUtils::encodePenJoinStyle( mPenJoinStyle ) );
exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyJoinStyle, context.renderContext().expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
mPen.setJoinStyle( QgsSymbolLayerUtils::decodePenJoinStyle( exprVal.toString() ) );
mSelPen.setJoinStyle( mPen.joinStyle() );
@@ -226,7 +226,7 @@ void QgsEllipseSymbolLayer::renderPoint( QPointF point, QgsSymbolRenderContext &
QString symbolName = mSymbolName;
context.setOriginalValueVariable( mSymbolName );
exprVal = mDataDefinedProperties.value( QgsSymbolLayer::PropertyName, context.renderContext().expressionContext() );
if ( exprVal.isValid() )
if ( !exprVal.isNull() )
{
symbolName = exprVal.toString();
}

0 comments on commit 2a3bcc3

Please sign in to comment.