Skip to content

Commit

Permalink
Use permissive parseColor method for evaluating data defined colors
Browse files Browse the repository at this point in the history
Allows more flexible conversion of evaluated strings to color
  • Loading branch information
nyalldawson committed May 6, 2015
1 parent aab3b15 commit 79c0d5b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/core/qgspallabeling.cpp
Expand Up @@ -2331,7 +2331,7 @@ bool QgsPalLayerSettings::dataDefinedValEval( const QString& valType,
{
QString colorstr = exprVal.toString().trimmed();
QgsDebugMsgLevel( dbgStr.arg( colorstr ), 4 );
QColor color = QgsSymbolLayerV2Utils::decodeColor( colorstr );
QColor color = QgsSymbolLayerV2Utils::parseColor( colorstr );

if ( color.isValid() )
{
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Expand Up @@ -209,12 +209,12 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
if ( hasDataDefinedProperty( "fill_color" ) )
{
QString colorString = evaluateDataDefinedProperty( "fill_color", context.feature() ).toString();
mBrush.setColor( QColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) ) );
mBrush.setColor( QColor( QgsSymbolLayerV2Utils::parseColor( colorString ) ) );
}
if ( hasDataDefinedProperty( "outline_color" ) )
{
QString colorString = evaluateDataDefinedProperty( "outline_color", context.feature() ).toString();
mPen.setColor( QColor( QgsSymbolLayerV2Utils::decodeColor( colorString ) ) );
mPen.setColor( QColor( QgsSymbolLayerV2Utils::parseColor( colorString ) ) );
}
double scaledWidth = mSymbolWidth;
double scaledHeight = mSymbolHeight;
Expand Down
22 changes: 11 additions & 11 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -82,15 +82,15 @@ void QgsSimpleFillSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderCon

if ( hasDataDefinedProperty( "color" ) )
{
brush.setColor( QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() ) );
brush.setColor( QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() ) );
}
if ( hasDataDefinedProperty( "fill_style" ) )
{
brush.setStyle( QgsSymbolLayerV2Utils::decodeBrushStyle( evaluateDataDefinedProperty( "fill_style", context.feature() ).toString() ) );
}
if ( hasDataDefinedProperty( "color_border" ) )
{
pen.setColor( QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color_border", context.feature() ).toString() ) );
pen.setColor( QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color_border", context.feature() ).toString() ) );
}
if ( hasDataDefinedProperty( "width_border" ) )
{
Expand Down Expand Up @@ -389,7 +389,7 @@ QColor QgsSimpleFillSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& con
{
if ( hasDataDefinedProperty( "border_color" ) )
{
return QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "border_color", context.feature() ).toString() );
return QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "border_color", context.feature() ).toString() );
}
return mBorderColor;
}
Expand All @@ -403,7 +403,7 @@ QColor QgsSimpleFillSymbolLayerV2::dxfBrushColor( const QgsSymbolV2RenderContext
{
if ( hasDataDefinedProperty( "color" ) )
{
return QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() );
return QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() );
}
return mColor;
}
Expand Down Expand Up @@ -540,14 +540,14 @@ void QgsGradientFillSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderC
QColor color = mColor;
if ( hasDataDefinedProperty( "color" ) )
{
color = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() );
color = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() );
}

//second gradient color
QColor color2 = mColor2;
if ( hasDataDefinedProperty( "color2" ) )
{
color2 = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color2", context.feature() ).toString() );
color2 = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color2", context.feature() ).toString() );
}

//gradient rotation angle
Expand Down Expand Up @@ -1020,14 +1020,14 @@ void QgsShapeburstFillSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2Rende
color = mColor;
if ( hasDataDefinedProperty( "color" ) )
{
color = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() );
color = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() );
}

//second gradient color
color2 = mColor2;
if ( hasDataDefinedProperty( "color2" ) )
{
color2 = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color2", context.feature() ).toString() );
color2 = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color2", context.feature() ).toString() );
}

//blur radius
Expand Down Expand Up @@ -2123,12 +2123,12 @@ void QgsSVGFillSymbolLayer::applyDataDefinedSettings( const QgsSymbolV2RenderCon
QColor svgFillColor = mSvgFillColor;
if ( hasDataDefinedProperty( "svgFillColor" ) )
{
svgFillColor = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "svgFillColor", context.feature() ).toString() );
svgFillColor = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "svgFillColor", context.feature() ).toString() );
}
QColor svgOutlineColor = mSvgOutlineColor;
if ( hasDataDefinedProperty( "svgOutlineColor" ) )
{
svgOutlineColor = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "svgOutlineColor", context.feature() ).toString() );
svgOutlineColor = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "svgOutlineColor", context.feature() ).toString() );
}
double outlineWidth = mSvgOutlineWidth;
if ( hasDataDefinedProperty( "svgOutlineWidth" ) )
Expand Down Expand Up @@ -2820,7 +2820,7 @@ void QgsLinePatternFillSymbolLayer::applyDataDefinedSettings( const QgsSymbolV2R
QColor color = mColor;
if ( hasDataDefinedProperty( "color" ) )
{
color = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() );
color = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() );
}
applyPattern( context, mBrush, lineAngle, distance, lineWidth, color );
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -479,7 +479,7 @@ void QgsSimpleLineSymbolLayerV2::applyDataDefinedSymbology( QgsSymbolV2RenderCon
//color
if ( hasDataDefinedProperty( "color" ) )
{
pen.setColor( QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() ) );
pen.setColor( QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() ) );
}

