Skip to content

Commit

Permalink
[symbology] Fix potential crash in data defined symbol rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 21, 2015
1 parent d9f54c4 commit d62794d
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/core/symbology-ng/qgssymbolv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ QgsDataDefined* scaleWholeSymbol( double scaleFactor, const QgsDataDefined& dd )
}

inline
QgsDataDefined* scaleWholeSymbol( double scaleFactorX, double scaleFactorY, const QgsDataDefined& dd )
QgsDataDefined* scaleWholeSymbol( double scaleFactorX, double scaleFactorY, const QgsDataDefined& dd )
{
QgsDataDefined* scaledDD = new QgsDataDefined( dd );
scaledDD->setUseExpression( true );
QString exprString = dd.useExpression() ? dd.expressionString() : dd.field();
scaledDD->setExpressionString(
( scaleFactorX ? "tostring(" + QString::number( scaleFactorX ) + "*(" + exprString + "))" : "'0'" ) +
"|| ',' || " +
( scaleFactorY ? "tostring(" + QString::number( scaleFactorY ) + "*(" + exprString + "))" : "'0'" ));
( scaleFactorX ? "tostring(" + QString::number( scaleFactorX ) + "*(" + exprString + "))" : "'0'" ) +
"|| ',' || " +
( scaleFactorY ? "tostring(" + QString::number( scaleFactorY ) + "*(" + exprString + "))" : "'0'" ) );
return scaledDD;
}

Expand Down Expand Up @@ -631,13 +631,13 @@ QgsDataDefined QgsMarkerSymbolV2::dataDefinedAngle() const

if ( qgsDoubleNear( layer->angle(), symbolRotation ) )
{
if ( *layerAngleDD != *symbolDD )
if ( !layerAngleDD || *layerAngleDD != *symbolDD )
return QgsDataDefined();
}
else
{
QScopedPointer< QgsDataDefined > rotatedDD( rotateWholeSymbol( layer->angle() - symbolRotation, *symbolDD ) );
if ( *layerAngleDD != *( rotatedDD.data() ) )
if ( !layerAngleDD || *layerAngleDD != *( rotatedDD.data() ) )
return QgsDataDefined();
}
}
Expand Down Expand Up @@ -707,8 +707,8 @@ void QgsMarkerSymbolV2::setDataDefinedSize( const QgsDataDefined &dd )
if ( layer->offset().x() || layer->offset().y() )
{
layer->setDataDefinedProperty( "offset", scaleWholeSymbol(
layer->offset().x() / symbolSize,
layer->offset().y() / symbolSize, dd ) );
layer->offset().x() / symbolSize,
layer->offset().y() / symbolSize, dd ) );
}
}
}
Expand Down Expand Up @@ -757,10 +757,9 @@ QgsDataDefined QgsMarkerSymbolV2::dataDefinedSize() const
return QgsDataDefined();
}


QScopedPointer< QgsDataDefined > scaledOffsetDD( scaleWholeSymbol( layer->offset().x() / symbolSize, layer->offset().y() / symbolSize, *symbolDD ) );
if ( layerOffsetDD && *layerOffsetDD != *( scaledOffsetDD.data() ) )
return QgsDataDefined();
return QgsDataDefined();
}

return QgsDataDefined( *symbolDD );
Expand Down Expand Up @@ -961,7 +960,7 @@ QgsDataDefined QgsLineSymbolV2::dataDefinedWidth() const

QScopedPointer< QgsDataDefined > scaledOffsetDD( scaleWholeSymbol( layer->offset() / symbolWidth, *symbolDD ) );
if ( layerOffsetDD && *layerOffsetDD != *( scaledOffsetDD.data() ) )
return QgsDataDefined();
return QgsDataDefined();
}

return QgsDataDefined( *symbolDD );
Expand Down

0 comments on commit d62794d

Please sign in to comment.