Skip to content

Commit

Permalink
[symbology] Fall back to symbol style if data defined evaluation
Browse files Browse the repository at this point in the history
fails or is null.
  • Loading branch information
nyalldawson committed May 9, 2015
1 parent 4a4877d commit eb716fc
Show file tree
Hide file tree
Showing 7 changed files with 328 additions and 200 deletions.
4 changes: 3 additions & 1 deletion python/core/symbology-ng/qgssymbollayerv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ class QgsSymbolLayerV2
* @param property property key
* @param feature pointer to the feature to use during expression or field
* evaluation
* @returns calculated value for data defined property, or an invalid QVariant
* @param defaultVal default value to return if evaluation was not successful
* @param ok if specified, will be set to true if evaluation was successful
* @returns calculated value for data defined property, or default value
* if property does not exist or is deactived.
* @see hasDataDefinedProperty
* @see getDataDefinedProperty
Expand Down
50 changes: 31 additions & 19 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,33 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie

void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context )
{
bool ok;
if ( hasDataDefinedProperty( "outline_width" ) )
{
double width = evaluateDataDefinedProperty( "outline_width", context.feature() ).toDouble();
double width = evaluateDataDefinedProperty( "outline_width", context.feature(), mOutlineWidth ).toDouble();
width *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOutlineWidthUnit, mOutlineWidthMapUnitScale );
mPen.setWidthF( width );
}
if ( hasDataDefinedProperty( "outline_style" ) )
{
Qt::PenStyle style = QgsSymbolLayerV2Utils::decodePenStyle( evaluateDataDefinedProperty( "outline_style", context.feature() ).toString() );
mPen.setStyle( style );
QString styleString = evaluateDataDefinedProperty( "outline_style", context.feature(), QVariant(), &ok ).toString();
if ( ok )
{
Qt::PenStyle style = QgsSymbolLayerV2Utils::decodePenStyle( styleString );
mPen.setStyle( style );
}
}
if ( hasDataDefinedProperty( "fill_color" ) )
{
QString colorString = evaluateDataDefinedProperty( "fill_color", context.feature() ).toString();
mBrush.setColor( QColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) ) );
QString colorString = evaluateDataDefinedProperty( "fill_color", context.feature(), QVariant(), &ok ).toString();
if ( ok )
mBrush.setColor( QColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) ) );
}
if ( hasDataDefinedProperty( "outline_color" ) )
{
QString colorString = evaluateDataDefinedProperty( "outline_color", context.feature() ).toString();
mPen.setColor( QColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) ) );
QString colorString = evaluateDataDefinedProperty( "outline_color", context.feature(), QVariant(), &ok ).toString();
if ( ok )
mPen.setColor( QColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) ) );
}
double scaledWidth = mSymbolWidth;
double scaledHeight = mSymbolHeight;
Expand All @@ -223,7 +230,7 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
QString symbolName = mSymbolName;
if ( hasDataDefinedProperty( "symbol_name" ) )
{
symbolName = evaluateDataDefinedProperty( "symbol_name", context.feature() ).toString();
symbolName = evaluateDataDefinedProperty( "symbol_name", context.feature(), mSymbolName ).toString();
}
preparePath( symbolName, context, &scaledWidth, &scaledHeight, context.feature() );
}
Expand All @@ -244,7 +251,7 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
double rotation = 0.0;
if ( hasDataDefinedProperty( "rotation" ) )
{
rotation = evaluateDataDefinedProperty( "rotation", context.feature() ).toDouble();
rotation = evaluateDataDefinedProperty( "rotation", context.feature(), mAngle ).toDouble();
}
else if ( !qgsDoubleNear( mAngle, 0.0 ) )
{
Expand Down Expand Up @@ -446,7 +453,7 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV

if ( hasDataDefinedProperty( "width" ) ) //1. priority: data defined setting on symbol layer le
{
width = evaluateDataDefinedProperty( "width", f ).toDouble();
width = evaluateDataDefinedProperty( "width", f, mSymbolWidth ).toDouble();
}
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
Expand All @@ -465,7 +472,7 @@ void QgsEllipseSymbolLayerV2::preparePath( const QString& symbolName, QgsSymbolV
double height = 0;
if ( hasDataDefinedProperty( "height" ) ) //1. priority: data defined setting on symbol layer level
{
height = evaluateDataDefinedProperty( "height", f ).toDouble();
height = evaluateDataDefinedProperty( "height", f, mSymbolHeight ).toDouble();
}
else if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
Expand Down Expand Up @@ -549,7 +556,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa

if ( hasDataDefinedProperty( "width" ) ) //1. priority: data defined setting on symbol layer le
{
symbolWidth = evaluateDataDefinedProperty( "width", f ).toDouble();
symbolWidth = evaluateDataDefinedProperty( "width", f, mSymbolWidth ).toDouble();
}
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
Expand All @@ -564,7 +571,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
double symbolHeight = mSymbolHeight;
if ( hasDataDefinedProperty( "height" ) ) //1. priority: data defined setting on symbol layer level
{
symbolHeight = evaluateDataDefinedProperty( "height", f ).toDouble();
symbolHeight = evaluateDataDefinedProperty( "height", f, mSymbolHeight ).toDouble();
}
else if ( context->renderHints() & QgsSymbolV2::DataDefinedSizeScale ) //2. priority: is data defined size on symbol level
{
Expand All @@ -580,32 +587,37 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa

if ( hasDataDefinedProperty( "outline_width" ) )
{
outlineWidth = evaluateDataDefinedProperty( "outline_width", f ).toDouble();
outlineWidth = evaluateDataDefinedProperty( "outline_width", f, mOutlineWidth ).toDouble();
}
if ( mOutlineWidthUnit == QgsSymbolV2::MM )
{
outlineWidth *= outlineWidth;
}

//fill color
bool ok;
QColor fc = mFillColor;
if ( hasDataDefinedProperty( "fill_color" ) )
{
fc = QColor( evaluateDataDefinedProperty( "fill_color", f ).toString() );
QString colorString = evaluateDataDefinedProperty( "fill_color", f, QVariant(), &ok ).toString();
if ( ok )
fc = QColor( colorString );
}

//outline color
QColor oc = mOutlineColor;
if ( hasDataDefinedProperty( "outline_color" ) )
{
oc = QColor( evaluateDataDefinedProperty( "outline_color", f ).toString() );
QString colorString = evaluateDataDefinedProperty( "outline_color", f, QVariant(), &ok ).toString();
if ( ok )
oc = QColor( colorString );
}

//symbol name
QString symbolName = mSymbolName;
QString symbolName = mSymbolName;
if ( hasDataDefinedProperty( "symbol_name" ) )
{
symbolName = evaluateDataDefinedProperty( "symbol_name", f ).toString();
symbolName = evaluateDataDefinedProperty( "symbol_name", f, mSymbolName ).toString();
}

//offset
Expand All @@ -618,7 +630,7 @@ bool QgsEllipseSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitScaleFa
double rotation = 0.0;
if ( hasDataDefinedProperty( "rotation" ) )
{
rotation = evaluateDataDefinedProperty( "rotation", f ).toDouble();
rotation = evaluateDataDefinedProperty( "rotation", f, mAngle ).toDouble();
}
else if ( !qgsDoubleNear( mAngle, 0.0 ) )
{
Expand Down
Loading

1 comment on commit eb716fc

@nirvn
Copy link
Contributor

@nirvn nirvn commented on eb716fc May 9, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhhhh, bye bye black rectangle legend items!

Please sign in to comment.