//offset
Expand Down Expand Up @@ -585,7 +585,7 @@ QColor QgsSimpleLineSymbolLayerV2::dxfColor( const QgsSymbolV2RenderContext& con
{
if ( hasDataDefinedProperty( "color" ) )
{
return ( QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() ) );
return ( QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() ) );
}
return mColor;
}
Expand Down
14 changes: 7 additions & 7 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -563,12 +563,12 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV

if ( hasDataDefinedProperty( "color" ) )
{
mBrush.setColor( QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() ) );
mBrush.setColor( QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color", context.feature() ).toString() ) );
}
if ( hasDataDefinedProperty( "color_border" ) )
{
mPen.setColor( QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color_border", context.feature() ).toString() ) );
mSelPen.setColor( QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color_border", context.feature() ).toString() ) );
mPen.setColor( QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color_border", context.feature() ).toString() ) );
mSelPen.setColor( QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color_border", context.feature() ).toString() ) );
}
if ( hasDataDefinedProperty( "outline_width" ) )
{
Expand Down Expand Up @@ -831,11 +831,11 @@ bool QgsSimpleMarkerSymbolLayerV2::writeDxf( QgsDxfExport& e, double mmMapUnitSc
QColor bc = mBrush.color();
if ( hasDataDefinedProperty( "color" ) )
{
bc = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color", f ).toString() );
bc = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color", f ).toString() );
}
if ( hasDataDefinedProperty( "color_border" ) )
{
pc = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "color_border", f ).toString() );
pc = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "color_border", f ).toString() );
}

//offset
Expand Down Expand Up @@ -1294,13 +1294,13 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
QColor fillColor = mFillColor;
if ( hasDataDefinedProperty( "fill" ) )
{
fillColor = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "fill", context.feature() ).toString() );
fillColor = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "fill", context.feature() ).toString() );
}

QColor outlineColor = mOutlineColor;
if ( hasDataDefinedProperty( "outline" ) )
{
outlineColor = QgsSymbolLayerV2Utils::decodeColor( evaluateDataDefinedProperty( "outline", context.feature() ).toString() );
outlineColor = QgsSymbolLayerV2Utils::parseColor( evaluateDataDefinedProperty( "outline", context.feature() ).toString() );
}

bool fitsInCache = true;
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgspointdisplacementrenderer.cpp
Expand Up @@ -336,8 +336,8 @@ QgsFeatureRendererV2* QgsPointDisplacementRenderer::create( QDomElement& symbolo
labelFont.fromString( symbologyElem.attribute( "labelFont", "" ) );
r->setLabelFont( labelFont );
r->setCircleWidth( symbologyElem.attribute( "circleWidth", "0.4" ).toDouble() );
r->setCircleColor( QgsSymbolLayerV2Utils::decodeColor( symbologyElem.attribute( "circleColor", "" ) ) );
r->setLabelColor( QgsSymbolLayerV2Utils::decodeColor( symbologyElem.attribute( "labelColor", "" ) ) );
r->setCircleColor( QgsSymbolLayerV2Utils::parseColor( symbologyElem.attribute( "circleColor", "" ) ) );
r->setLabelColor( QgsSymbolLayerV2Utils::parseColor( symbologyElem.attribute( "labelColor", "" ) ) );
r->setCircleRadiusAddition( symbologyElem.attribute( "circleRadiusAddition", "0.0" ).toDouble() );
r->setMaxLabelScaleDenominator( symbologyElem.attribute( "maxLabelScaleDenominator", "-1" ).toDouble() );
r->setTolerance( symbologyElem.attribute( "tolerance", "0.00001" ).toDouble() );
Expand Down

4 comments on commit 79c0d5b

@m-kuhn
Copy link
Member

@m-kuhn m-kuhn commented on 79c0d5b May 7, 2015

Choose a reason for hiding this comment

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

This breaks parsing colors like 0,0,255,255

@m-kuhn
Copy link
Member

@m-kuhn m-kuhn commented on 79c0d5b May 7, 2015

Choose a reason for hiding this comment

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

Looks like the alpha value is interpreted differently.
int 0-255 vs. float 0-1

@nyalldawson
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@m-kuhn gah... reverted. I can't fix this since it's impossible to differentiate 0,0,255,1 from an alpha of 100% (eg, final value is a double from 0->1, css style) from an alpha of 1/255 (2.8 behaviour).

@m-kuhn
Copy link
Member

@m-kuhn m-kuhn commented on 79c0d5b May 7, 2015

Choose a reason for hiding this comment

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

Too bad, so colors are not interpreted consistently within QGIS?
(Btw, the 2.8 behavior is the Qt behavior)

Please sign in to comment.