From 673f0b198afc02c3c27e2c7a2d2649c6a46937d3 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Fri, 29 Dec 2023 15:59:50 +0700 Subject: [PATCH 1/6] [core] Rely on QgsColorUtils encoding/decoding to handle CMYK --- src/3d/lights/qgsdirectionallightsettings.cpp | 5 +- src/3d/lights/qgspointlightsettings.cpp | 5 +- src/3d/materials/qgsgoochmaterialsettings.cpp | 18 +++--- src/3d/materials/qgsphongmaterialsettings.cpp | 14 ++--- .../qgsphongtexturedmaterialsettings.cpp | 10 ++-- .../qgssimplelinematerialsettings.cpp | 7 ++- src/3d/qgs3dmapsettings.cpp | 10 ++-- src/3d/symbols/qgsmesh3dsymbol.cpp | 10 ++-- src/3d/symbols/qgspointcloud3dsymbol.cpp | 10 ++-- src/3d/symbols/qgspolygon3dsymbol.cpp | 6 +- src/app/decorations/qgsdecorationimage.cpp | 9 +-- .../decorations/qgsdecorationnortharrow.cpp | 9 +-- src/app/decorations/qgsdecorationscalebar.cpp | 10 ++-- src/app/decorations/qgsdecorationtitle.cpp | 6 +- .../editform/qgsattributeeditorelement.cpp | 6 +- src/core/effects/qgscoloreffect.cpp | 8 ++- src/core/effects/qgsgloweffect.cpp | 5 +- src/core/effects/qgsshadoweffect.cpp | 5 +- .../labeling/qgslabelingenginesettings.cpp | 6 +- src/core/labeling/qgspallabeling.cpp | 13 +++-- src/core/layout/qgslayoutitemlegend.cpp | 6 +- src/core/layout/qgslayoutitemmapgrid.cpp | 15 ++--- src/core/layout/qgslayoutitempicture.cpp | 9 +-- src/core/layout/qgslayoutitempolyline.cpp | 9 +-- src/core/layout/qgslayouttable.cpp | 18 +++--- src/core/mesh/qgsmeshrenderersettings.cpp | 10 ++-- .../qgspointcloudclassifiedrenderer.cpp | 6 +- .../qgspointcloudlayerelevationproperties.cpp | 6 +- .../models/qgsprocessingmodelcomponent.cpp | 6 +- src/core/project/qgsproject.cpp | 6 +- src/core/qgscolorrampimpl.cpp | 18 +++--- src/core/qgsdatadefinedsizelegend.cpp | 5 +- src/core/qgsdiagramrenderer.cpp | 5 +- src/core/qgspropertytransformer.cpp | 5 +- src/core/qgsxmlutils.cpp | 6 +- src/core/raster/qgsrasterrenderer.cpp | 6 +- src/core/symbology/qgsellipsesymbollayer.cpp | 14 +++-- src/core/symbology/qgsfillsymbollayer.cpp | 57 ++++++++++--------- .../symbology/qgsinterpolatedlinerenderer.cpp | 13 +++-- src/core/symbology/qgslinesymbollayer.cpp | 19 ++++--- src/core/symbology/qgsmarkersymbollayer.cpp | 37 ++++++------ .../qgspointdisplacementrenderer.cpp | 9 +-- src/core/symbology/qgssymbol.cpp | 3 +- src/core/symbology/qgssymbollayerutils.cpp | 11 ++-- .../qgstextbackgroundsettings.cpp | 9 +-- .../textrenderer/qgstextbuffersettings.cpp | 5 +- src/core/textrenderer/qgstextformat.cpp | 9 +-- .../textrenderer/qgstextshadowsettings.cpp | 5 +- 48 files changed, 264 insertions(+), 235 deletions(-) diff --git a/src/3d/lights/qgsdirectionallightsettings.cpp b/src/3d/lights/qgsdirectionallightsettings.cpp index e53f6f480d2a..c7d30a26f924 100644 --- a/src/3d/lights/qgsdirectionallightsettings.cpp +++ b/src/3d/lights/qgsdirectionallightsettings.cpp @@ -15,6 +15,7 @@ #include "qgsdirectionallightsettings.h" #include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include #include @@ -53,7 +54,7 @@ QDomElement QgsDirectionalLightSettings::writeXml( QDomDocument &doc, const QgsR elemLight.setAttribute( QStringLiteral( "x" ), mDirection.x() ); elemLight.setAttribute( QStringLiteral( "y" ), mDirection.y() ); elemLight.setAttribute( QStringLiteral( "z" ), mDirection.z() ); - elemLight.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); + elemLight.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) ); elemLight.setAttribute( QStringLiteral( "intensity" ), mIntensity ); return elemLight; } @@ -63,7 +64,7 @@ void QgsDirectionalLightSettings::readXml( const QDomElement &elem, const QgsRea mDirection.set( elem.attribute( QStringLiteral( "x" ) ).toFloat(), elem.attribute( QStringLiteral( "y" ) ).toFloat(), elem.attribute( QStringLiteral( "z" ) ).toFloat() ); - mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "color" ) ) ); + mColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "color" ) ) ); mIntensity = elem.attribute( QStringLiteral( "intensity" ) ).toFloat(); } diff --git a/src/3d/lights/qgspointlightsettings.cpp b/src/3d/lights/qgspointlightsettings.cpp index 9ccdbee31b06..1f35154d5c87 100644 --- a/src/3d/lights/qgspointlightsettings.cpp +++ b/src/3d/lights/qgspointlightsettings.cpp @@ -15,6 +15,7 @@ #include "qgspointlightsettings.h" #include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgs3dmapsettings.h" #include @@ -90,7 +91,7 @@ QDomElement QgsPointLightSettings::writeXml( QDomDocument &doc, const QgsReadWri elemLight.setAttribute( QStringLiteral( "x" ), mPosition.x() ); elemLight.setAttribute( QStringLiteral( "y" ), mPosition.y() ); elemLight.setAttribute( QStringLiteral( "z" ), mPosition.z() ); - elemLight.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); + elemLight.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) ); elemLight.setAttribute( QStringLiteral( "intensity" ), mIntensity ); elemLight.setAttribute( QStringLiteral( "attenuation-0" ), mConstantAttenuation ); elemLight.setAttribute( QStringLiteral( "attenuation-1" ), mLinearAttenuation ); @@ -103,7 +104,7 @@ void QgsPointLightSettings::readXml( const QDomElement &elem, const QgsReadWrite mPosition.set( elem.attribute( QStringLiteral( "x" ) ).toDouble(), elem.attribute( QStringLiteral( "y" ) ).toDouble(), elem.attribute( QStringLiteral( "z" ) ).toDouble() ); - mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "color" ) ) ); + mColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "color" ) ) ); mIntensity = elem.attribute( QStringLiteral( "intensity" ) ).toFloat(); mConstantAttenuation = elem.attribute( QStringLiteral( "attenuation-0" ) ).toDouble(); mLinearAttenuation = elem.attribute( QStringLiteral( "attenuation-1" ) ).toDouble(); diff --git a/src/3d/materials/qgsgoochmaterialsettings.cpp b/src/3d/materials/qgsgoochmaterialsettings.cpp index fdf83cc375ad..9e7427ecbf0b 100644 --- a/src/3d/materials/qgsgoochmaterialsettings.cpp +++ b/src/3d/materials/qgsgoochmaterialsettings.cpp @@ -14,8 +14,8 @@ ***************************************************************************/ #include "qgsgoochmaterialsettings.h" +#include "qgscolorutils.h" -#include "qgssymbollayerutils.h" #include #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include @@ -75,10 +75,10 @@ QgsGoochMaterialSettings *QgsGoochMaterialSettings::clone() const void QgsGoochMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context ) { - mWarm = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "warm" ), QStringLiteral( "107,0,107" ) ) ); - mCool = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "cool" ), QStringLiteral( "255,130,0" ) ) ); - mDiffuse = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "diffuse" ), QStringLiteral( "178,178,178" ) ) ); - mSpecular = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "specular" ) ) ); + mWarm = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "warm" ), QStringLiteral( "107,0,107" ) ) ); + mCool = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "cool" ), QStringLiteral( "255,130,0" ) ) ); + mDiffuse = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "diffuse" ), QStringLiteral( "178,178,178" ) ) ); + mSpecular = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "specular" ) ) ); mShininess = elem.attribute( QStringLiteral( "shininess2" ), QStringLiteral( "100" ) ).toFloat(); mAlpha = elem.attribute( QStringLiteral( "alpha" ), QStringLiteral( "0.25" ) ).toFloat(); mBeta = elem.attribute( QStringLiteral( "beta" ), QStringLiteral( "0.5" ) ).toFloat(); @@ -88,10 +88,10 @@ void QgsGoochMaterialSettings::readXml( const QDomElement &elem, const QgsReadWr void QgsGoochMaterialSettings::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const { - elem.setAttribute( QStringLiteral( "warm" ), QgsSymbolLayerUtils::encodeColor( mWarm ) ); - elem.setAttribute( QStringLiteral( "cool" ), QgsSymbolLayerUtils::encodeColor( mCool ) ); - elem.setAttribute( QStringLiteral( "diffuse" ), QgsSymbolLayerUtils::encodeColor( mDiffuse ) ); - elem.setAttribute( QStringLiteral( "specular" ), QgsSymbolLayerUtils::encodeColor( mSpecular ) ); + elem.setAttribute( QStringLiteral( "warm" ), QgsColorUtils::colorToString( mWarm ) ); + elem.setAttribute( QStringLiteral( "cool" ), QgsColorUtils::colorToString( mCool ) ); + elem.setAttribute( QStringLiteral( "diffuse" ), QgsColorUtils::colorToString( mDiffuse ) ); + elem.setAttribute( QStringLiteral( "specular" ), QgsColorUtils::colorToString( mSpecular ) ); elem.setAttribute( QStringLiteral( "shininess2" ), mShininess ); elem.setAttribute( QStringLiteral( "alpha" ), mAlpha ); elem.setAttribute( QStringLiteral( "beta" ), mBeta ); diff --git a/src/3d/materials/qgsphongmaterialsettings.cpp b/src/3d/materials/qgsphongmaterialsettings.cpp index a1768bf95a56..2cadc6990b95 100644 --- a/src/3d/materials/qgsphongmaterialsettings.cpp +++ b/src/3d/materials/qgsphongmaterialsettings.cpp @@ -14,8 +14,8 @@ ***************************************************************************/ #include "qgsphongmaterialsettings.h" +#include "qgscolorutils.h" -#include "qgssymbollayerutils.h" #include #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include @@ -79,9 +79,9 @@ QgsPhongMaterialSettings *QgsPhongMaterialSettings::clone() const void QgsPhongMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context ) { - mAmbient = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "ambient" ), QStringLiteral( "25,25,25" ) ) ); - mDiffuse = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "diffuse" ), QStringLiteral( "178,178,178" ) ) ); - mSpecular = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "specular" ), QStringLiteral( "255,255,255" ) ) ); + mAmbient = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "ambient" ), QStringLiteral( "25,25,25" ) ) ); + mDiffuse = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "diffuse" ), QStringLiteral( "178,178,178" ) ) ); + mSpecular = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "specular" ), QStringLiteral( "255,255,255" ) ) ); mShininess = elem.attribute( QStringLiteral( "shininess" ) ).toFloat(); mOpacity = elem.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1.0" ) ).toFloat(); @@ -90,9 +90,9 @@ void QgsPhongMaterialSettings::readXml( const QDomElement &elem, const QgsReadWr void QgsPhongMaterialSettings::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const { - elem.setAttribute( QStringLiteral( "ambient" ), QgsSymbolLayerUtils::encodeColor( mAmbient ) ); - elem.setAttribute( QStringLiteral( "diffuse" ), QgsSymbolLayerUtils::encodeColor( mDiffuse ) ); - elem.setAttribute( QStringLiteral( "specular" ), QgsSymbolLayerUtils::encodeColor( mSpecular ) ); + elem.setAttribute( QStringLiteral( "ambient" ), QgsColorUtils::colorToString( mAmbient ) ); + elem.setAttribute( QStringLiteral( "diffuse" ), QgsColorUtils::colorToString( mDiffuse ) ); + elem.setAttribute( QStringLiteral( "specular" ), QgsColorUtils::colorToString( mSpecular ) ); elem.setAttribute( QStringLiteral( "shininess" ), mShininess ); elem.setAttribute( QStringLiteral( "opacity" ), mOpacity ); diff --git a/src/3d/materials/qgsphongtexturedmaterialsettings.cpp b/src/3d/materials/qgsphongtexturedmaterialsettings.cpp index 017a45dfc9b8..97885d33712e 100644 --- a/src/3d/materials/qgsphongtexturedmaterialsettings.cpp +++ b/src/3d/materials/qgsphongtexturedmaterialsettings.cpp @@ -15,8 +15,8 @@ #include "qgsphongtexturedmaterialsettings.h" -#include "qgssymbollayerutils.h" #include "qgsapplication.h" +#include "qgscolorutils.h" #include "qgsimagecache.h" #include "qgsimagetexture.h" #include "qgsphongmaterialsettings.h" @@ -69,8 +69,8 @@ float QgsPhongTexturedMaterialSettings::textureRotation() const void QgsPhongTexturedMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context ) { - mAmbient = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "ambient" ), QStringLiteral( "25,25,25" ) ) ); - mSpecular = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "specular" ), QStringLiteral( "255,255,255" ) ) ); + mAmbient = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "ambient" ), QStringLiteral( "25,25,25" ) ) ); + mSpecular = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "specular" ), QStringLiteral( "255,255,255" ) ) ); mShininess = elem.attribute( QStringLiteral( "shininess" ) ).toFloat(); mOpacity = elem.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1.0" ) ).toFloat(); mDiffuseTexturePath = elem.attribute( QStringLiteral( "diffuse_texture_path" ), QString() ); @@ -82,8 +82,8 @@ void QgsPhongTexturedMaterialSettings::readXml( const QDomElement &elem, const Q void QgsPhongTexturedMaterialSettings::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const { - elem.setAttribute( QStringLiteral( "ambient" ), QgsSymbolLayerUtils::encodeColor( mAmbient ) ); - elem.setAttribute( QStringLiteral( "specular" ), QgsSymbolLayerUtils::encodeColor( mSpecular ) ); + elem.setAttribute( QStringLiteral( "ambient" ), QgsColorUtils::colorToString( mAmbient ) ); + elem.setAttribute( QStringLiteral( "specular" ), QgsColorUtils::colorToString( mSpecular ) ); elem.setAttribute( QStringLiteral( "shininess" ), mShininess ); elem.setAttribute( QStringLiteral( "opacity" ), mOpacity ); elem.setAttribute( QStringLiteral( "diffuse_texture_path" ), mDiffuseTexturePath ); diff --git a/src/3d/materials/qgssimplelinematerialsettings.cpp b/src/3d/materials/qgssimplelinematerialsettings.cpp index 29b13758cb2d..bbdf61d54e1a 100644 --- a/src/3d/materials/qgssimplelinematerialsettings.cpp +++ b/src/3d/materials/qgssimplelinematerialsettings.cpp @@ -14,8 +14,9 @@ ***************************************************************************/ #include "qgssimplelinematerialsettings.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgslinematerial_p.h" + #include #include #include @@ -74,14 +75,14 @@ QgsSimpleLineMaterialSettings *QgsSimpleLineMaterialSettings::clone() const void QgsSimpleLineMaterialSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context ) { - mAmbient = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "ambient" ), QStringLiteral( "25,25,25" ) ) ); + mAmbient = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "ambient" ), QStringLiteral( "25,25,25" ) ) ); QgsAbstractMaterialSettings::readXml( elem, context ); } void QgsSimpleLineMaterialSettings::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const { - elem.setAttribute( QStringLiteral( "ambient" ), QgsSymbolLayerUtils::encodeColor( mAmbient ) ); + elem.setAttribute( QStringLiteral( "ambient" ), QgsColorUtils::colorToString( mAmbient ) ); QgsAbstractMaterialSettings::writeXml( elem, context ); } diff --git a/src/3d/qgs3dmapsettings.cpp b/src/3d/qgs3dmapsettings.cpp index e83471caeb05..9447f60a7b2d 100644 --- a/src/3d/qgs3dmapsettings.cpp +++ b/src/3d/qgs3dmapsettings.cpp @@ -27,7 +27,7 @@ #include "qgsprojectelevationproperties.h" #include "qgsterrainprovider.h" #include "qgslightsource.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgsrasterlayer.h" #include "qgspointlightsettings.h" #include "qgsdirectionallightsettings.h" @@ -159,8 +159,8 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte QDomElement elemColor = elem.firstChildElement( QStringLiteral( "color" ) ); if ( !elemColor.isNull() ) { - mBackgroundColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( QStringLiteral( "background" ) ) ); - mSelectionColor = QgsSymbolLayerUtils::decodeColor( elemColor.attribute( QStringLiteral( "selection" ) ) ); + mBackgroundColor = QgsColorUtils::colorFromString( elemColor.attribute( QStringLiteral( "background" ) ) ); + mSelectionColor = QgsColorUtils::colorFromString( elemColor.attribute( QStringLiteral( "selection" ) ) ); } QDomElement elemCrs = elem.firstChildElement( QStringLiteral( "crs" ) ); @@ -349,8 +349,8 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon elem.appendChild( elemCamera ); QDomElement elemColor = doc.createElement( QStringLiteral( "color" ) ); - elemColor.setAttribute( QStringLiteral( "background" ), QgsSymbolLayerUtils::encodeColor( mBackgroundColor ) ); - elemColor.setAttribute( QStringLiteral( "selection" ), QgsSymbolLayerUtils::encodeColor( mSelectionColor ) ); + elemColor.setAttribute( QStringLiteral( "background" ), QgsColorUtils::colorToString( mBackgroundColor ) ); + elemColor.setAttribute( QStringLiteral( "selection" ), QgsColorUtils::colorToString( mSelectionColor ) ); elem.appendChild( elemColor ); QDomElement elemCrs = doc.createElement( QStringLiteral( "crs" ) ); diff --git a/src/3d/symbols/qgsmesh3dsymbol.cpp b/src/3d/symbols/qgsmesh3dsymbol.cpp index 07e15266b96a..f93ac18c7949 100644 --- a/src/3d/symbols/qgsmesh3dsymbol.cpp +++ b/src/3d/symbols/qgsmesh3dsymbol.cpp @@ -15,8 +15,8 @@ #include "qgsmesh3dsymbol.h" #include "qgs3dtypes.h" -#include "qgssymbollayerutils.h" #include "qgs3dutils.h" +#include "qgscolorutils.h" #include "qgsphongmaterialsettings.h" QgsMesh3DSymbol::QgsMesh3DSymbol() @@ -79,7 +79,7 @@ void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &co elemAdvancedSettings.setAttribute( QStringLiteral( "smoothed-triangle" ), mSmoothedTriangles ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-enabled" ), mWireframeEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-width" ), mWireframeLineWidth ); - elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-color" ), QgsSymbolLayerUtils::encodeColor( mWireframeLineColor ) ); + elemAdvancedSettings.setAttribute( QStringLiteral( "wireframe-line-color" ), QgsColorUtils::colorToString( mWireframeLineColor ) ); elemAdvancedSettings.setAttribute( QStringLiteral( "level-of-detail" ), mLevelOfDetailIndex ); elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-scale" ), mVerticalScale ); elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-group-index" ), mVerticalDatasetGroupIndex ); @@ -88,7 +88,7 @@ void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &co elemAdvancedSettings.appendChild( mColorRampShader.writeXml( doc, context ) ); elemAdvancedSettings.setAttribute( QStringLiteral( "min-color-ramp-shader" ), mColorRampShader.minimumValue() ); elemAdvancedSettings.setAttribute( QStringLiteral( "max-color-ramp-shader" ), mColorRampShader.maximumValue() ); - elemAdvancedSettings.setAttribute( QStringLiteral( "texture-single-color" ), QgsSymbolLayerUtils::encodeColor( mSingleColor ) ); + elemAdvancedSettings.setAttribute( QStringLiteral( "texture-single-color" ), QgsColorUtils::colorToString( mSingleColor ) ); elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-enabled" ), mArrowsEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-spacing" ), mArrowsSpacing ); elemAdvancedSettings.setAttribute( QStringLiteral( "arrows-fixed-size" ), mArrowsFixedSize ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); @@ -117,7 +117,7 @@ void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex mSmoothedTriangles = elemAdvancedSettings.attribute( QStringLiteral( "smoothed-triangle" ) ).toInt(); mWireframeEnabled = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-enabled" ) ).toInt(); mWireframeLineWidth = elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-width" ) ).toDouble(); - mWireframeLineColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-color" ) ) ); + mWireframeLineColor = QgsColorUtils::colorFromString( elemAdvancedSettings.attribute( QStringLiteral( "wireframe-line-color" ) ) ); mLevelOfDetailIndex = elemAdvancedSettings.attribute( QStringLiteral( "level-of-detail" ) ).toInt(); mVerticalScale = elemAdvancedSettings.attribute( "vertical-scale" ).toDouble(); mVerticalDatasetGroupIndex = elemAdvancedSettings.attribute( "vertical-group-index" ).toInt(); @@ -126,7 +126,7 @@ void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex mColorRampShader.readXml( elemAdvancedSettings.firstChildElement( "colorrampshader" ), context ); mColorRampShader.setMinimumValue( elemAdvancedSettings.attribute( QStringLiteral( "min-color-ramp-shader" ) ).toDouble() ); mColorRampShader.setMaximumValue( elemAdvancedSettings.attribute( QStringLiteral( "max-color-ramp-shader" ) ).toDouble() ); - mSingleColor = QgsSymbolLayerUtils::decodeColor( elemAdvancedSettings.attribute( QStringLiteral( "texture-single-color" ) ) ); + mSingleColor = QgsColorUtils::colorFromString( elemAdvancedSettings.attribute( QStringLiteral( "texture-single-color" ) ) ); mArrowsEnabled = elemAdvancedSettings.attribute( QStringLiteral( "arrows-enabled" ) ).toInt(); if ( elemAdvancedSettings.hasAttribute( QStringLiteral( "arrows-spacing" ) ) ) mArrowsSpacing = elemAdvancedSettings.attribute( QStringLiteral( "arrows-spacing" ) ).toDouble(); diff --git a/src/3d/symbols/qgspointcloud3dsymbol.cpp b/src/3d/symbols/qgspointcloud3dsymbol.cpp index 0896b5c12355..eacc98df2c12 100644 --- a/src/3d/symbols/qgspointcloud3dsymbol.cpp +++ b/src/3d/symbols/qgspointcloud3dsymbol.cpp @@ -15,8 +15,8 @@ #include "qgspointcloud3dsymbol.h" +#include "qgscolorutils.h" #include "qgscolorramptexture.h" -#include "qgssymbollayerutils.h" #include #include @@ -149,7 +149,7 @@ void QgsSingleColorPointCloud3DSymbol::writeXml( QDomElement &elem, const QgsRea Q_UNUSED( context ) writeBaseXml( elem, context ); - elem.setAttribute( QStringLiteral( "single-color" ), QgsSymbolLayerUtils::encodeColor( mSingleColor ) ); + elem.setAttribute( QStringLiteral( "single-color" ), QgsColorUtils::colorToString( mSingleColor ) ); } @@ -158,7 +158,7 @@ void QgsSingleColorPointCloud3DSymbol::readXml( const QDomElement &elem, const Q Q_UNUSED( context ) readBaseXml( elem, context ); - mSingleColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "single-color" ), QStringLiteral( "0,0,255" ) ) ); + mSingleColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "single-color" ), QStringLiteral( "0,0,255" ) ) ); } void QgsSingleColorPointCloud3DSymbol::setSingleColor( QColor color ) @@ -493,7 +493,7 @@ void QgsClassificationPointCloud3DSymbol::writeXml( QDomElement &elem, const Qgs catElem.setAttribute( QStringLiteral( "value" ), QString::number( category.value() ) ); catElem.setAttribute( QStringLiteral( "pointSize" ), category.pointSize() ); catElem.setAttribute( QStringLiteral( "label" ), category.label() ); - catElem.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( category.color() ) ); + catElem.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( category.color() ) ); catElem.setAttribute( QStringLiteral( "render" ), category.renderState() ? "true" : "false" ); catsElem.appendChild( catElem ); } @@ -520,7 +520,7 @@ void QgsClassificationPointCloud3DSymbol::readXml( const QDomElement &elem, cons const double size = catElem.attribute( QStringLiteral( "pointSize" ), QStringLiteral( "0" ) ).toDouble(); const QString label = catElem.attribute( QStringLiteral( "label" ) ); const bool render = catElem.attribute( QStringLiteral( "render" ) ) != QLatin1String( "false" ); - const QColor color = QgsSymbolLayerUtils::decodeColor( catElem.attribute( QStringLiteral( "color" ) ) ); + const QColor color = QgsColorUtils::colorFromString( catElem.attribute( QStringLiteral( "color" ) ) ); mCategoriesList.append( QgsPointCloudCategory( value, color, label, render, size ) ); } catElem = catElem.nextSiblingElement(); diff --git a/src/3d/symbols/qgspolygon3dsymbol.cpp b/src/3d/symbols/qgspolygon3dsymbol.cpp index a472bc1d2b8e..c28c25abc7c5 100644 --- a/src/3d/symbols/qgspolygon3dsymbol.cpp +++ b/src/3d/symbols/qgspolygon3dsymbol.cpp @@ -18,8 +18,8 @@ #include #include "qgs3dutils.h" -#include "qgssymbollayerutils.h" #include "qgs3d.h" +#include "qgscolorutils.h" #include "qgsmaterialregistry.h" #include "qgs3dsceneexporter.h" #include "qgsvectorlayerelevationproperties.h" @@ -82,7 +82,7 @@ void QgsPolygon3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext QDomElement elemEdges = doc.createElement( QStringLiteral( "edges" ) ); elemEdges.setAttribute( QStringLiteral( "enabled" ), mEdgesEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); elemEdges.setAttribute( QStringLiteral( "width" ), mEdgeWidth ); - elemEdges.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mEdgeColor ) ); + elemEdges.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mEdgeColor ) ); elem.appendChild( elemEdges ); } @@ -116,7 +116,7 @@ void QgsPolygon3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteCon { mEdgesEnabled = elemEdges.attribute( QStringLiteral( "enabled" ) ).toInt(); mEdgeWidth = elemEdges.attribute( QStringLiteral( "width" ) ).toFloat(); - mEdgeColor = QgsSymbolLayerUtils::decodeColor( elemEdges.attribute( QStringLiteral( "color" ) ) ); + mEdgeColor = QgsColorUtils::colorFromString( elemEdges.attribute( QStringLiteral( "color" ) ) ); } } diff --git a/src/app/decorations/qgsdecorationimage.cpp b/src/app/decorations/qgsdecorationimage.cpp index 5f13d79c9d85..f5b9605c5da5 100644 --- a/src/app/decorations/qgsdecorationimage.cpp +++ b/src/app/decorations/qgsdecorationimage.cpp @@ -20,6 +20,7 @@ #include "qgsimagecache.h" #include "qgslogger.h" #include "qgsproject.h" +#include "qgscolorutils.h" #include "qgssymbollayerutils.h" #include "qgssvgcache.h" #include "qgsmapsettings.h" @@ -49,8 +50,8 @@ QgsDecorationImage::QgsDecorationImage( QObject *parent ) void QgsDecorationImage::projectRead() { QgsDecorationItem::projectRead(); - mColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/Color" ), QStringLiteral( "#000000" ) ) ); - mOutlineColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QStringLiteral( "#FFFFFF" ) ) ); + mColor = QgsColorUtils::colorFromString( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/Color" ), QStringLiteral( "#000000" ) ) ); + mOutlineColor = QgsColorUtils::colorFromString( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QStringLiteral( "#FFFFFF" ) ) ); mSize = QgsProject::instance()->readDoubleEntry( mConfigurationName, QStringLiteral( "/Size" ), 16.0 ); setImagePath( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/ImagePath" ), QString() ) ); mMarginHorizontal = QgsProject::instance()->readNumEntry( mConfigurationName, QStringLiteral( "/MarginH" ), 0 ); @@ -60,8 +61,8 @@ void QgsDecorationImage::projectRead() void QgsDecorationImage::saveToProject() { QgsDecorationItem::saveToProject(); - QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); - QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QgsSymbolLayerUtils::encodeColor( mOutlineColor ) ); + QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Color" ), QgsColorUtils::colorToString( mColor ) ); + QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QgsColorUtils::colorToString( mOutlineColor ) ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Size" ), mSize ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/ImagePath" ), QgsProject::instance()->pathResolver().writePath( mImagePath ) ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/MarginH" ), mMarginHorizontal ); diff --git a/src/app/decorations/qgsdecorationnortharrow.cpp b/src/app/decorations/qgsdecorationnortharrow.cpp index b5c3b7d3fa3d..f040f0a92a80 100644 --- a/src/app/decorations/qgsdecorationnortharrow.cpp +++ b/src/app/decorations/qgsdecorationnortharrow.cpp @@ -26,6 +26,7 @@ email : tim@linfiniti.com #include "qgisapp.h" #include "qgsbearingutils.h" +#include "qgscolorutils.h" #include "qgsexception.h" #include "qgslogger.h" #include "qgsproject.h" @@ -63,8 +64,8 @@ QgsDecorationNorthArrow::QgsDecorationNorthArrow( QObject *parent ) void QgsDecorationNorthArrow::projectRead() { QgsDecorationItem::projectRead(); - mColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/Color" ), QStringLiteral( "#000000" ) ) ); - mOutlineColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QStringLiteral( "#FFFFFF" ) ) ); + mColor = QgsColorUtils::colorFromString( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/Color" ), QStringLiteral( "#000000" ) ) ); + mOutlineColor = QgsColorUtils::colorFromString( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QStringLiteral( "#FFFFFF" ) ) ); mSize = QgsProject::instance()->readDoubleEntry( mConfigurationName, QStringLiteral( "/Size" ), 16.0 ); mSvgPath = QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/SvgPath" ), QString() ); mRotationInt = QgsProject::instance()->readNumEntry( mConfigurationName, QStringLiteral( "/Rotation" ), 0 ); @@ -76,8 +77,8 @@ void QgsDecorationNorthArrow::projectRead() void QgsDecorationNorthArrow::saveToProject() { QgsDecorationItem::saveToProject(); - QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); - QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QgsSymbolLayerUtils::encodeColor( mOutlineColor ) ); + QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Color" ), QgsColorUtils::colorToString( mColor ) ); + QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QgsColorUtils::colorToString( mOutlineColor ) ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Size" ), mSize ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/SvgPath" ), mSvgPath ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Rotation" ), mRotationInt ); diff --git a/src/app/decorations/qgsdecorationscalebar.cpp b/src/app/decorations/qgsdecorationscalebar.cpp index 237854a1ba04..99f73ae61fcc 100644 --- a/src/app/decorations/qgsdecorationscalebar.cpp +++ b/src/app/decorations/qgsdecorationscalebar.cpp @@ -33,7 +33,7 @@ email : sbr00pwb@users.sourceforge.net #include "qgsproject.h" #include "qgsunittypes.h" #include "qgssettings.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgsfillsymbollayer.h" #include "qgsfillsymbol.h" #include "qgslinesymbol.h" @@ -78,8 +78,8 @@ void QgsDecorationScaleBar::projectRead() mPreferredSize = QgsProject::instance()->readNumEntry( mConfigurationName, QStringLiteral( "/PreferredSize" ), 30 ); mStyleIndex = QgsProject::instance()->readNumEntry( mConfigurationName, QStringLiteral( "/Style" ), 0 ); mSnapping = QgsProject::instance()->readBoolEntry( mConfigurationName, QStringLiteral( "/Snapping" ), true ); - mColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/Color" ), QStringLiteral( "#000000" ) ) ); - mOutlineColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QStringLiteral( "#FFFFFF" ) ) ); + mColor = QgsColorUtils::colorFromString( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/Color" ), QStringLiteral( "#000000" ) ) ); + mOutlineColor = QgsColorUtils::colorFromString( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QStringLiteral( "#FFFFFF" ) ) ); mMarginHorizontal = QgsProject::instance()->readNumEntry( mConfigurationName, QStringLiteral( "/MarginH" ), 0 ); mMarginVertical = QgsProject::instance()->readNumEntry( mConfigurationName, QStringLiteral( "/MarginV" ), 0 ); @@ -121,8 +121,8 @@ void QgsDecorationScaleBar::saveToProject() QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/PreferredSize" ), mPreferredSize ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Snapping" ), mSnapping ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Style" ), mStyleIndex ); - QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); - QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QgsSymbolLayerUtils::encodeColor( mOutlineColor ) ); + QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Color" ), QgsColorUtils::colorToString( mColor ) ); + QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/OutlineColor" ), QgsColorUtils::colorToString( mOutlineColor ) ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/MarginH" ), mMarginHorizontal ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/MarginV" ), mMarginVertical ); diff --git a/src/app/decorations/qgsdecorationtitle.cpp b/src/app/decorations/qgsdecorationtitle.cpp index fd8a83a86717..e70b85da9995 100644 --- a/src/app/decorations/qgsdecorationtitle.cpp +++ b/src/app/decorations/qgsdecorationtitle.cpp @@ -22,7 +22,7 @@ #include "qgslogger.h" #include "qgsproject.h" #include "qgsreadwritecontext.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgstextrenderer.h" #include @@ -52,7 +52,7 @@ void QgsDecorationTitle::projectRead() QgsDecorationItem::projectRead(); mLabelText = QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/Label" ), QString() ); - mBackgroundColor = QgsSymbolLayerUtils::decodeColor( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/BackgroundColor" ), QStringLiteral( "0,0,0,99" ) ) ); + mBackgroundColor = QgsColorUtils::colorFromString( QgsProject::instance()->readEntry( mConfigurationName, QStringLiteral( "/BackgroundColor" ), QStringLiteral( "0,0,0,99" ) ) ); mMarginHorizontal = QgsProject::instance()->readNumEntry( mConfigurationName, QStringLiteral( "/MarginH" ), 0 ); mMarginVertical = QgsProject::instance()->readNumEntry( mConfigurationName, QStringLiteral( "/MarginV" ), 0 ); @@ -75,7 +75,7 @@ void QgsDecorationTitle::saveToProject() QgsDecorationItem::saveToProject(); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/Label" ), mLabelText ); - QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/BackgroundColor" ), QgsSymbolLayerUtils::encodeColor( mBackgroundColor ) ); + QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/BackgroundColor" ), QgsColorUtils::colorToString( mBackgroundColor ) ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/MarginH" ), mMarginHorizontal ); QgsProject::instance()->writeEntry( mConfigurationName, QStringLiteral( "/MarginV" ), mMarginVertical ); diff --git a/src/core/editform/qgsattributeeditorelement.cpp b/src/core/editform/qgsattributeeditorelement.cpp index 213aa6016930..b4077ec2353c 100644 --- a/src/core/editform/qgsattributeeditorelement.cpp +++ b/src/core/editform/qgsattributeeditorelement.cpp @@ -24,7 +24,7 @@ #include "qgsattributeeditorrelation.h" #include "qgsattributeeditorspacerelement.h" #include "qgsattributeeditortextelement.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgsfontutils.h" QDomElement QgsAttributeEditorElement::toDomElement( QDomDocument &doc ) const @@ -134,7 +134,7 @@ void QgsAttributeEditorElement::LabelStyle::readXml( const QDomNode &node ) // Label font and color if ( element.hasAttribute( QStringLiteral( "labelColor" ) ) ) { - color = QgsSymbolLayerUtils::decodeColor( element.attribute( QStringLiteral( "labelColor" ) ) ); + color = QgsColorUtils::colorFromString( element.attribute( QStringLiteral( "labelColor" ) ) ); } QFont newFont; @@ -157,7 +157,7 @@ void QgsAttributeEditorElement::LabelStyle::readXml( const QDomNode &node ) QDomElement QgsAttributeEditorElement::LabelStyle::writeXml( QDomDocument &document ) const { QDomElement elem { document.createElement( QStringLiteral( "labelStyle" ) ) }; - elem.setAttribute( QStringLiteral( "labelColor" ), QgsSymbolLayerUtils::encodeColor( color ) ); + elem.setAttribute( QStringLiteral( "labelColor" ), QgsColorUtils::colorToString( color ) ); elem.appendChild( QgsFontUtils::toXmlElement( font, document, QStringLiteral( "labelFont" ) ) ); elem.setAttribute( QStringLiteral( "overrideLabelColor" ), overrideColor ? QChar( '1' ) : QChar( '0' ) ); elem.setAttribute( QStringLiteral( "overrideLabelFont" ), overrideFont ? QChar( '1' ) : QChar( '0' ) ); diff --git a/src/core/effects/qgscoloreffect.cpp b/src/core/effects/qgscoloreffect.cpp index 0df5e2721e67..ab9e420b4f10 100644 --- a/src/core/effects/qgscoloreffect.cpp +++ b/src/core/effects/qgscoloreffect.cpp @@ -16,8 +16,10 @@ ***************************************************************************/ #include "qgscoloreffect.h" +#include "qgscolorutils.h" #include "qgsimageoperation.h" -#include "qgssymbollayerutils.h" +#include "qgsrendercontext.h" + #include QgsPaintEffect *QgsColorEffect::create( const QVariantMap &map ) @@ -84,7 +86,7 @@ QVariantMap QgsColorEffect::properties() const props.insert( QStringLiteral( "saturation" ), QString::number( mSaturation ) ); props.insert( QStringLiteral( "grayscale_mode" ), QString::number( int( mGrayscaleMode ) ) ); props.insert( QStringLiteral( "colorize" ), mColorizeOn ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); - props.insert( QStringLiteral( "colorize_color" ), QgsSymbolLayerUtils::encodeColor( mColorizeColor ) ); + props.insert( QStringLiteral( "colorize_color" ), QgsColorUtils::colorToString( mColorizeColor ) ); props.insert( QStringLiteral( "colorize_strength" ), QString::number( mColorizeStrength ) ); return props; @@ -124,7 +126,7 @@ void QgsColorEffect::readProperties( const QVariantMap &props ) mColorizeOn = props.value( QStringLiteral( "colorize" ), QStringLiteral( "0" ) ).toInt(); if ( props.contains( QStringLiteral( "colorize_color" ) ) ) { - setColorizeColor( QgsSymbolLayerUtils::decodeColor( props.value( QStringLiteral( "colorize_color" ) ).toString() ) ); + setColorizeColor( QgsColorUtils::colorFromString( props.value( QStringLiteral( "colorize_color" ) ).toString() ) ); } mColorizeStrength = props.value( QStringLiteral( "colorize_strength" ), QStringLiteral( "100" ) ).toInt(); } diff --git a/src/core/effects/qgsgloweffect.cpp b/src/core/effects/qgsgloweffect.cpp index 57eb4de3e084..bb5d2ce055cc 100644 --- a/src/core/effects/qgsgloweffect.cpp +++ b/src/core/effects/qgsgloweffect.cpp @@ -17,6 +17,7 @@ #include "qgsgloweffect.h" #include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgsimageoperation.h" #include "qgscolorrampimpl.h" #include "qgsunittypes.h" @@ -121,7 +122,7 @@ QVariantMap QgsGlowEffect::properties() const props.insert( QStringLiteral( "spread_unit" ), QgsUnitTypes::encodeUnit( mSpreadUnit ) ); props.insert( QStringLiteral( "spread_unit_scale" ), QgsSymbolLayerUtils::encodeMapUnitScale( mSpreadMapUnitScale ) ); props.insert( QStringLiteral( "color_type" ), QString::number( static_cast< int >( mColorType ) ) ); - props.insert( QStringLiteral( "single_color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); + props.insert( QStringLiteral( "single_color" ), QgsColorUtils::colorToString( mColor ) ); if ( mRamp ) { @@ -183,7 +184,7 @@ void QgsGlowEffect::readProperties( const QVariantMap &props ) } if ( props.contains( QStringLiteral( "single_color" ) ) ) { - mColor = QgsSymbolLayerUtils::decodeColor( props.value( QStringLiteral( "single_color" ) ).toString() ); + mColor = QgsColorUtils::colorFromString( props.value( QStringLiteral( "single_color" ) ).toString() ); } //attempt to create color ramp from props diff --git a/src/core/effects/qgsshadoweffect.cpp b/src/core/effects/qgsshadoweffect.cpp index 23efbede778d..ed88f36f4aef 100644 --- a/src/core/effects/qgsshadoweffect.cpp +++ b/src/core/effects/qgsshadoweffect.cpp @@ -18,6 +18,7 @@ #include "qgsshadoweffect.h" #include "qgsimageoperation.h" #include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgsunittypes.h" QgsShadowEffect::QgsShadowEffect() @@ -111,7 +112,7 @@ QVariantMap QgsShadowEffect::properties() const props.insert( QStringLiteral( "offset_distance" ), QString::number( mOffsetDist ) ); props.insert( QStringLiteral( "offset_unit" ), QgsUnitTypes::encodeUnit( mOffsetUnit ) ); props.insert( QStringLiteral( "offset_unit_scale" ), QgsSymbolLayerUtils::encodeMapUnitScale( mOffsetMapUnitScale ) ); - props.insert( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); + props.insert( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) ); return props; } @@ -167,7 +168,7 @@ void QgsShadowEffect::readProperties( const QVariantMap &props ) mOffsetMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( props.value( QStringLiteral( "offset_unit_scale" ) ).toString() ); if ( props.contains( QStringLiteral( "color" ) ) ) { - mColor = QgsSymbolLayerUtils::decodeColor( props.value( QStringLiteral( "color" ) ).toString() ); + mColor = QgsColorUtils::colorFromString( props.value( QStringLiteral( "color" ) ).toString() ); } } diff --git a/src/core/labeling/qgslabelingenginesettings.cpp b/src/core/labeling/qgslabelingenginesettings.cpp index ceb5d4812ed6..64ebb776d940 100644 --- a/src/core/labeling/qgslabelingenginesettings.cpp +++ b/src/core/labeling/qgslabelingenginesettings.cpp @@ -16,7 +16,7 @@ #include "qgslabelingenginesettings.h" #include "qgsproject.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" QgsLabelingEngineSettings::QgsLabelingEngineSettings() { @@ -51,7 +51,7 @@ void QgsLabelingEngineSettings::readSettingsFromProject( QgsProject *prj ) if ( projectTextFormat >= 0 ) mDefaultTextRenderFormat = static_cast< Qgis::TextRenderFormat >( projectTextFormat ); - mUnplacedLabelColor = QgsSymbolLayerUtils::decodeColor( prj->readEntry( QStringLiteral( "PAL" ), QStringLiteral( "/UnplacedColor" ), QStringLiteral( "#ff0000" ) ) ); + mUnplacedLabelColor = QgsColorUtils::colorFromString( prj->readEntry( QStringLiteral( "PAL" ), QStringLiteral( "/UnplacedColor" ), QStringLiteral( "#ff0000" ) ) ); mPlacementVersion = static_cast< Qgis::LabelPlacementEngineVersion >( prj->readNumEntry( QStringLiteral( "PAL" ), QStringLiteral( "/PlacementEngineVersion" ), static_cast< int >( Qgis::LabelPlacementEngineVersion::Version1 ) ) ); } @@ -71,7 +71,7 @@ void QgsLabelingEngineSettings::writeSettingsToProject( QgsProject *project ) project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/TextFormat" ), static_cast< int >( mDefaultTextRenderFormat ) ); - project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/UnplacedColor" ), QgsSymbolLayerUtils::encodeColor( mUnplacedLabelColor ) ); + project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/UnplacedColor" ), QgsColorUtils::colorToString( mUnplacedLabelColor ) ); project->writeEntry( QStringLiteral( "PAL" ), QStringLiteral( "/PlacementEngineVersion" ), static_cast< int >( mPlacementVersion ) ); } diff --git a/src/core/labeling/qgspallabeling.cpp b/src/core/labeling/qgspallabeling.cpp index 7d2a34998e1d..fd3f5447dedb 100644 --- a/src/core/labeling/qgspallabeling.cpp +++ b/src/core/labeling/qgspallabeling.cpp @@ -16,6 +16,7 @@ ***************************************************************************/ #include "qgspallabeling.h" +#include "qgscolorutils.h" #include "qgstextlabelfeature.h" #include "qgsunittypes.h" #include "qgsexception.h" @@ -3134,7 +3135,7 @@ bool QgsPalLayerSettings::dataDefinedValEval( DataDefinedValueType valType, case DDColor: { QString colorstr = exprVal.toString().trimmed(); - QColor color = QgsSymbolLayerUtils::decodeColor( colorstr ); + QColor color = QgsColorUtils::colorFromString( colorstr ); if ( color.isValid() ) { @@ -3368,7 +3369,7 @@ void QgsPalLayerSettings::parseTextStyle( QFont &labelFont, // pass the rest on to QgsPalLabeling::drawLabeling // data defined font color? - dataDefinedValEval( DDColor, QgsPalLayerSettings::Color, exprVal, context.expressionContext(), QgsSymbolLayerUtils::encodeColor( mFormat.color() ) ); + dataDefinedValEval( DDColor, QgsPalLayerSettings::Color, exprVal, context.expressionContext(), QgsColorUtils::colorToString( mFormat.color() ) ); // data defined font opacity? dataDefinedValEval( DDOpacity, QgsPalLayerSettings::FontOpacity, exprVal, context.expressionContext(), mFormat.opacity() * 100 ); @@ -3428,7 +3429,7 @@ void QgsPalLayerSettings::parseTextBuffer( QgsRenderContext &context ) dataDefinedValEval( DDUnits, QgsPalLayerSettings::BufferUnit, exprVal, context.expressionContext() ); // data defined buffer color? - dataDefinedValEval( DDColor, QgsPalLayerSettings::BufferColor, exprVal, context.expressionContext(), QgsSymbolLayerUtils::encodeColor( buffer.color() ) ); + dataDefinedValEval( DDColor, QgsPalLayerSettings::BufferColor, exprVal, context.expressionContext(), QgsColorUtils::colorToString( buffer.color() ) ); // data defined buffer pen join style? dataDefinedValEval( DDJoinStyle, QgsPalLayerSettings::BufferJoinStyle, exprVal, context.expressionContext(), QgsSymbolLayerUtils::encodePenJoinStyle( buffer.joinStyle() ) ); @@ -3780,10 +3781,10 @@ void QgsPalLayerSettings::parseShapeBackground( QgsRenderContext &context ) dataDefinedValEval( DDBlendMode, QgsPalLayerSettings::ShapeBlendMode, exprVal, context.expressionContext() ); // data defined shape fill color? - dataDefinedValEval( DDColor, QgsPalLayerSettings::ShapeFillColor, exprVal, context.expressionContext(), QgsSymbolLayerUtils::encodeColor( background.fillColor() ) ); + dataDefinedValEval( DDColor, QgsPalLayerSettings::ShapeFillColor, exprVal, context.expressionContext(), QgsColorUtils::colorToString( background.fillColor() ) ); // data defined shape stroke color? - dataDefinedValEval( DDColor, QgsPalLayerSettings::ShapeStrokeColor, exprVal, context.expressionContext(), QgsSymbolLayerUtils::encodeColor( background.strokeColor() ) ); + dataDefinedValEval( DDColor, QgsPalLayerSettings::ShapeStrokeColor, exprVal, context.expressionContext(), QgsColorUtils::colorToString( background.strokeColor() ) ); // data defined shape stroke width? dataDefinedValEval( DDDoublePos, QgsPalLayerSettings::ShapeStrokeWidth, exprVal, context.expressionContext(), background.strokeWidth() ); @@ -3879,7 +3880,7 @@ void QgsPalLayerSettings::parseDropShadow( QgsRenderContext &context ) dataDefinedValEval( DDIntPos, QgsPalLayerSettings::ShadowScale, exprVal, context.expressionContext(), shadow.scale() ); // data defined shadow color? - dataDefinedValEval( DDColor, QgsPalLayerSettings::ShadowColor, exprVal, context.expressionContext(), QgsSymbolLayerUtils::encodeColor( shadow.color() ) ); + dataDefinedValEval( DDColor, QgsPalLayerSettings::ShadowColor, exprVal, context.expressionContext(), QgsColorUtils::colorToString( shadow.color() ) ); // data defined shadow blend mode? dataDefinedValEval( DDBlendMode, QgsPalLayerSettings::ShadowBlendMode, exprVal, context.expressionContext() ); diff --git a/src/core/layout/qgslayoutitemlegend.cpp b/src/core/layout/qgslayoutitemlegend.cpp index 3ed55d97dcb3..d25f53d36eb9 100644 --- a/src/core/layout/qgslayoutitemlegend.cpp +++ b/src/core/layout/qgslayoutitemlegend.cpp @@ -27,7 +27,7 @@ #include "qgslogger.h" #include "qgsmapsettings.h" #include "qgsproject.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgslayertreeutils.h" #include "qgslayoututils.h" #include "qgslayout.h" @@ -634,7 +634,7 @@ bool QgsLayoutItemLegend::writePropertiesToElement( QDomElement &legendElem, QDo legendElem.setAttribute( QStringLiteral( "symbolAlignment" ), mSettings.symbolAlignment() ); legendElem.setAttribute( QStringLiteral( "rasterBorder" ), mSettings.drawRasterStroke() ); - legendElem.setAttribute( QStringLiteral( "rasterBorderColor" ), QgsSymbolLayerUtils::encodeColor( mSettings.rasterStrokeColor() ) ); + legendElem.setAttribute( QStringLiteral( "rasterBorderColor" ), QgsColorUtils::colorToString( mSettings.rasterStrokeColor() ) ); legendElem.setAttribute( QStringLiteral( "rasterBorderWidth" ), QString::number( mSettings.rasterStrokeWidth() ) ); legendElem.setAttribute( QStringLiteral( "wmsLegendWidth" ), QString::number( mSettings.wmsLegendSize().width() ) ); @@ -774,7 +774,7 @@ bool QgsLayoutItemLegend::readPropertiesFromElement( const QDomElement &itemElem } mSettings.setDrawRasterStroke( itemElem.attribute( QStringLiteral( "rasterBorder" ), QStringLiteral( "1" ) ) != QLatin1String( "0" ) ); - mSettings.setRasterStrokeColor( QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "rasterBorderColor" ), QStringLiteral( "0,0,0" ) ) ) ); + mSettings.setRasterStrokeColor( QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "rasterBorderColor" ), QStringLiteral( "0,0,0" ) ) ) ); mSettings.setRasterStrokeWidth( itemElem.attribute( QStringLiteral( "rasterBorderWidth" ), QStringLiteral( "0" ) ).toDouble() ); mSettings.setWrapChar( itemElem.attribute( QStringLiteral( "wrapChar" ) ) ); diff --git a/src/core/layout/qgslayoutitemmapgrid.cpp b/src/core/layout/qgslayoutitemmapgrid.cpp index c8f21bf233ca..a1b5022a16ac 100644 --- a/src/core/layout/qgslayoutitemmapgrid.cpp +++ b/src/core/layout/qgslayoutitemmapgrid.cpp @@ -23,6 +23,7 @@ #include "qgsreadwritecontext.h" #include "qgsrendercontext.h" #include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgssymbol.h" #include "qgscoordinatereferencesystem.h" #include "qgslogger.h" @@ -277,9 +278,9 @@ bool QgsLayoutItemMapGrid::writeXml( QDomElement &elem, QDomDocument &doc, const mapGridElem.setAttribute( QStringLiteral( "gridFrameWidth" ), qgsDoubleToString( mGridFrameWidth ) ); mapGridElem.setAttribute( QStringLiteral( "gridFrameMargin" ), qgsDoubleToString( mGridFrameMargin ) ); mapGridElem.setAttribute( QStringLiteral( "gridFramePenThickness" ), qgsDoubleToString( mGridFramePenThickness ) ); - mapGridElem.setAttribute( QStringLiteral( "gridFramePenColor" ), QgsSymbolLayerUtils::encodeColor( mGridFramePenColor ) ); - mapGridElem.setAttribute( QStringLiteral( "frameFillColor1" ), QgsSymbolLayerUtils::encodeColor( mGridFrameFillColor1 ) ); - mapGridElem.setAttribute( QStringLiteral( "frameFillColor2" ), QgsSymbolLayerUtils::encodeColor( mGridFrameFillColor2 ) ); + mapGridElem.setAttribute( QStringLiteral( "gridFramePenColor" ), QgsColorUtils::colorToString( mGridFramePenColor ) ); + mapGridElem.setAttribute( QStringLiteral( "frameFillColor1" ), QgsColorUtils::colorToString( mGridFrameFillColor1 ) ); + mapGridElem.setAttribute( QStringLiteral( "frameFillColor2" ), QgsColorUtils::colorToString( mGridFrameFillColor2 ) ); mapGridElem.setAttribute( QStringLiteral( "leftFrameDivisions" ), mLeftFrameDivisions ); mapGridElem.setAttribute( QStringLiteral( "rightFrameDivisions" ), mRightFrameDivisions ); mapGridElem.setAttribute( QStringLiteral( "topFrameDivisions" ), mTopFrameDivisions ); @@ -347,9 +348,9 @@ bool QgsLayoutItemMapGrid::readXml( const QDomElement &itemElem, const QDomDocum mGridFrameWidth = itemElem.attribute( QStringLiteral( "gridFrameWidth" ), QStringLiteral( "2.0" ) ).toDouble(); mGridFrameMargin = itemElem.attribute( QStringLiteral( "gridFrameMargin" ), QStringLiteral( "0.0" ) ).toDouble(); mGridFramePenThickness = itemElem.attribute( QStringLiteral( "gridFramePenThickness" ), QStringLiteral( "0.3" ) ).toDouble(); - mGridFramePenColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "gridFramePenColor" ), QStringLiteral( "0,0,0" ) ) ); - mGridFrameFillColor1 = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "frameFillColor1" ), QStringLiteral( "255,255,255,255" ) ) ); - mGridFrameFillColor2 = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "frameFillColor2" ), QStringLiteral( "0,0,0,255" ) ) ); + mGridFramePenColor = QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "gridFramePenColor" ), QStringLiteral( "0,0,0" ) ) ); + mGridFrameFillColor1 = QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "frameFillColor1" ), QStringLiteral( "255,255,255,255" ) ) ); + mGridFrameFillColor2 = QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "frameFillColor2" ), QStringLiteral( "0,0,0,255" ) ) ); mLeftFrameDivisions = QgsLayoutItemMapGrid::DisplayMode( itemElem.attribute( QStringLiteral( "leftFrameDivisions" ), QStringLiteral( "0" ) ).toInt() ); mRightFrameDivisions = QgsLayoutItemMapGrid::DisplayMode( itemElem.attribute( QStringLiteral( "rightFrameDivisions" ), QStringLiteral( "0" ) ).toInt() ); mTopFrameDivisions = QgsLayoutItemMapGrid::DisplayMode( itemElem.attribute( QStringLiteral( "topFrameDivisions" ), QStringLiteral( "0" ) ).toInt() ); @@ -431,7 +432,7 @@ bool QgsLayoutItemMapGrid::readXml( const QDomElement &itemElem, const QDomDocum mAnnotationFormat.setFont( font ); mAnnotationFormat.setSize( font.pointSizeF() ); mAnnotationFormat.setSizeUnit( Qgis::RenderUnit::Points ); - mAnnotationFormat.setColor( QgsSymbolLayerUtils::decodeColor( itemElem.attribute( "annotationFontColor", "0,0,0,255" ) ) ); + mAnnotationFormat.setColor( QgsColorUtils::colorFromString( itemElem.attribute( "annotationFontColor", "0,0,0,255" ) ) ); } mGridAnnotationPrecision = itemElem.attribute( QStringLiteral( "annotationPrecision" ), QStringLiteral( "3" ) ).toInt(); diff --git a/src/core/layout/qgslayoutitempicture.cpp b/src/core/layout/qgslayoutitempicture.cpp index 8a03dfde61f2..1a9475947986 100644 --- a/src/core/layout/qgslayoutitempicture.cpp +++ b/src/core/layout/qgslayoutitempicture.cpp @@ -27,6 +27,7 @@ #include "qgsproperty.h" #include "qgsnetworkcontentfetcher.h" #include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgssvgcache.h" #include "qgslogger.h" #include "qgsreadwritecontext.h" @@ -792,8 +793,8 @@ bool QgsLayoutItemPicture::writePropertiesToElement( QDomElement &elem, QDomDocu elem.setAttribute( QStringLiteral( "pictureHeight" ), QString::number( mPictureHeight ) ); elem.setAttribute( QStringLiteral( "resizeMode" ), QString::number( static_cast< int >( mResizeMode ) ) ); elem.setAttribute( QStringLiteral( "anchorPoint" ), QString::number( static_cast< int >( mPictureAnchor ) ) ); - elem.setAttribute( QStringLiteral( "svgFillColor" ), QgsSymbolLayerUtils::encodeColor( mSvgFillColor ) ); - elem.setAttribute( QStringLiteral( "svgBorderColor" ), QgsSymbolLayerUtils::encodeColor( mSvgStrokeColor ) ); + elem.setAttribute( QStringLiteral( "svgFillColor" ), QgsColorUtils::colorToString( mSvgFillColor ) ); + elem.setAttribute( QStringLiteral( "svgBorderColor" ), QgsColorUtils::colorToString( mSvgStrokeColor ) ); elem.setAttribute( QStringLiteral( "svgBorderWidth" ), QString::number( mSvgStrokeWidth ) ); elem.setAttribute( QStringLiteral( "mode" ), mOriginalMode ); @@ -820,8 +821,8 @@ bool QgsLayoutItemPicture::readPropertiesFromElement( const QDomElement &itemEle //when loading from xml, default to anchor point of middle to match pre 2.4 behavior mPictureAnchor = static_cast< QgsLayoutItem::ReferencePoint >( itemElem.attribute( QStringLiteral( "anchorPoint" ), QString::number( QgsLayoutItem::Middle ) ).toInt() ); - mSvgFillColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "svgFillColor" ), QgsSymbolLayerUtils::encodeColor( QColor( 255, 255, 255 ) ) ) ); - mSvgStrokeColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "svgBorderColor" ), QgsSymbolLayerUtils::encodeColor( QColor( 0, 0, 0 ) ) ) ); + mSvgFillColor = QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "svgFillColor" ), QgsColorUtils::colorToString( QColor( 255, 255, 255 ) ) ) ); + mSvgStrokeColor = QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "svgBorderColor" ), QgsColorUtils::colorToString( QColor( 0, 0, 0 ) ) ) ); mSvgStrokeWidth = itemElem.attribute( QStringLiteral( "svgBorderWidth" ), QStringLiteral( "0.2" ) ).toDouble(); mOriginalMode = static_cast< Format >( itemElem.attribute( QStringLiteral( "mode" ), QString::number( FormatUnknown ) ).toInt() ); mMode = mOriginalMode; diff --git a/src/core/layout/qgslayoutitempolyline.cpp b/src/core/layout/qgslayoutitempolyline.cpp index 9d8b32e2a03e..73f0350b873c 100644 --- a/src/core/layout/qgslayoutitempolyline.cpp +++ b/src/core/layout/qgslayoutitempolyline.cpp @@ -17,6 +17,7 @@ #include "qgslayoutitempolyline.h" #include "qgslayoutitemregistry.h" #include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgssymbol.h" #include "qgslayout.h" #include "qgslayoutrendercontext.h" @@ -426,8 +427,8 @@ bool QgsLayoutItemPolyline::writePropertiesToElement( QDomElement &elmt, QDomDoc const QString endMarkerPath = QgsSymbolLayerUtils::svgSymbolPathToName( mEndMarkerFile, context.pathResolver() ); elmt.setAttribute( QStringLiteral( "arrowHeadWidth" ), QString::number( mArrowHeadWidth ) ); - elmt.setAttribute( QStringLiteral( "arrowHeadFillColor" ), QgsSymbolLayerUtils::encodeColor( mArrowHeadFillColor ) ); - elmt.setAttribute( QStringLiteral( "arrowHeadOutlineColor" ), QgsSymbolLayerUtils::encodeColor( mArrowHeadStrokeColor ) ); + elmt.setAttribute( QStringLiteral( "arrowHeadFillColor" ), QgsColorUtils::colorToString( mArrowHeadFillColor ) ); + elmt.setAttribute( QStringLiteral( "arrowHeadOutlineColor" ), QgsColorUtils::colorToString( mArrowHeadStrokeColor ) ); elmt.setAttribute( QStringLiteral( "outlineWidth" ), QString::number( mArrowHeadStrokeWidth ) ); elmt.setAttribute( QStringLiteral( "markerMode" ), mEndMarker ); elmt.setAttribute( QStringLiteral( "startMarkerMode" ), mStartMarker ); @@ -440,8 +441,8 @@ bool QgsLayoutItemPolyline::writePropertiesToElement( QDomElement &elmt, QDomDoc bool QgsLayoutItemPolyline::readPropertiesFromElement( const QDomElement &elmt, const QDomDocument &doc, const QgsReadWriteContext &context ) { mArrowHeadWidth = elmt.attribute( QStringLiteral( "arrowHeadWidth" ), QStringLiteral( "2.0" ) ).toDouble(); - mArrowHeadFillColor = QgsSymbolLayerUtils::decodeColor( elmt.attribute( QStringLiteral( "arrowHeadFillColor" ), QStringLiteral( "0,0,0,255" ) ) ); - mArrowHeadStrokeColor = QgsSymbolLayerUtils::decodeColor( elmt.attribute( QStringLiteral( "arrowHeadOutlineColor" ), QStringLiteral( "0,0,0,255" ) ) ); + mArrowHeadFillColor = QgsColorUtils::colorFromString( elmt.attribute( QStringLiteral( "arrowHeadFillColor" ), QStringLiteral( "0,0,0,255" ) ) ); + mArrowHeadStrokeColor = QgsColorUtils::colorFromString( elmt.attribute( QStringLiteral( "arrowHeadOutlineColor" ), QStringLiteral( "0,0,0,255" ) ) ); mArrowHeadStrokeWidth = elmt.attribute( QStringLiteral( "outlineWidth" ), QStringLiteral( "1.0" ) ).toDouble(); // relative paths to absolute const QString startMarkerPath = elmt.attribute( QStringLiteral( "startMarkerFile" ), QString() ); diff --git a/src/core/layout/qgslayouttable.cpp b/src/core/layout/qgslayouttable.cpp index 8a65fbf73ad5..86d49877935a 100644 --- a/src/core/layout/qgslayouttable.cpp +++ b/src/core/layout/qgslayouttable.cpp @@ -20,7 +20,7 @@ #include "qgslayouttable.h" #include "qgslayoututils.h" #include "qgslayouttablecolumn.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgslayoutframe.h" #include "qgsfontutils.h" #include "qgslayoutpagecollection.h" @@ -34,14 +34,14 @@ bool QgsLayoutTableStyle::writeXml( QDomElement &styleElem, QDomDocument &doc ) const { Q_UNUSED( doc ) - styleElem.setAttribute( QStringLiteral( "cellBackgroundColor" ), QgsSymbolLayerUtils::encodeColor( cellBackgroundColor ) ); + styleElem.setAttribute( QStringLiteral( "cellBackgroundColor" ), QgsColorUtils::colorToString( cellBackgroundColor ) ); styleElem.setAttribute( QStringLiteral( "enabled" ), enabled ); return true; } bool QgsLayoutTableStyle::readXml( const QDomElement &styleElem ) { - cellBackgroundColor = QgsSymbolLayerUtils::decodeColor( styleElem.attribute( QStringLiteral( "cellBackgroundColor" ), QStringLiteral( "255,255,255,255" ) ) ); + cellBackgroundColor = QgsColorUtils::colorFromString( styleElem.attribute( QStringLiteral( "cellBackgroundColor" ), QStringLiteral( "255,255,255,255" ) ) ); enabled = ( styleElem.attribute( QStringLiteral( "enabled" ), QStringLiteral( "0" ) ) != QLatin1String( "0" ) ); return true; } @@ -85,11 +85,11 @@ bool QgsLayoutTable::writePropertiesToElement( QDomElement &elem, QDomDocument & contentElem.appendChild( contentTextElem ); elem.appendChild( contentElem ); elem.setAttribute( QStringLiteral( "gridStrokeWidth" ), QString::number( mGridStrokeWidth ) ); - elem.setAttribute( QStringLiteral( "gridColor" ), QgsSymbolLayerUtils::encodeColor( mGridColor ) ); + elem.setAttribute( QStringLiteral( "gridColor" ), QgsColorUtils::colorToString( mGridColor ) ); elem.setAttribute( QStringLiteral( "horizontalGrid" ), mHorizontalGrid ); elem.setAttribute( QStringLiteral( "verticalGrid" ), mVerticalGrid ); elem.setAttribute( QStringLiteral( "showGrid" ), mShowGrid ); - elem.setAttribute( QStringLiteral( "backgroundColor" ), QgsSymbolLayerUtils::encodeColor( mBackgroundColor ) ); + elem.setAttribute( QStringLiteral( "backgroundColor" ), QgsColorUtils::colorToString( mBackgroundColor ) ); elem.setAttribute( QStringLiteral( "wrapBehavior" ), QString::number( static_cast< int >( mWrapBehavior ) ) ); // display columns @@ -150,7 +150,7 @@ bool QgsLayoutTable::readPropertiesFromElement( const QDomElement &itemElem, con { headerFont.fromString( itemElem.attribute( QStringLiteral( "headerFont" ), QString() ) ); } - QColor headerFontColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "headerFontColor" ), QStringLiteral( "0,0,0,255" ) ) ); + QColor headerFontColor = QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "headerFontColor" ), QStringLiteral( "0,0,0,255" ) ) ); mHeaderTextFormat.setFont( headerFont ); if ( headerFont.pointSizeF() > 0 ) { @@ -182,7 +182,7 @@ bool QgsLayoutTable::readPropertiesFromElement( const QDomElement &itemElem, con { contentFont.fromString( itemElem.attribute( QStringLiteral( "contentFont" ), QString() ) ); } - QColor contentFontColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "contentFontColor" ), QStringLiteral( "0,0,0,255" ) ) ); + QColor contentFontColor = QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "contentFontColor" ), QStringLiteral( "0,0,0,255" ) ) ); mContentTextFormat.setFont( contentFont ); if ( contentFont.pointSizeF() > 0 ) { @@ -202,8 +202,8 @@ bool QgsLayoutTable::readPropertiesFromElement( const QDomElement &itemElem, con mHorizontalGrid = itemElem.attribute( QStringLiteral( "horizontalGrid" ), QStringLiteral( "1" ) ).toInt(); mVerticalGrid = itemElem.attribute( QStringLiteral( "verticalGrid" ), QStringLiteral( "1" ) ).toInt(); mShowGrid = itemElem.attribute( QStringLiteral( "showGrid" ), QStringLiteral( "1" ) ).toInt(); - mGridColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "gridColor" ), QStringLiteral( "0,0,0,255" ) ) ); - mBackgroundColor = QgsSymbolLayerUtils::decodeColor( itemElem.attribute( QStringLiteral( "backgroundColor" ), QStringLiteral( "255,255,255,0" ) ) ); + mGridColor = QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "gridColor" ), QStringLiteral( "0,0,0,255" ) ) ); + mBackgroundColor = QgsColorUtils::colorFromString( itemElem.attribute( QStringLiteral( "backgroundColor" ), QStringLiteral( "255,255,255,0" ) ) ); mWrapBehavior = QgsLayoutTable::WrapBehavior( itemElem.attribute( QStringLiteral( "wrapBehavior" ), QStringLiteral( "0" ) ).toInt() ); //restore display column specifications diff --git a/src/core/mesh/qgsmeshrenderersettings.cpp b/src/core/mesh/qgsmeshrenderersettings.cpp index dd247e7f9ac6..2289d9c8c96b 100644 --- a/src/core/mesh/qgsmeshrenderersettings.cpp +++ b/src/core/mesh/qgsmeshrenderersettings.cpp @@ -16,7 +16,7 @@ ***************************************************************************/ #include "qgsmeshrenderersettings.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgsunittypes.h" bool QgsMeshRendererMeshSettings::isEnabled() const @@ -64,7 +64,7 @@ QDomElement QgsMeshRendererMeshSettings::writeXml( QDomDocument &doc ) const QDomElement elem = doc.createElement( QStringLiteral( "mesh-settings" ) ); elem.setAttribute( QStringLiteral( "enabled" ), mEnabled ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); elem.setAttribute( QStringLiteral( "line-width" ), mLineWidth ); - elem.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); + elem.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) ); elem.setAttribute( QStringLiteral( "line-width-unit" ), QgsUnitTypes::encodeUnit( mLineWidthUnit ) ); return elem; } @@ -73,7 +73,7 @@ void QgsMeshRendererMeshSettings::readXml( const QDomElement &elem ) { mEnabled = elem.attribute( QStringLiteral( "enabled" ) ).toInt(); mLineWidth = elem.attribute( QStringLiteral( "line-width" ) ).toDouble(); - mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "color" ) ) ); + mColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "color" ) ) ); mLineWidthUnit = QgsUnitTypes::decodeRenderUnit( elem.attribute( QStringLiteral( "line-width-unit" ) ) ); } // --------------------------------------------------------------------- @@ -599,7 +599,7 @@ QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc, const Qg elem.setAttribute( QStringLiteral( "line-width" ), mLineWidth ); elem.setAttribute( QStringLiteral( "coloring-method" ), coloringMethod() ); - elem.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); + elem.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) ); const QDomElement elemShader = mColorRampShader.writeXml( doc, context ); elem.appendChild( elemShader ); elem.setAttribute( QStringLiteral( "filter-min" ), mFilterMin ); @@ -624,7 +624,7 @@ void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem, const QgsR mLineWidth = elem.attribute( QStringLiteral( "line-width" ) ).toDouble(); mColoringMethod = static_cast( elem.attribute( QStringLiteral( "coloring-method" ) ).toInt() ); - mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "color" ) ) ); + mColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "color" ) ) ); mColorRampShader.readXml( elem.firstChildElement( "colorrampshader" ), context ); mFilterMin = elem.attribute( QStringLiteral( "filter-min" ) ).toDouble(); mFilterMax = elem.attribute( QStringLiteral( "filter-max" ) ).toDouble(); diff --git a/src/core/pointcloud/qgspointcloudclassifiedrenderer.cpp b/src/core/pointcloud/qgspointcloudclassifiedrenderer.cpp index 187f83e16fe7..0bb910151c3c 100644 --- a/src/core/pointcloud/qgspointcloudclassifiedrenderer.cpp +++ b/src/core/pointcloud/qgspointcloudclassifiedrenderer.cpp @@ -19,7 +19,7 @@ #include "qgspointcloudblock.h" #include "qgsstyle.h" #include "qgscolorramp.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgslayertreemodellegendnode.h" #include "qgspointclouddataprovider.h" @@ -200,7 +200,7 @@ QgsPointCloudRenderer *QgsPointCloudClassifiedRenderer::create( QDomElement &ele const double size = catElem.attribute( QStringLiteral( "pointSize" ), QStringLiteral( "0" ) ).toDouble(); const QString label = catElem.attribute( QStringLiteral( "label" ) ); const bool render = catElem.attribute( QStringLiteral( "render" ) ) != QLatin1String( "false" ); - const QColor color = QgsSymbolLayerUtils::decodeColor( catElem.attribute( QStringLiteral( "color" ) ) ); + const QColor color = QgsColorUtils::colorFromString( catElem.attribute( QStringLiteral( "color" ) ) ); categories.append( QgsPointCloudCategory( value, color, label, render, size ) ); } catElem = catElem.nextSiblingElement(); @@ -251,7 +251,7 @@ QDomElement QgsPointCloudClassifiedRenderer::save( QDomDocument &doc, const QgsR catElem.setAttribute( QStringLiteral( "value" ), QString::number( category.value() ) ); catElem.setAttribute( QStringLiteral( "pointSize" ), QString::number( category.pointSize() ) ); catElem.setAttribute( QStringLiteral( "label" ), category.label() ); - catElem.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( category.color() ) ); + catElem.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( category.color() ) ); catElem.setAttribute( QStringLiteral( "render" ), category.renderState() ? "true" : "false" ); catsElem.appendChild( catElem ); } diff --git a/src/core/pointcloud/qgspointcloudlayerelevationproperties.cpp b/src/core/pointcloud/qgspointcloudlayerelevationproperties.cpp index cf21d49a8097..da894c426fa0 100644 --- a/src/core/pointcloud/qgspointcloudlayerelevationproperties.cpp +++ b/src/core/pointcloud/qgspointcloudlayerelevationproperties.cpp @@ -17,9 +17,9 @@ #include "qgspointcloudlayerelevationproperties.h" #include "qgspointcloudlayer.h" -#include "qgssymbollayerutils.h" #include "qgsapplication.h" #include "qgscolorschemeregistry.h" +#include "qgscolorutils.h" QgsPointCloudLayerElevationProperties::QgsPointCloudLayerElevationProperties( QObject *parent ) : QgsMapLayerElevationProperties( parent ) @@ -51,7 +51,7 @@ QDomElement QgsPointCloudLayerElevationProperties::writeXml( QDomElement &parent element.setAttribute( QStringLiteral( "point_size" ), qgsDoubleToString( mPointSize ) ); element.setAttribute( QStringLiteral( "point_size_unit" ), QgsUnitTypes::encodeUnit( mPointSizeUnit ) ); element.setAttribute( QStringLiteral( "point_symbol" ), qgsEnumValueToKey( mPointSymbol ) ); - element.setAttribute( QStringLiteral( "point_color" ), QgsSymbolLayerUtils::encodeColor( mPointColor ) ); + element.setAttribute( QStringLiteral( "point_color" ), QgsColorUtils::colorToString( mPointColor ) ); element.setAttribute( QStringLiteral( "respect_layer_colors" ), mRespectLayerColors ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); element.setAttribute( QStringLiteral( "opacity_by_distance" ), mApplyOpacityByDistanceEffect ? QStringLiteral( "1" ) : QStringLiteral( "0" ) ); @@ -77,7 +77,7 @@ bool QgsPointCloudLayerElevationProperties::readXml( const QDomElement &element, const QString colorString = elevationElement.attribute( QStringLiteral( "point_color" ) ); if ( !colorString.isEmpty() ) { - mPointColor = QgsSymbolLayerUtils::decodeColor( elevationElement.attribute( QStringLiteral( "point_color" ) ) ); + mPointColor = QgsColorUtils::colorFromString( elevationElement.attribute( QStringLiteral( "point_color" ) ) ); } else { diff --git a/src/core/processing/models/qgsprocessingmodelcomponent.cpp b/src/core/processing/models/qgsprocessingmodelcomponent.cpp index 46c45d5fbb81..212244786b02 100644 --- a/src/core/processing/models/qgsprocessingmodelcomponent.cpp +++ b/src/core/processing/models/qgsprocessingmodelcomponent.cpp @@ -17,7 +17,7 @@ #include "qgsprocessingmodelcomponent.h" #include "qgsprocessingmodelcomment.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" ///@cond NOT_STABLE @@ -114,7 +114,7 @@ void QgsProcessingModelComponent::saveCommonProperties( QVariantMap &map ) const map.insert( QStringLiteral( "component_height" ), mSize.height() ); map.insert( QStringLiteral( "parameters_collapsed" ), mTopEdgeLinksCollapsed ); map.insert( QStringLiteral( "outputs_collapsed" ), mBottomEdgeLinksCollapsed ); - map.insert( QStringLiteral( "color" ), mColor.isValid() ? QgsSymbolLayerUtils::encodeColor( mColor ) : QString() ); + map.insert( QStringLiteral( "color" ), mColor.isValid() ? QgsColorUtils::colorToString( mColor ) : QString() ); const QgsProcessingModelComment *thisComment = comment(); if ( thisComment ) map.insert( QStringLiteral( "comment" ), thisComment->toVariant() ); @@ -129,7 +129,7 @@ void QgsProcessingModelComponent::restoreCommonProperties( const QVariantMap &ma mDescription = map.value( QStringLiteral( "component_description" ) ).toString(); mSize.setWidth( map.value( QStringLiteral( "component_width" ), QString::number( DEFAULT_COMPONENT_WIDTH ) ).toDouble() ); mSize.setHeight( map.value( QStringLiteral( "component_height" ), QString::number( DEFAULT_COMPONENT_HEIGHT ) ).toDouble() ); - mColor = map.value( QStringLiteral( "color" ) ).toString().isEmpty() ? QColor() : QgsSymbolLayerUtils::decodeColor( map.value( QStringLiteral( "color" ) ).toString() ); + mColor = map.value( QStringLiteral( "color" ) ).toString().isEmpty() ? QColor() : QgsColorUtils::colorFromString( map.value( QStringLiteral( "color" ) ).toString() ); mTopEdgeLinksCollapsed = map.value( QStringLiteral( "parameters_collapsed" ) ).toBool(); mBottomEdgeLinksCollapsed = map.value( QStringLiteral( "outputs_collapsed" ) ).toBool(); QgsProcessingModelComment *thisComment = comment(); diff --git a/src/core/project/qgsproject.cpp b/src/core/project/qgsproject.cpp index 82fb001becde..7acf396f7d35 100644 --- a/src/core/project/qgsproject.cpp +++ b/src/core/project/qgsproject.cpp @@ -51,7 +51,7 @@ #include "qgsmaplayerstore.h" #include "qgsziputils.h" #include "qgsauxiliarystorage.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgsapplication.h" #include "qgsexpressioncontextutils.h" #include "qgsstyleentityvisitor.h" @@ -4836,7 +4836,7 @@ void QgsProject::setProjectColors( const QgsNamedColorList &colors ) QgsNamedColorList::const_iterator colorIt = colors.constBegin(); for ( ; colorIt != colors.constEnd(); ++colorIt ) { - const QString color = QgsSymbolLayerUtils::encodeColor( ( *colorIt ).first ); + const QString color = QgsColorUtils::colorToString( ( *colorIt ).first ); const QString label = ( *colorIt ).second; customColors.append( color ); customColorLabels.append( label ); @@ -5025,7 +5025,7 @@ GetNamedProjectColor::GetNamedProjectColor( const QgsProject *project ) for ( QStringList::iterator it = colorStrings.begin(); it != colorStrings.end(); ++it ) { - const QColor color = QgsSymbolLayerUtils::decodeColor( *it ); + const QColor color = QgsColorUtils::colorFromString( *it ); QString label; if ( colorLabels.length() > colorIndex ) { diff --git a/src/core/qgscolorrampimpl.cpp b/src/core/qgscolorrampimpl.cpp index afa6b4ac305c..fff5b34e1919 100644 --- a/src/core/qgscolorrampimpl.cpp +++ b/src/core/qgscolorrampimpl.cpp @@ -17,8 +17,8 @@ #include "qgscolorbrewerpalette.h" #include "qgscptcityarchive.h" -#include "qgssymbollayerutils.h" #include "qgsapplication.h" +#include "qgscolorutils.h" #include "qgslogger.h" #include @@ -221,9 +221,9 @@ QgsColorRamp *QgsGradientColorRamp::create( const QVariantMap &props ) QColor color1 = DEFAULT_GRADIENT_COLOR1; QColor color2 = DEFAULT_GRADIENT_COLOR2; if ( props.contains( QStringLiteral( "color1" ) ) ) - color1 = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color1" )].toString() ); + color1 = QgsColorUtils::colorFromString( props[QStringLiteral( "color1" )].toString() ); if ( props.contains( QStringLiteral( "color2" ) ) ) - color2 = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color2" )].toString() ); + color2 = QgsColorUtils::colorFromString( props[QStringLiteral( "color2" )].toString() ); //stops QgsGradientStopsList stops; @@ -236,7 +236,7 @@ QgsColorRamp *QgsGradientColorRamp::create( const QVariantMap &props ) if ( parts.size() != 2 && parts.size() != 4 ) continue; - QColor c = QgsSymbolLayerUtils::decodeColor( parts.at( 1 ) ); + QColor c = QgsColorUtils::colorFromString( parts.at( 1 ) ); stops.append( QgsGradientStop( parts.at( 0 ).toDouble(), c ) ); if ( parts.size() == 4 ) @@ -427,15 +427,15 @@ QgsGradientColorRamp *QgsGradientColorRamp::clone() const QVariantMap QgsGradientColorRamp::properties() const { QVariantMap map; - map[QStringLiteral( "color1" )] = QgsSymbolLayerUtils::encodeColor( mColor1 ); - map[QStringLiteral( "color2" )] = QgsSymbolLayerUtils::encodeColor( mColor2 ); + map[QStringLiteral( "color1" )] = QgsColorUtils::colorToString( mColor1 ); + map[QStringLiteral( "color2" )] = QgsColorUtils::colorToString( mColor2 ); if ( !mStops.isEmpty() ) { QStringList lst; lst.reserve( mStops.size() ); for ( const QgsGradientStop &stop : mStops ) { - lst.append( QStringLiteral( "%1;%2;%3;%4" ).arg( stop.offset ).arg( QgsSymbolLayerUtils::encodeColor( stop.color ), + lst.append( QStringLiteral( "%1;%2;%3;%4" ).arg( stop.offset ).arg( QgsColorUtils::colorToString( stop.color ), stop.colorSpec() == QColor::Rgb ? QStringLiteral( "rgb" ) : stop.colorSpec() == QColor::Hsv ? QStringLiteral( "hsv" ) : stop.colorSpec() == QColor::Hsl ? QStringLiteral( "hsl" ) : QString(), @@ -1171,7 +1171,7 @@ QgsColorRamp *QgsPresetSchemeColorRamp::create( const QVariantMap &properties ) QString colorName = properties.value( QStringLiteral( "preset_color_name_%1" ).arg( i ), QString() ).toString(); while ( !colorString.isEmpty() ) { - colors << qMakePair( QgsSymbolLayerUtils::decodeColor( colorString ), colorName ); + colors << qMakePair( QgsColorUtils::colorFromString( colorString ), colorName ); i++; colorString = properties.value( QStringLiteral( "preset_color_%1" ).arg( i ), QString() ).toString(); colorName = properties.value( QStringLiteral( "preset_color_name_%1" ).arg( i ), QString() ).toString(); @@ -1238,7 +1238,7 @@ QVariantMap QgsPresetSchemeColorRamp::properties() const QVariantMap props; for ( int i = 0; i < mColors.count(); ++i ) { - props.insert( QStringLiteral( "preset_color_%1" ).arg( i ), QgsSymbolLayerUtils::encodeColor( mColors.at( i ).first ) ); + props.insert( QStringLiteral( "preset_color_%1" ).arg( i ), QgsColorUtils::colorToString( mColors.at( i ).first ) ); props.insert( QStringLiteral( "preset_color_name_%1" ).arg( i ), mColors.at( i ).second ); } props[QStringLiteral( "rampType" )] = type(); diff --git a/src/core/qgsdatadefinedsizelegend.cpp b/src/core/qgsdatadefinedsizelegend.cpp index 38a4d3712fa7..d9420824c772 100644 --- a/src/core/qgsdatadefinedsizelegend.cpp +++ b/src/core/qgsdatadefinedsizelegend.cpp @@ -25,6 +25,7 @@ #include "qgsmarkersymbol.h" #include "qgslinesymbol.h" #include "qgsfontutils.h" +#include "qgscolorutils.h" QgsDataDefinedSizeLegend::QgsDataDefinedSizeLegend() { @@ -401,7 +402,7 @@ QgsDataDefinedSizeLegend *QgsDataDefinedSizeLegend::readXml( const QDomElement & ddsLegend->setFont( QgsFontUtils::createFont( elemFont.attribute( QStringLiteral( "family" ) ), elemFont.attribute( QStringLiteral( "size" ) ).toInt(), elemFont.attribute( QStringLiteral( "weight" ) ).toInt(), elemFont.attribute( QStringLiteral( "italic" ) ).toInt() ) ); } - ddsLegend->setTextColor( QgsSymbolLayerUtils::decodeColor( elemTextStyle.attribute( QStringLiteral( "color" ) ) ) ); + ddsLegend->setTextColor( QgsColorUtils::colorFromString( elemTextStyle.attribute( QStringLiteral( "color" ) ) ) ); ddsLegend->setTextAlignment( static_cast( elemTextStyle.attribute( QStringLiteral( "align" ) ).toInt() ) ); } @@ -456,7 +457,7 @@ void QgsDataDefinedSizeLegend::writeXml( QDomElement &elem, const QgsReadWriteCo elemFont.setAttribute( QStringLiteral( "italic" ), mFont.italic() ); QDomElement elemTextStyle = doc.createElement( QStringLiteral( "text-style" ) ); - elemTextStyle.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mTextColor ) ); + elemTextStyle.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( mTextColor ) ); elemTextStyle.setAttribute( QStringLiteral( "align" ), static_cast( mTextAlignment ) ); elemTextStyle.appendChild( elemFont ); elem.appendChild( elemTextStyle ); diff --git a/src/core/qgsdiagramrenderer.cpp b/src/core/qgsdiagramrenderer.cpp index a9a3ae4b7089..a9fbb7283f50 100644 --- a/src/core/qgsdiagramrenderer.cpp +++ b/src/core/qgsdiagramrenderer.cpp @@ -14,6 +14,7 @@ ***************************************************************************/ #include "qgsdiagramrenderer.h" +#include "qgscolorutils.h" #include "qgsdatadefinedsizelegend.h" #include "diagram/qgstextdiagram.h" #include "diagram/qgspiediagram.h" @@ -474,9 +475,9 @@ void QgsDiagramRenderer::renderDiagram( const QgsFeature &feature, QgsRenderCont if ( properties.hasActiveProperties() ) { - c.expressionContext().setOriginalValueVariable( QgsSymbolLayerUtils::encodeColor( s.backgroundColor ) ); + c.expressionContext().setOriginalValueVariable( QgsColorUtils::colorToString( s.backgroundColor ) ); s.backgroundColor = properties.valueAsColor( QgsDiagramLayerSettings::BackgroundColor, c.expressionContext(), s.backgroundColor ); - c.expressionContext().setOriginalValueVariable( QgsSymbolLayerUtils::encodeColor( s.penColor ) ); + c.expressionContext().setOriginalValueVariable( QgsColorUtils::colorToString( s.penColor ) ); s.penColor = properties.valueAsColor( QgsDiagramLayerSettings::StrokeColor, c.expressionContext(), s.penColor ); c.expressionContext().setOriginalValueVariable( s.penWidth ); s.penWidth = properties.valueAsDouble( QgsDiagramLayerSettings::StrokeWidth, c.expressionContext(), s.penWidth ); diff --git a/src/core/qgspropertytransformer.cpp b/src/core/qgspropertytransformer.cpp index bd04c6397232..05b80caf1ee7 100644 --- a/src/core/qgspropertytransformer.cpp +++ b/src/core/qgspropertytransformer.cpp @@ -20,6 +20,7 @@ #include "qgsexpressionnodeimpl.h" #include "qgssymbollayerutils.h" #include "qgscolorramp.h" +#include "qgscolorutils.h" #include "qgspointxy.h" @@ -571,7 +572,7 @@ QVariant QgsColorRampTransformer::toVariant() const { transformerMap.insert( QStringLiteral( "colorramp" ), QgsSymbolLayerUtils::colorRampToVariant( QStringLiteral( "[source]" ), mGradientRamp.get() ) ); } - transformerMap.insert( QStringLiteral( "nullColor" ), QgsSymbolLayerUtils::encodeColor( mNullColor ) ); + transformerMap.insert( QStringLiteral( "nullColor" ), QgsColorUtils::colorToString( mNullColor ) ); transformerMap.insert( QStringLiteral( "rampName" ), mRampName ); return transformerMap; @@ -589,7 +590,7 @@ bool QgsColorRampTransformer::loadVariant( const QVariant &definition ) setColorRamp( QgsSymbolLayerUtils::loadColorRamp( transformerMap.value( QStringLiteral( "colorramp" ) ).toMap() ) ); } - mNullColor = QgsSymbolLayerUtils::decodeColor( transformerMap.value( QStringLiteral( "nullColor" ), QStringLiteral( "0,0,0,0" ) ).toString() ); + mNullColor = QgsColorUtils::colorFromString( transformerMap.value( QStringLiteral( "nullColor" ), QStringLiteral( "0,0,0,0" ) ).toString() ); mRampName = transformerMap.value( QStringLiteral( "rampName" ) ).toString(); return true; } diff --git a/src/core/qgsxmlutils.cpp b/src/core/qgsxmlutils.cpp index a0c2b6b6df37..36afec760928 100644 --- a/src/core/qgsxmlutils.cpp +++ b/src/core/qgsxmlutils.cpp @@ -18,7 +18,7 @@ #include "qgsrectangle.h" #include "qgsproperty.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgsprocessingparameters.h" #include "qgsremappingproxyfeaturesink.h" #include "qgsunittypes.h" @@ -212,7 +212,7 @@ QDomElement QgsXmlUtils::writeVariant( const QVariant &value, QDomDocument &doc case QVariant::Color: element.setAttribute( QStringLiteral( "type" ), QStringLiteral( "color" ) ); - element.setAttribute( QStringLiteral( "value" ), value.value< QColor >().isValid() ? QgsSymbolLayerUtils::encodeColor( value.value< QColor >() ) : QString() ); + element.setAttribute( QStringLiteral( "value" ), value.value< QColor >().isValid() ? QgsColorUtils::colorToString( value.value< QColor >() ) : QString() ); break; case QVariant::DateTime: @@ -329,7 +329,7 @@ QVariant QgsXmlUtils::readVariant( const QDomElement &element ) } else if ( type == QLatin1String( "color" ) ) { - return element.attribute( QStringLiteral( "value" ) ).isEmpty() ? QColor() : QgsSymbolLayerUtils::decodeColor( element.attribute( QStringLiteral( "value" ) ) ); + return element.attribute( QStringLiteral( "value" ) ).isEmpty() ? QColor() : QgsColorUtils::colorFromString( element.attribute( QStringLiteral( "value" ) ) ); } else if ( type == QLatin1String( "datetime" ) ) { diff --git a/src/core/raster/qgsrasterrenderer.cpp b/src/core/raster/qgsrasterrenderer.cpp index c95bd1d757fb..87e47e30a9b2 100644 --- a/src/core/raster/qgsrasterrenderer.cpp +++ b/src/core/raster/qgsrasterrenderer.cpp @@ -18,7 +18,7 @@ #include "qgsrasterrenderer.h" #include "qgsrastertransparency.h" -#include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include "qgslayertreemodellegendnode.h" #include @@ -155,7 +155,7 @@ void QgsRasterRenderer::_writeXml( QDomDocument &doc, QDomElement &rasterRendere rasterRendererElem.setAttribute( QStringLiteral( "type" ), mType ); rasterRendererElem.setAttribute( QStringLiteral( "opacity" ), QString::number( mOpacity ) ); rasterRendererElem.setAttribute( QStringLiteral( "alphaBand" ), mAlphaBand ); - rasterRendererElem.setAttribute( QStringLiteral( "nodataColor" ), mNodataColor.isValid() ? QgsSymbolLayerUtils::encodeColor( mNodataColor ) : QString() ); + rasterRendererElem.setAttribute( QStringLiteral( "nodataColor" ), mNodataColor.isValid() ? QgsColorUtils::colorToString( mNodataColor ) : QString() ); if ( mRasterTransparency ) { @@ -186,7 +186,7 @@ void QgsRasterRenderer::readXml( const QDomElement &rendererElem ) mOpacity = rendererElem.attribute( QStringLiteral( "opacity" ), QStringLiteral( "1.0" ) ).toDouble(); mAlphaBand = rendererElem.attribute( QStringLiteral( "alphaBand" ), QStringLiteral( "-1" ) ).toInt(); const QString colorEncoded = rendererElem.attribute( QStringLiteral( "nodataColor" ) ); - mNodataColor = !colorEncoded.isEmpty() ? QgsSymbolLayerUtils::decodeColor( colorEncoded ) : QColor(); + mNodataColor = !colorEncoded.isEmpty() ? QgsColorUtils::colorFromString( colorEncoded ) : QColor(); const QDomElement rasterTransparencyElem = rendererElem.firstChildElement( QStringLiteral( "rasterTransparency" ) ); if ( !rasterTransparencyElem.isNull() ) diff --git a/src/core/symbology/qgsellipsesymbollayer.cpp b/src/core/symbology/qgsellipsesymbollayer.cpp index 9e4107501871..dba14cb6ac3c 100644 --- a/src/core/symbology/qgsellipsesymbollayer.cpp +++ b/src/core/symbology/qgsellipsesymbollayer.cpp @@ -12,6 +12,7 @@ * (at your option) any later version. * * * ***************************************************************************/ + #include "qgsellipsesymbollayer.h" #include "qgsdxfexport.h" #include "qgsfeature.h" @@ -20,6 +21,7 @@ #include "qgsunittypes.h" #include "qgsproperty.h" #include "qgssymbollayerutils.h" +#include "qgscolorutils.h" #include #include @@ -128,19 +130,19 @@ QgsSymbolLayer *QgsEllipseSymbolLayer::create( const QVariantMap &properties ) if ( properties.contains( QStringLiteral( "fill_color" ) ) ) { //pre 2.5 projects used "fill_color" - layer->setFillColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "fill_color" )].toString() ) ); + layer->setFillColor( QgsColorUtils::colorFromString( properties[QStringLiteral( "fill_color" )].toString() ) ); } else if ( properties.contains( QStringLiteral( "color" ) ) ) { - layer->setFillColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "color" )].toString() ) ); + layer->setFillColor( QgsColorUtils::colorFromString( properties[QStringLiteral( "color" )].toString() ) ); } if ( properties.contains( QStringLiteral( "outline_color" ) ) ) { - layer->setStrokeColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "outline_color" )].toString() ) ); + layer->setStrokeColor( QgsColorUtils::colorFromString( properties[QStringLiteral( "outline_color" )].toString() ) ); } else if ( properties.contains( QStringLiteral( "line_color" ) ) ) { - layer->setStrokeColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "line_color" )].toString() ) ); + layer->setStrokeColor( QgsColorUtils::colorFromString( properties[QStringLiteral( "line_color" )].toString() ) ); } if ( properties.contains( QStringLiteral( "offset" ) ) ) { @@ -553,8 +555,8 @@ QVariantMap QgsEllipseSymbolLayer::properties() const map[QStringLiteral( "outline_width_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mStrokeWidthMapUnitScale ); map[QStringLiteral( "joinstyle" )] = QgsSymbolLayerUtils::encodePenJoinStyle( mPenJoinStyle ); map[QStringLiteral( "cap_style" )] = QgsSymbolLayerUtils::encodePenCapStyle( mPenCapStyle ); - map[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mColor ); - map[QStringLiteral( "outline_color" )] = QgsSymbolLayerUtils::encodeColor( mStrokeColor ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( mColor ); + map[QStringLiteral( "outline_color" )] = QgsColorUtils::colorToString( mStrokeColor ); map[QStringLiteral( "offset" )] = QgsSymbolLayerUtils::encodePoint( mOffset ); map[QStringLiteral( "offset_unit" )] = QgsUnitTypes::encodeUnit( mOffsetUnit ); map[QStringLiteral( "offset_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mOffsetMapUnitScale ); diff --git a/src/core/symbology/qgsfillsymbollayer.cpp b/src/core/symbology/qgsfillsymbollayer.cpp index b57f7ee2ddf7..e1f082286fa2 100644 --- a/src/core/symbology/qgsfillsymbollayer.cpp +++ b/src/core/symbology/qgsfillsymbollayer.cpp @@ -38,6 +38,7 @@ #include "qgslinesymbol.h" #include "qgsfeedback.h" #include "qgsgeometryengine.h" +#include "qgscolorutils.h" #include #include @@ -178,21 +179,21 @@ QgsSymbolLayer *QgsSimpleFillSymbolLayer::create( const QVariantMap &props ) QPointF offset; if ( props.contains( QStringLiteral( "color" ) ) ) - color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color" )].toString() ); + color = QgsColorUtils::colorFromString( props[QStringLiteral( "color" )].toString() ); if ( props.contains( QStringLiteral( "style" ) ) ) style = QgsSymbolLayerUtils::decodeBrushStyle( props[QStringLiteral( "style" )].toString() ); if ( props.contains( QStringLiteral( "color_border" ) ) ) { //pre 2.5 projects used "color_border" - strokeColor = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color_border" )].toString() ); + strokeColor = QgsColorUtils::colorFromString( props[QStringLiteral( "color_border" )].toString() ); } else if ( props.contains( QStringLiteral( "outline_color" ) ) ) { - strokeColor = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "outline_color" )].toString() ); + strokeColor = QgsColorUtils::colorFromString( props[QStringLiteral( "outline_color" )].toString() ); } else if ( props.contains( QStringLiteral( "line_color" ) ) ) { - strokeColor = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "line_color" )].toString() ); + strokeColor = QgsColorUtils::colorFromString( props[QStringLiteral( "line_color" )].toString() ); } if ( props.contains( QStringLiteral( "style_border" ) ) ) @@ -360,9 +361,9 @@ void QgsSimpleFillSymbolLayer::renderPolygon( const QPolygonF &points, const QVe QVariantMap QgsSimpleFillSymbolLayer::properties() const { QVariantMap map; - map[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mColor ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( mColor ); map[QStringLiteral( "style" )] = QgsSymbolLayerUtils::encodeBrushStyle( mBrushStyle ); - map[QStringLiteral( "outline_color" )] = QgsSymbolLayerUtils::encodeColor( mStrokeColor ); + map[QStringLiteral( "outline_color" )] = QgsColorUtils::colorToString( mStrokeColor ); map[QStringLiteral( "outline_style" )] = QgsSymbolLayerUtils::encodePenStyle( mStrokeStyle ); map[QStringLiteral( "outline_width" )] = QString::number( mStrokeWidth ); map[QStringLiteral( "outline_width_unit" )] = QgsUnitTypes::encodeUnit( mStrokeWidthUnit ); @@ -640,15 +641,15 @@ QgsSymbolLayer *QgsGradientFillSymbolLayer::create( const QVariantMap &props ) if ( props.contains( QStringLiteral( "gradient_color" ) ) ) { //pre 2.5 projects used "gradient_color" - color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "gradient_color" )].toString() ); + color = QgsColorUtils::colorFromString( props[QStringLiteral( "gradient_color" )].toString() ); } else if ( props.contains( QStringLiteral( "color" ) ) ) { - color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color" )].toString() ); + color = QgsColorUtils::colorFromString( props[QStringLiteral( "color" )].toString() ); } if ( props.contains( QStringLiteral( "gradient_color2" ) ) ) { - color2 = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "gradient_color2" )].toString() ); + color2 = QgsColorUtils::colorFromString( props[QStringLiteral( "gradient_color2" )].toString() ); } if ( props.contains( QStringLiteral( "reference_point1" ) ) ) @@ -1023,8 +1024,8 @@ void QgsGradientFillSymbolLayer::renderPolygon( const QPolygonF &points, const Q QVariantMap QgsGradientFillSymbolLayer::properties() const { QVariantMap map; - map[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mColor ); - map[QStringLiteral( "gradient_color2" )] = QgsSymbolLayerUtils::encodeColor( mColor2 ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( mColor ); + map[QStringLiteral( "gradient_color2" )] = QgsColorUtils::colorToString( mColor2 ); map[QStringLiteral( "color_type" )] = QString::number( static_cast< int >( mGradientColorType ) ); map[QStringLiteral( "type" )] = QString::number( static_cast( mGradientType ) ); map[QStringLiteral( "coordinate_mode" )] = QString::number( static_cast< int >( mCoordinateMode ) ); @@ -1131,21 +1132,21 @@ QgsSymbolLayer *QgsShapeburstFillSymbolLayer::create( const QVariantMap &props ) if ( props.contains( QStringLiteral( "shapeburst_color" ) ) ) { //pre 2.5 projects used "shapeburst_color" - color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "shapeburst_color" )].toString() ); + color = QgsColorUtils::colorFromString( props[QStringLiteral( "shapeburst_color" )].toString() ); } else if ( props.contains( QStringLiteral( "color" ) ) ) { - color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color" )].toString() ); + color = QgsColorUtils::colorFromString( props[QStringLiteral( "color" )].toString() ); } if ( props.contains( QStringLiteral( "shapeburst_color2" ) ) ) { //pre 2.5 projects used "shapeburst_color2" - color2 = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "shapeburst_color2" )].toString() ); + color2 = QgsColorUtils::colorFromString( props[QStringLiteral( "shapeburst_color2" )].toString() ); } else if ( props.contains( QStringLiteral( "gradient_color2" ) ) ) { - color2 = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "gradient_color2" )].toString() ); + color2 = QgsColorUtils::colorFromString( props[QStringLiteral( "gradient_color2" )].toString() ); } if ( props.contains( QStringLiteral( "blur_radius" ) ) ) { @@ -1679,8 +1680,8 @@ void QgsShapeburstFillSymbolLayer::dtArrayToQImage( double *array, QImage *im, Q QVariantMap QgsShapeburstFillSymbolLayer::properties() const { QVariantMap map; - map[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mColor ); - map[QStringLiteral( "gradient_color2" )] = QgsSymbolLayerUtils::encodeColor( mColor2 ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( mColor ); + map[QStringLiteral( "gradient_color2" )] = QgsColorUtils::colorToString( mColor2 ); map[QStringLiteral( "color_type" )] = QString::number( static_cast< int >( mColorType ) ); map[QStringLiteral( "blur_radius" )] = QString::number( mBlurRadius ); map[QStringLiteral( "use_whole_shape" )] = QString::number( mUseWholeShape ); @@ -2005,24 +2006,24 @@ QgsSymbolLayer *QgsSVGFillSymbolLayer::create( const QVariantMap &properties ) if ( properties.contains( QStringLiteral( "svgFillColor" ) ) ) { //pre 2.5 projects used "svgFillColor" - symbolLayer->setSvgFillColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "svgFillColor" )].toString() ) ); + symbolLayer->setSvgFillColor( QgsColorUtils::colorFromString( properties[QStringLiteral( "svgFillColor" )].toString() ) ); } else if ( properties.contains( QStringLiteral( "color" ) ) ) { - symbolLayer->setSvgFillColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "color" )].toString() ) ); + symbolLayer->setSvgFillColor( QgsColorUtils::colorFromString( properties[QStringLiteral( "color" )].toString() ) ); } if ( properties.contains( QStringLiteral( "svgOutlineColor" ) ) ) { //pre 2.5 projects used "svgOutlineColor" - symbolLayer->setSvgStrokeColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "svgOutlineColor" )].toString() ) ); + symbolLayer->setSvgStrokeColor( QgsColorUtils::colorFromString( properties[QStringLiteral( "svgOutlineColor" )].toString() ) ); } else if ( properties.contains( QStringLiteral( "outline_color" ) ) ) { - symbolLayer->setSvgStrokeColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "outline_color" )].toString() ) ); + symbolLayer->setSvgStrokeColor( QgsColorUtils::colorFromString( properties[QStringLiteral( "outline_color" )].toString() ) ); } else if ( properties.contains( QStringLiteral( "line_color" ) ) ) { - symbolLayer->setSvgStrokeColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "line_color" )].toString() ) ); + symbolLayer->setSvgStrokeColor( QgsColorUtils::colorFromString( properties[QStringLiteral( "line_color" )].toString() ) ); } if ( properties.contains( QStringLiteral( "svgOutlineWidth" ) ) ) { @@ -2199,8 +2200,8 @@ QVariantMap QgsSVGFillSymbolLayer::properties() const map.insert( QStringLiteral( "angle" ), QString::number( mAngle ) ); //svg parameters - map.insert( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); - map.insert( QStringLiteral( "outline_color" ), QgsSymbolLayerUtils::encodeColor( mSvgStrokeColor ) ); + map.insert( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) ); + map.insert( QStringLiteral( "outline_color" ), QgsColorUtils::colorToString( mSvgStrokeColor ) ); map.insert( QStringLiteral( "outline_width" ), QString::number( mSvgStrokeWidth ) ); //units @@ -2768,15 +2769,15 @@ QgsSymbolLayer *QgsLinePatternFillSymbolLayer::create( const QVariantMap &proper if ( properties.contains( QStringLiteral( "color" ) ) ) { - color = QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "color" )].toString() ); + color = QgsColorUtils::colorFromString( properties[QStringLiteral( "color" )].toString() ); } else if ( properties.contains( QStringLiteral( "outline_color" ) ) ) { - color = QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "outline_color" )].toString() ); + color = QgsColorUtils::colorFromString( properties[QStringLiteral( "outline_color" )].toString() ); } else if ( properties.contains( QStringLiteral( "line_color" ) ) ) { - color = QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "line_color" )].toString() ); + color = QgsColorUtils::colorFromString( properties[QStringLiteral( "line_color" )].toString() ); } patternLayer->setColor( color ); @@ -3367,7 +3368,7 @@ QVariantMap QgsLinePatternFillSymbolLayer::properties() const map.insert( QStringLiteral( "angle" ), QString::number( mLineAngle ) ); map.insert( QStringLiteral( "distance" ), QString::number( mDistance ) ); map.insert( QStringLiteral( "line_width" ), QString::number( mLineWidth ) ); - map.insert( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mColor ) ); + map.insert( QStringLiteral( "color" ), QgsColorUtils::colorToString( mColor ) ); map.insert( QStringLiteral( "offset" ), QString::number( mOffset ) ); map.insert( QStringLiteral( "distance_unit" ), QgsUnitTypes::encodeUnit( mDistanceUnit ) ); map.insert( QStringLiteral( "line_width_unit" ), QgsUnitTypes::encodeUnit( mLineWidthUnit ) ); diff --git a/src/core/symbology/qgsinterpolatedlinerenderer.cpp b/src/core/symbology/qgsinterpolatedlinerenderer.cpp index ba748e630238..029363beb475 100644 --- a/src/core/symbology/qgsinterpolatedlinerenderer.cpp +++ b/src/core/symbology/qgsinterpolatedlinerenderer.cpp @@ -20,6 +20,7 @@ #include "qgssymbollayerutils.h" #include "qgsstyle.h" #include "qgsunittypes.h" +#include "qgscolorutils.h" void QgsInterpolatedLineRenderer::setInterpolatedWidth( const QgsInterpolatedLineWidth &strokeWidth ) @@ -507,7 +508,7 @@ QDomElement QgsInterpolatedLineColor::writeXml( QDomDocument &doc, const QgsRead { QDomElement elem = doc.createElement( QStringLiteral( "mesh-stroke-color" ) ); - elem.setAttribute( QStringLiteral( "single-color" ), QgsSymbolLayerUtils::encodeColor( mSingleColor ) ); + elem.setAttribute( QStringLiteral( "single-color" ), QgsColorUtils::colorToString( mSingleColor ) ); elem.setAttribute( QStringLiteral( "coloring-method" ), mColoringMethod ); elem.appendChild( mColorRampShader.writeXml( doc ) ); @@ -519,7 +520,7 @@ void QgsInterpolatedLineColor::readXml( const QDomElement &elem, const QgsReadWr QDomElement shaderElem = elem.firstChildElement( QStringLiteral( "colorrampshader" ) ); mColorRampShader.readXml( shaderElem ); - mSingleColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "single-color" ) ) ); + mSingleColor = QgsColorUtils::colorFromString( elem.attribute( QStringLiteral( "single-color" ) ) ); mColoringMethod = static_cast( elem.attribute( QStringLiteral( "coloring-method" ) ).toInt() ); } @@ -855,7 +856,7 @@ QgsSymbolLayer *QgsInterpolatedLineSymbolLayer::create( const QVariantMap &prope symbolLayer->mLineRender.mStrokeWidth.setIsVariableWidth( properties.value( QStringLiteral( "width_varying_is_variable_width" ) ).toInt() ); if ( properties.contains( QStringLiteral( "single_color" ) ) ) - symbolLayer->mLineRender.mStrokeColoring.setColor( QgsSymbolLayerUtils::decodeColor( properties.value( QStringLiteral( "single_color" ) ).toString() ) ); + symbolLayer->mLineRender.mStrokeColoring.setColor( QgsColorUtils::colorFromString( properties.value( QStringLiteral( "single_color" ) ).toString() ) ); if ( properties.contains( QStringLiteral( "color_ramp_shader" ) ) ) symbolLayer->mLineRender.mStrokeColoring.setColor( createColorRampShaderFromProperties( properties.value( QStringLiteral( "color_ramp_shader" ) ) ) ); if ( properties.contains( QStringLiteral( "coloring_method" ) ) ) @@ -887,7 +888,7 @@ QVariantMap QgsInterpolatedLineSymbolLayer::properties() const // Color varying props.insert( QStringLiteral( "coloring_method" ), mLineRender.mStrokeColoring.coloringMethod() ); - props.insert( QStringLiteral( "single_color" ), QgsSymbolLayerUtils::encodeColor( mLineRender.mStrokeColoring.singleColor() ) ); + props.insert( QStringLiteral( "single_color" ), QgsColorUtils::colorToString( mLineRender.mStrokeColoring.singleColor() ) ); props.insert( QStringLiteral( "color_ramp_shader" ), colorRampShaderProperties() ); return props; @@ -1025,7 +1026,7 @@ QVariant QgsInterpolatedLineSymbolLayer::colorRampShaderProperties() const { QVariantMap itemVar; itemVar[QStringLiteral( "label" )] = item.label; - itemVar[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( item.color ); + itemVar[QStringLiteral( "color" )] = QgsColorUtils::colorToString( item.color ); itemVar[QStringLiteral( "value" )] = item.value; colorRampItemListVariant.append( itemVar ); } @@ -1074,7 +1075,7 @@ QgsColorRampShader QgsInterpolatedLineSymbolLayer::createColorRampShaderFromProp continue; item.label = itemVarMap.value( QStringLiteral( "label" ) ).toString(); - item.color = QgsSymbolLayerUtils::decodeColor( itemVarMap.value( QStringLiteral( "color" ) ).toString() ); + item.color = QgsColorUtils::colorFromString( itemVarMap.value( QStringLiteral( "color" ) ).toString() ); item.value = itemVarMap.value( QStringLiteral( "value" ) ).toDouble(); colorRampItemList.append( item ); diff --git a/src/core/symbology/qgslinesymbollayer.cpp b/src/core/symbology/qgslinesymbollayer.cpp index bccf6031937d..92a1d1874439 100644 --- a/src/core/symbology/qgslinesymbollayer.cpp +++ b/src/core/symbology/qgslinesymbollayer.cpp @@ -32,6 +32,7 @@ #include "qgsimageoperation.h" #include "qgscolorrampimpl.h" #include "qgsfillsymbol.h" +#include "qgscolorutils.h" #include #include @@ -104,16 +105,16 @@ QgsSymbolLayer *QgsSimpleLineSymbolLayer::create( const QVariantMap &props ) if ( props.contains( QStringLiteral( "line_color" ) ) ) { - color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "line_color" )].toString() ); + color = QgsColorUtils::colorFromString( props[QStringLiteral( "line_color" )].toString() ); } else if ( props.contains( QStringLiteral( "outline_color" ) ) ) { - color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "outline_color" )].toString() ); + color = QgsColorUtils::colorFromString( props[QStringLiteral( "outline_color" )].toString() ); } else if ( props.contains( QStringLiteral( "color" ) ) ) { //pre 2.5 projects used "color" - color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color" )].toString() ); + color = QgsColorUtils::colorFromString( props[QStringLiteral( "color" )].toString() ); } if ( props.contains( QStringLiteral( "line_width" ) ) ) { @@ -507,7 +508,7 @@ void QgsSimpleLineSymbolLayer::renderPolyline( const QPolygonF &pts, QgsSymbolRe QVariantMap QgsSimpleLineSymbolLayer::properties() const { QVariantMap map; - map[QStringLiteral( "line_color" )] = QgsSymbolLayerUtils::encodeColor( mColor ); + map[QStringLiteral( "line_color" )] = QgsColorUtils::colorToString( mColor ); map[QStringLiteral( "line_width" )] = QString::number( mWidth ); map[QStringLiteral( "line_width_unit" )] = QgsUnitTypes::encodeUnit( mWidthUnit ); map[QStringLiteral( "width_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mWidthMapUnitScale ); @@ -3596,11 +3597,11 @@ QgsSymbolLayer *QgsLineburstSymbolLayer::create( const QVariantMap &properties ) if ( properties.contains( QStringLiteral( "color" ) ) ) { - res->setColor( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "color" )].toString() ) ); + res->setColor( QgsColorUtils::colorFromString( properties[QStringLiteral( "color" )].toString() ) ); } if ( properties.contains( QStringLiteral( "gradient_color2" ) ) ) { - res->setColor2( QgsSymbolLayerUtils::decodeColor( properties[QStringLiteral( "gradient_color2" )].toString() ) ); + res->setColor2( QgsColorUtils::colorFromString( properties[QStringLiteral( "gradient_color2" )].toString() ) ); } //attempt to create color ramp from props @@ -3631,8 +3632,8 @@ QVariantMap QgsLineburstSymbolLayer::properties() const map[QStringLiteral( "offset_unit" )] = QgsUnitTypes::encodeUnit( mOffsetUnit ); map[QStringLiteral( "offset_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mOffsetMapUnitScale ); - map[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mColor ); - map[QStringLiteral( "gradient_color2" )] = QgsSymbolLayerUtils::encodeColor( mColor2 ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( mColor ); + map[QStringLiteral( "gradient_color2" )] = QgsColorUtils::colorToString( mColor2 ); map[QStringLiteral( "color_type" )] = QString::number( static_cast< int >( mGradientColorType ) ); if ( mGradientRamp ) { @@ -3982,7 +3983,7 @@ QVariantMap QgsFilledLineSymbolLayer::properties() const map[QStringLiteral( "offset_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mOffsetMapUnitScale ); if ( mFill ) { - map[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mFill->color() ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( mFill->color() ); } return map; } diff --git a/src/core/symbology/qgsmarkersymbollayer.cpp b/src/core/symbology/qgsmarkersymbollayer.cpp index 3d676ee99bd7..0e892a42ad4f 100644 --- a/src/core/symbology/qgsmarkersymbollayer.cpp +++ b/src/core/symbology/qgsmarkersymbollayer.cpp @@ -28,6 +28,7 @@ #include "qgssymbol.h" #include "qgsfillsymbol.h" #include "qgsfontmanager.h" +#include "qgscolorutils.h" #include #include @@ -997,19 +998,19 @@ QgsSymbolLayer *QgsSimpleMarkerSymbolLayer::create( const QVariantMap &props ) shape = decodeShape( props[QStringLiteral( "name" )].toString() ); } if ( props.contains( QStringLiteral( "color" ) ) ) - color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color" )].toString() ); + color = QgsColorUtils::colorFromString( props[QStringLiteral( "color" )].toString() ); if ( props.contains( QStringLiteral( "color_border" ) ) ) { //pre 2.5 projects use "color_border" - strokeColor = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color_border" )].toString() ); + strokeColor = QgsColorUtils::colorFromString( props[QStringLiteral( "color_border" )].toString() ); } else if ( props.contains( QStringLiteral( "outline_color" ) ) ) { - strokeColor = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "outline_color" )].toString() ); + strokeColor = QgsColorUtils::colorFromString( props[QStringLiteral( "outline_color" )].toString() ); } else if ( props.contains( QStringLiteral( "line_color" ) ) ) { - strokeColor = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "line_color" )].toString() ); + strokeColor = QgsColorUtils::colorFromString( props[QStringLiteral( "line_color" )].toString() ); } if ( props.contains( QStringLiteral( "joinstyle" ) ) ) { @@ -1369,8 +1370,8 @@ QVariantMap QgsSimpleMarkerSymbolLayer::properties() const { QVariantMap map; map[QStringLiteral( "name" )] = encodeShape( mShape ); - map[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mColor ); - map[QStringLiteral( "outline_color" )] = QgsSymbolLayerUtils::encodeColor( mStrokeColor ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( mColor ); + map[QStringLiteral( "outline_color" )] = QgsColorUtils::colorToString( mStrokeColor ); map[QStringLiteral( "size" )] = QString::number( mSize ); map[QStringLiteral( "size_unit" )] = QgsUnitTypes::encodeUnit( mSizeUnit ); map[QStringLiteral( "size_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mSizeMapUnitScale ); @@ -1961,7 +1962,7 @@ QVariantMap QgsFilledMarkerSymbolLayer::properties() const if ( mFill ) { - map[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mFill->color() ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( mFill->color() ); } return map; } @@ -2141,24 +2142,24 @@ QgsSymbolLayer *QgsSvgMarkerSymbolLayer::create( const QVariantMap &props ) if ( props.contains( QStringLiteral( "fill" ) ) ) { //pre 2.5 projects used "fill" - m->setFillColor( QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "fill" )].toString() ) ); + m->setFillColor( QgsColorUtils::colorFromString( props[QStringLiteral( "fill" )].toString() ) ); } else if ( props.contains( QStringLiteral( "color" ) ) ) { - m->setFillColor( QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color" )].toString() ) ); + m->setFillColor( QgsColorUtils::colorFromString( props[QStringLiteral( "color" )].toString() ) ); } if ( props.contains( QStringLiteral( "outline" ) ) ) { //pre 2.5 projects used "outline" - m->setStrokeColor( QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "outline" )].toString() ) ); + m->setStrokeColor( QgsColorUtils::colorFromString( props[QStringLiteral( "outline" )].toString() ) ); } else if ( props.contains( QStringLiteral( "outline_color" ) ) ) { - m->setStrokeColor( QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "outline_color" )].toString() ) ); + m->setStrokeColor( QgsColorUtils::colorFromString( props[QStringLiteral( "outline_color" )].toString() ) ); } else if ( props.contains( QStringLiteral( "line_color" ) ) ) { - m->setStrokeColor( QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "line_color" )].toString() ) ); + m->setStrokeColor( QgsColorUtils::colorFromString( props[QStringLiteral( "line_color" )].toString() ) ); } if ( props.contains( QStringLiteral( "outline-width" ) ) ) @@ -2596,8 +2597,8 @@ QVariantMap QgsSvgMarkerSymbolLayer::properties() const map[QStringLiteral( "offset_unit" )] = QgsUnitTypes::encodeUnit( mOffsetUnit ); map[QStringLiteral( "offset_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mOffsetMapUnitScale ); map[QStringLiteral( "scale_method" )] = QgsSymbolLayerUtils::encodeScaleMethod( mScaleMethod ); - map[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mColor ); - map[QStringLiteral( "outline_color" )] = QgsSymbolLayerUtils::encodeColor( mStrokeColor ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( mColor ); + map[QStringLiteral( "outline_color" )] = QgsColorUtils::colorToString( mStrokeColor ); map[QStringLiteral( "outline_width" )] = QString::number( mStrokeWidth ); map[QStringLiteral( "outline_width_unit" )] = QgsUnitTypes::encodeUnit( mStrokeWidthUnit ); map[QStringLiteral( "outline_width_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mStrokeWidthMapUnitScale ); @@ -3491,7 +3492,7 @@ QgsSymbolLayer *QgsFontMarkerSymbolLayer::create( const QVariantMap &props ) if ( props.contains( QStringLiteral( "size" ) ) ) pointSize = props[QStringLiteral( "size" )].toDouble(); if ( props.contains( QStringLiteral( "color" ) ) ) - color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color" )].toString() ); + color = QgsColorUtils::colorFromString( props[QStringLiteral( "color" )].toString() ); if ( props.contains( QStringLiteral( "angle" ) ) ) angle = props[QStringLiteral( "angle" )].toDouble(); @@ -3500,7 +3501,7 @@ QgsSymbolLayer *QgsFontMarkerSymbolLayer::create( const QVariantMap &props ) if ( props.contains( QStringLiteral( "font_style" ) ) ) m->setFontStyle( props[QStringLiteral( "font_style" )].toString() ); if ( props.contains( QStringLiteral( "outline_color" ) ) ) - m->setStrokeColor( QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "outline_color" )].toString() ) ); + m->setStrokeColor( QgsColorUtils::colorFromString( props[QStringLiteral( "outline_color" )].toString() ) ); if ( props.contains( QStringLiteral( "outline_width" ) ) ) m->setStrokeWidth( props[QStringLiteral( "outline_width" )].toDouble() ); if ( props.contains( QStringLiteral( "offset" ) ) ) @@ -3823,8 +3824,8 @@ QVariantMap QgsFontMarkerSymbolLayer::properties() const props[QStringLiteral( "size" )] = QString::number( mSize ); props[QStringLiteral( "size_unit" )] = QgsUnitTypes::encodeUnit( mSizeUnit ); props[QStringLiteral( "size_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mSizeMapUnitScale ); - props[QStringLiteral( "color" )] = QgsSymbolLayerUtils::encodeColor( mColor ); - props[QStringLiteral( "outline_color" )] = QgsSymbolLayerUtils::encodeColor( mStrokeColor ); + props[QStringLiteral( "color" )] = QgsColorUtils::colorToString( mColor ); + props[QStringLiteral( "outline_color" )] = QgsColorUtils::colorToString( mStrokeColor ); props[QStringLiteral( "outline_width" )] = QString::number( mStrokeWidth ); props[QStringLiteral( "outline_width_unit" )] = QgsUnitTypes::encodeUnit( mStrokeWidthUnit ); props[QStringLiteral( "outline_width_map_unit_scale" )] = QgsSymbolLayerUtils::encodeMapUnitScale( mStrokeWidthMapUnitScale ); diff --git a/src/core/symbology/qgspointdisplacementrenderer.cpp b/src/core/symbology/qgspointdisplacementrenderer.cpp index 20d28429346a..b0dcd9a8b4c9 100644 --- a/src/core/symbology/qgspointdisplacementrenderer.cpp +++ b/src/core/symbology/qgspointdisplacementrenderer.cpp @@ -23,6 +23,7 @@ #include "qgsrenderedfeaturehandlerinterface.h" #include "qgsmarkersymbol.h" #include "qgsunittypes.h" +#include "qgscolorutils.h" #include #include @@ -164,8 +165,8 @@ QgsFeatureRenderer *QgsPointDisplacementRenderer::create( QDomElement &symbology r->setLabelFont( labelFont ); r->setPlacement( static_cast< Placement >( symbologyElem.attribute( QStringLiteral( "placement" ), QStringLiteral( "0" ) ).toInt() ) ); r->setCircleWidth( symbologyElem.attribute( QStringLiteral( "circleWidth" ), QStringLiteral( "0.4" ) ).toDouble() ); - r->setCircleColor( QgsSymbolLayerUtils::decodeColor( symbologyElem.attribute( QStringLiteral( "circleColor" ), QString() ) ) ); - r->setLabelColor( QgsSymbolLayerUtils::decodeColor( symbologyElem.attribute( QStringLiteral( "labelColor" ), QString() ) ) ); + r->setCircleColor( QgsColorUtils::colorFromString( symbologyElem.attribute( QStringLiteral( "circleColor" ), QString() ) ) ); + r->setLabelColor( QgsColorUtils::colorFromString( symbologyElem.attribute( QStringLiteral( "labelColor" ), QString() ) ) ); r->setCircleRadiusAddition( symbologyElem.attribute( QStringLiteral( "circleRadiusAddition" ), QStringLiteral( "0.0" ) ).toDouble() ); r->setLabelDistanceFactor( symbologyElem.attribute( QStringLiteral( "labelDistanceFactor" ), QStringLiteral( "0.5" ) ).toDouble() ); r->setMinimumLabelScale( symbologyElem.attribute( QStringLiteral( "maxLabelScaleDenominator" ), QStringLiteral( "-1" ) ).toDouble() ); @@ -201,8 +202,8 @@ QDomElement QgsPointDisplacementRenderer::save( QDomDocument &doc, const QgsRead rendererElement.setAttribute( QStringLiteral( "labelAttributeName" ), mLabelAttributeName ); rendererElement.appendChild( QgsFontUtils::toXmlElement( mLabelFont, doc, QStringLiteral( "labelFontProperties" ) ) ); rendererElement.setAttribute( QStringLiteral( "circleWidth" ), QString::number( mCircleWidth ) ); - rendererElement.setAttribute( QStringLiteral( "circleColor" ), QgsSymbolLayerUtils::encodeColor( mCircleColor ) ); - rendererElement.setAttribute( QStringLiteral( "labelColor" ), QgsSymbolLayerUtils::encodeColor( mLabelColor ) ); + rendererElement.setAttribute( QStringLiteral( "circleColor" ), QgsColorUtils::colorToString( mCircleColor ) ); + rendererElement.setAttribute( QStringLiteral( "labelColor" ), QgsColorUtils::colorToString( mLabelColor ) ); rendererElement.setAttribute( QStringLiteral( "circleRadiusAddition" ), QString::number( mCircleRadiusAddition ) ); rendererElement.setAttribute( QStringLiteral( "labelDistanceFactor" ), QString::number( mLabelDistanceFactor ) ); rendererElement.setAttribute( QStringLiteral( "placement" ), static_cast< int >( mPlacement ) ); diff --git a/src/core/symbology/qgssymbol.cpp b/src/core/symbology/qgssymbol.cpp index c281f8f9db64..df23621b0c0d 100644 --- a/src/core/symbology/qgssymbol.cpp +++ b/src/core/symbology/qgssymbol.cpp @@ -52,6 +52,7 @@ #include "qgsmarkersymbol.h" #include "qgslinesymbol.h" #include "qgsfillsymbol.h" +#include "qgscolorutils.h" QgsPropertiesDefinition QgsSymbol::sPropertyDefinitions; @@ -1138,7 +1139,7 @@ QString QgsSymbol::dump() const default: Q_ASSERT( false && "unknown symbol type" ); } - QString s = QStringLiteral( "%1 SYMBOL (%2 layers) color %3" ).arg( t ).arg( mLayers.count() ).arg( QgsSymbolLayerUtils::encodeColor( color() ) ); + QString s = QStringLiteral( "%1 SYMBOL (%2 layers) color %3" ).arg( t ).arg( mLayers.count() ).arg( QgsColorUtils::colorToString( color() ) ); for ( QgsSymbolLayerList::const_iterator it = mLayers.begin(); it != mLayers.end(); ++it ) { diff --git a/src/core/symbology/qgssymbollayerutils.cpp b/src/core/symbology/qgssymbollayerutils.cpp index 709c59e96b48..d1e86166e20b 100644 --- a/src/core/symbology/qgssymbollayerutils.cpp +++ b/src/core/symbology/qgssymbollayerutils.cpp @@ -20,6 +20,7 @@ #include "qgssymbol.h" #include "qgscolorramp.h" #include "qgscolorrampimpl.h" +#include "qgscolorutils.h" #include "qgsexpression.h" #include "qgsexpressionnode.h" #include "qgspainteffect.h" @@ -1967,8 +1968,8 @@ bool QgsSymbolLayerUtils::convertPolygonSymbolizerToPointMarker( QDomElement &el { QVariantMap map; map[QStringLiteral( "name" )] = QStringLiteral( "square" ); - map[QStringLiteral( "color" )] = encodeColor( validFill ? fillColor : Qt::transparent ); - map[QStringLiteral( "color_border" )] = encodeColor( validStroke ? strokeColor : Qt::transparent ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( validFill ? fillColor : Qt::transparent ); + map[QStringLiteral( "color_border" )] = QgsColorUtils::colorToString( validStroke ? strokeColor : Qt::transparent ); map[QStringLiteral( "size" )] = QString::number( 6 ); map[QStringLiteral( "angle" )] = QString::number( 0 ); map[QStringLiteral( "offset" )] = encodePoint( QPointF( 0, 0 ) ); @@ -2160,7 +2161,7 @@ bool QgsSymbolLayerUtils::convertPolygonSymbolizerToPointMarker( QDomElement &el QVariantMap map; map[QStringLiteral( "font" )] = name; map[QStringLiteral( "chr" )] = markIndex; - map[QStringLiteral( "color" )] = encodeColor( validFill ? fillColor : Qt::transparent ); + map[QStringLiteral( "color" )] = QgsColorUtils::colorToString( validFill ? fillColor : Qt::transparent ); if ( size > 0 ) map[QStringLiteral( "size" )] = QString::number( size ); if ( !qgsDoubleNear( angle, 0.0 ) ) @@ -3618,7 +3619,7 @@ QgsNamedColorList QgsSymbolLayerUtils::colorListFromMimeData( const QMimeData *d } QPair< QColor, QString> namedColor; - namedColor.first = QgsSymbolLayerUtils::decodeColor( currentElem.attribute( QStringLiteral( "color" ), QStringLiteral( "255,255,255,255" ) ) ); + namedColor.first = QgsColorUtils::colorFromString( currentElem.attribute( QStringLiteral( "color" ), QStringLiteral( "255,255,255,255" ) ) ); namedColor.second = currentElem.attribute( QStringLiteral( "label" ), QString() ); mimeColors << namedColor; @@ -3715,7 +3716,7 @@ QMimeData *QgsSymbolLayerUtils::colorListToMimeData( const QgsNamedColorList &co for ( ; colorIt != colorList.constEnd(); ++colorIt ) { QDomElement namedColor = xmlDoc.createElement( QStringLiteral( "NamedColor" ) ); - namedColor.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( ( *colorIt ).first ) ); + namedColor.setAttribute( QStringLiteral( "color" ), QgsColorUtils::colorToString( ( *colorIt ).first ) ); namedColor.setAttribute( QStringLiteral( "label" ), ( *colorIt ).second ); xmlRootElement.appendChild( namedColor ); } diff --git a/src/core/textrenderer/qgstextbackgroundsettings.cpp b/src/core/textrenderer/qgstextbackgroundsettings.cpp index a98b2c84d81d..72af8a1b739d 100644 --- a/src/core/textrenderer/qgstextbackgroundsettings.cpp +++ b/src/core/textrenderer/qgstextbackgroundsettings.cpp @@ -24,6 +24,7 @@ #include "qgspainteffectregistry.h" #include "qgsapplication.h" #include "qgsunittypes.h" +#include "qgscolorutils.h" QgsTextBackgroundSettings::QgsTextBackgroundSettings() { @@ -628,8 +629,8 @@ void QgsTextBackgroundSettings::readXml( const QDomElement &elem, const QgsReadW { d->radiiMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( backgroundElem.attribute( QStringLiteral( "shapeRadiiMapUnitScale" ) ) ); } - d->fillColor = QgsSymbolLayerUtils::decodeColor( backgroundElem.attribute( QStringLiteral( "shapeFillColor" ), QgsSymbolLayerUtils::encodeColor( Qt::white ) ) ); - d->strokeColor = QgsSymbolLayerUtils::decodeColor( backgroundElem.attribute( QStringLiteral( "shapeBorderColor" ), QgsSymbolLayerUtils::encodeColor( Qt::darkGray ) ) ); + d->fillColor = QgsColorUtils::colorFromString( backgroundElem.attribute( QStringLiteral( "shapeFillColor" ), QgsColorUtils::colorToString( Qt::white ) ) ); + d->strokeColor = QgsColorUtils::colorFromString( backgroundElem.attribute( QStringLiteral( "shapeBorderColor" ), QgsColorUtils::colorToString( Qt::darkGray ) ) ); d->strokeWidth = backgroundElem.attribute( QStringLiteral( "shapeBorderWidth" ), QStringLiteral( "0" ) ).toDouble(); if ( !backgroundElem.hasAttribute( QStringLiteral( "shapeBorderWidthUnit" ) ) ) @@ -728,8 +729,8 @@ QDomElement QgsTextBackgroundSettings::writeXml( QDomDocument &doc, const QgsRea backgroundElem.setAttribute( QStringLiteral( "shapeRadiiY" ), d->radii.height() ); backgroundElem.setAttribute( QStringLiteral( "shapeRadiiUnit" ), QgsUnitTypes::encodeUnit( d->radiiUnits ) ); backgroundElem.setAttribute( QStringLiteral( "shapeRadiiMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->radiiMapUnitScale ) ); - backgroundElem.setAttribute( QStringLiteral( "shapeFillColor" ), QgsSymbolLayerUtils::encodeColor( d->fillColor ) ); - backgroundElem.setAttribute( QStringLiteral( "shapeBorderColor" ), QgsSymbolLayerUtils::encodeColor( d->strokeColor ) ); + backgroundElem.setAttribute( QStringLiteral( "shapeFillColor" ), QgsColorUtils::colorToString( d->fillColor ) ); + backgroundElem.setAttribute( QStringLiteral( "shapeBorderColor" ), QgsColorUtils::colorToString( d->strokeColor ) ); backgroundElem.setAttribute( QStringLiteral( "shapeBorderWidth" ), d->strokeWidth ); backgroundElem.setAttribute( QStringLiteral( "shapeBorderWidthUnit" ), QgsUnitTypes::encodeUnit( d->strokeWidthUnits ) ); backgroundElem.setAttribute( QStringLiteral( "shapeBorderWidthMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->strokeWidthMapUnitScale ) ); diff --git a/src/core/textrenderer/qgstextbuffersettings.cpp b/src/core/textrenderer/qgstextbuffersettings.cpp index 29bdcc813c9b..2fe8a52c7629 100644 --- a/src/core/textrenderer/qgstextbuffersettings.cpp +++ b/src/core/textrenderer/qgstextbuffersettings.cpp @@ -24,6 +24,7 @@ #include "qgstextrendererutils.h" #include "qgsapplication.h" #include "qgsunittypes.h" +#include "qgscolorutils.h" QgsTextBufferSettings::QgsTextBufferSettings() { @@ -354,7 +355,7 @@ void QgsTextBufferSettings::readXml( const QDomElement &elem ) { d->sizeMapUnitScale = QgsSymbolLayerUtils::decodeMapUnitScale( textBufferElem.attribute( QStringLiteral( "bufferSizeMapUnitScale" ) ) ); } - d->color = QgsSymbolLayerUtils::decodeColor( textBufferElem.attribute( QStringLiteral( "bufferColor" ), QgsSymbolLayerUtils::encodeColor( Qt::white ) ) ); + d->color = QgsColorUtils::colorFromString( textBufferElem.attribute( QStringLiteral( "bufferColor" ), QgsColorUtils::colorToString( Qt::white ) ) ); if ( !textBufferElem.hasAttribute( QStringLiteral( "bufferOpacity" ) ) ) { @@ -384,7 +385,7 @@ QDomElement QgsTextBufferSettings::writeXml( QDomDocument &doc ) const textBufferElem.setAttribute( QStringLiteral( "bufferSize" ), d->size ); textBufferElem.setAttribute( QStringLiteral( "bufferSizeUnits" ), QgsUnitTypes::encodeUnit( d->sizeUnit ) ); textBufferElem.setAttribute( QStringLiteral( "bufferSizeMapUnitScale" ), QgsSymbolLayerUtils::encodeMapUnitScale( d->sizeMapUnitScale ) ); - textBufferElem.setAttribute( QStringLiteral( "bufferColor" ), QgsSymbolLayerUtils::encodeColor( d->color ) ); + textBufferElem.setAttribute( QStringLiteral( "bufferColor" ), QgsColorUtils::colorToString( d->color ) ); textBufferElem.setAttribute( QStringLiteral( "bufferNoFill" ), !d->fillBufferInterior ); textBufferElem.setAttribute( QStringLiteral( "bufferOpacity" ), d->opacity ); textBufferElem.setAttribute( QStringLiteral( "bufferJoinStyle" ), static_cast< unsigned int >( d->joinStyle ) ); diff --git a/src/core/textrenderer/qgstextformat.cpp b/src/core/textrenderer/qgstextformat.cpp index 76c80afae230..ae3c70ea57c4 100644 --- a/src/core/textrenderer/qgstextformat.cpp +++ b/src/core/textrenderer/qgstextformat.cpp @@ -26,6 +26,7 @@ #include "qgsfontmanager.h" #include "qgsapplication.h" #include "qgsunittypes.h" +#include "qgscolorutils.h" #include #include @@ -615,7 +616,7 @@ void QgsTextFormat::readXml( const QDomElement &elem, const QgsReadWriteContext d->textFont.setKerning( textStyleElem.attribute( QStringLiteral( "fontKerning" ), QStringLiteral( "1" ) ).toInt() ); d->textFont.setLetterSpacing( QFont::AbsoluteSpacing, textStyleElem.attribute( QStringLiteral( "fontLetterSpacing" ), QStringLiteral( "0" ) ).toDouble() ); d->textFont.setWordSpacing( textStyleElem.attribute( QStringLiteral( "fontWordSpacing" ), QStringLiteral( "0" ) ).toDouble() ); - d->textColor = QgsSymbolLayerUtils::decodeColor( textStyleElem.attribute( QStringLiteral( "textColor" ), QgsSymbolLayerUtils::encodeColor( Qt::black ) ) ); + d->textColor = QgsColorUtils::colorFromString( textStyleElem.attribute( QStringLiteral( "textColor" ), QgsColorUtils::colorToString( Qt::black ) ) ); if ( !textStyleElem.hasAttribute( QStringLiteral( "textOpacity" ) ) ) { d->opacity = ( 1 - textStyleElem.attribute( QStringLiteral( "textTransp" ) ).toInt() / 100.0 ); //0 -100 @@ -628,7 +629,7 @@ void QgsTextFormat::readXml( const QDomElement &elem, const QgsReadWriteContext d->textFont.setStretch( textStyleElem.attribute( QStringLiteral( "stretchFactor" ), QStringLiteral( "100" ) ).toInt() ); #endif d->orientation = QgsTextRendererUtils::decodeTextOrientation( textStyleElem.attribute( QStringLiteral( "textOrientation" ) ) ); - d->previewBackgroundColor = QgsSymbolLayerUtils::decodeColor( textStyleElem.attribute( QStringLiteral( "previewBkgrdColor" ), QgsSymbolLayerUtils::encodeColor( Qt::white ) ) ); + d->previewBackgroundColor = QgsColorUtils::colorFromString( textStyleElem.attribute( QStringLiteral( "previewBkgrdColor" ), QgsColorUtils::colorToString( Qt::white ) ) ); d->blendMode = QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( textStyleElem.attribute( QStringLiteral( "blendMode" ), QString::number( static_cast< int >( Qgis::BlendMode::Normal ) ) ).toUInt() ) ); @@ -729,8 +730,8 @@ QDomElement QgsTextFormat::writeXml( QDomDocument &doc, const QgsReadWriteContex textStyleElem.setAttribute( QStringLiteral( "fontUnderline" ), d->textFont.underline() ); textStyleElem.setAttribute( QStringLiteral( "forcedBold" ), d->forcedBold ); textStyleElem.setAttribute( QStringLiteral( "forcedItalic" ), d->forcedItalic ); - textStyleElem.setAttribute( QStringLiteral( "textColor" ), QgsSymbolLayerUtils::encodeColor( d->textColor ) ); - textStyleElem.setAttribute( QStringLiteral( "previewBkgrdColor" ), QgsSymbolLayerUtils::encodeColor( d->previewBackgroundColor ) ); + textStyleElem.setAttribute( QStringLiteral( "textColor" ), QgsColorUtils::colorToString( d->textColor ) ); + textStyleElem.setAttribute( QStringLiteral( "previewBkgrdColor" ), QgsColorUtils::colorToString( d->previewBackgroundColor ) ); textStyleElem.setAttribute( QStringLiteral( "fontLetterSpacing" ), d->textFont.letterSpacing() ); textStyleElem.setAttribute( QStringLiteral( "fontWordSpacing" ), d->textFont.wordSpacing() ); textStyleElem.setAttribute( QStringLiteral( "fontKerning" ), d->textFont.kerning() ); diff --git a/src/core/textrenderer/qgstextshadowsettings.cpp b/src/core/textrenderer/qgstextshadowsettings.cpp index 614cd52b76c5..2061fbfe672f 100644 --- a/src/core/textrenderer/qgstextshadowsettings.cpp +++ b/src/core/textrenderer/qgstextshadowsettings.cpp @@ -21,6 +21,7 @@ #include "qgspallabeling.h" #include "qgstextrendererutils.h" #include "qgsunittypes.h" +#include "qgscolorutils.h" QgsTextShadowSettings::QgsTextShadowSettings() { @@ -350,7 +351,7 @@ void QgsTextShadowSettings::readXml( const QDomElement &elem ) d->opacity = ( shadowElem.attribute( QStringLiteral( "shadowOpacity" ) ).toDouble() ); } d->scale = shadowElem.attribute( QStringLiteral( "shadowScale" ), QStringLiteral( "100" ) ).toInt(); - d->color = QgsSymbolLayerUtils::decodeColor( shadowElem.attribute( QStringLiteral( "shadowColor" ), QgsSymbolLayerUtils::encodeColor( Qt::black ) ) ); + d->color = QgsColorUtils::colorFromString( shadowElem.attribute( QStringLiteral( "shadowColor" ), QgsColorUtils::colorToString( Qt::black ) ) ); d->blendMode = QgsPainting::getCompositionMode( static_cast< Qgis::BlendMode >( shadowElem.attribute( QStringLiteral( "shadowBlendMode" ), QString::number( static_cast( Qgis::BlendMode::Multiply ) ) ).toUInt() ) ); } @@ -371,7 +372,7 @@ QDomElement QgsTextShadowSettings::writeXml( QDomDocument &doc ) const shadowElem.setAttribute( QStringLiteral( "shadowRadiusAlphaOnly" ), d->radiusAlphaOnly ); shadowElem.setAttribute( QStringLiteral( "shadowOpacity" ), d->opacity ); shadowElem.setAttribute( QStringLiteral( "shadowScale" ), d->scale ); - shadowElem.setAttribute( QStringLiteral( "shadowColor" ), QgsSymbolLayerUtils::encodeColor( d->color ) ); + shadowElem.setAttribute( QStringLiteral( "shadowColor" ), QgsColorUtils::colorToString( d->color ) ); shadowElem.setAttribute( QStringLiteral( "shadowBlendMode" ), static_cast< int >( QgsPainting::getBlendModeEnum( d->blendMode ) ) ); return shadowElem; } From f0b4c067f54121b95f3af4d2f7d5c45b6f02363c Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 30 Dec 2023 09:45:07 +0700 Subject: [PATCH 2/6] Fix typo in QgsColorUtils::colorToString --- src/core/qgscolorutils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/qgscolorutils.cpp b/src/core/qgscolorutils.cpp index 17a47a033417..21c74ee67106 100644 --- a/src/core/qgscolorutils.cpp +++ b/src/core/qgscolorutils.cpp @@ -281,7 +281,7 @@ QString QgsColorUtils::colorToString( const QColor &color ) qreal alpha = 1; #endif - color.getCmykF( &c, &y, &m, &k, &alpha ); + color.getCmykF( &c, &m, &y, &k, &alpha ); return compatString + QStringLiteral( "cmyk:%1,%2,%3,%4,%5" ).arg( qgsDoubleToString( c ), qgsDoubleToString( m ), qgsDoubleToString( y ), From 0bf5f90d6405f3d39db3d0c7f5546b6e3e622050 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 30 Dec 2023 10:08:31 +0700 Subject: [PATCH 3/6] Fix creation of QgsGradientColorRamp stops from properties --- src/core/qgscolorrampimpl.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/qgscolorrampimpl.cpp b/src/core/qgscolorrampimpl.cpp index fff5b34e1919..e0e264bbe42f 100644 --- a/src/core/qgscolorrampimpl.cpp +++ b/src/core/qgscolorrampimpl.cpp @@ -229,7 +229,8 @@ QgsColorRamp *QgsGradientColorRamp::create( const QVariantMap &props ) QgsGradientStopsList stops; if ( props.contains( QStringLiteral( "stops" ) ) ) { - const auto constSplit = props[QStringLiteral( "stops" )].toString().split( ':' ); + const thread_local QRegularExpression rx( QStringLiteral( "(? Date: Sat, 30 Dec 2023 10:10:29 +0700 Subject: [PATCH 4/6] Fix QgsLayoutMapOverview test --- tests/src/python/test_qgslayoutmapoverview.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/python/test_qgslayoutmapoverview.py b/tests/src/python/test_qgslayoutmapoverview.py index f55a593b3190..538f878edab0 100644 --- a/tests/src/python/test_qgslayoutmapoverview.py +++ b/tests/src/python/test_qgslayoutmapoverview.py @@ -196,8 +196,8 @@ def testAsMapLayer(self): overviewMap.overview().setFrameSymbol(fill_symbol) layer = overviewMap.overview().asMapLayer() self.assertIsInstance(layer.renderer(), QgsSingleSymbolRenderer) - self.assertEqual(layer.renderer().symbol().symbolLayer(0).properties()['color'], '0,255,0,255') - self.assertEqual(layer.renderer().symbol().symbolLayer(0).properties()['outline_color'], '255,0,0,255') + self.assertEqual(layer.renderer().symbol().symbolLayer(0).properties()['color'], '0,255,0,255,rgb:0,1,0,1') + self.assertEqual(layer.renderer().symbol().symbolLayer(0).properties()['outline_color'], '255,0,0,255,rgb:1,0,0,1') # test layer blend mode self.assertEqual(layer.blendMode(), QPainter.CompositionMode_SourceOver) From 58ff964194ad4241696d159cb460a8262d7ed3b8 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Sat, 30 Dec 2023 10:17:43 +0700 Subject: [PATCH 5/6] Fix QgsMapBoxGlConverter and QgsSymbolLayerReadSld tests --- tests/src/python/test_qgsmapboxglconverter.py | 4 ++-- tests/src/python/test_qgssymbollayer_readsld.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/src/python/test_qgsmapboxglconverter.py b/tests/src/python/test_qgsmapboxglconverter.py index e013ef7e1b48..594d66f1daca 100644 --- a/tests/src/python/test_qgsmapboxglconverter.py +++ b/tests/src/python/test_qgsmapboxglconverter.py @@ -723,14 +723,14 @@ def testCircleLayer(self): expected_properties = { 'angle': '0', 'cap_style': 'square', - 'color': '22,22,22,153', + 'color': '22,22,22,153,rgb:0.08627450980392157,0.08627450980392157,0.08627450980392157,0.59999999999999998', 'horizontal_anchor_point': '1', 'joinstyle': 'bevel', 'name': 'circle', 'offset': '11,22', 'offset_map_unit_scale': '3x:0,0,0,0,0,0', 'offset_unit': 'Pixel', - 'outline_color': '46,46,46,128', + 'outline_color': '46,46,46,128,rgb:0.1803921568627451,0.1803921568627451,0.1803921568627451,0.50000762951094835', 'outline_style': 'solid', 'outline_width': '3', 'outline_width_map_unit_scale': '3x:0,0,0,0,0,0', diff --git a/tests/src/python/test_qgssymbollayer_readsld.py b/tests/src/python/test_qgssymbollayer_readsld.py index f617a5a5cc70..60369986c2cb 100644 --- a/tests/src/python/test_qgssymbollayer_readsld.py +++ b/tests/src/python/test_qgssymbollayer_readsld.py @@ -115,7 +115,7 @@ def testLineWidth(): def testLineOpacity(): # stroke-opacity CSSParameter NOT within ogc:Literal # stroke-opacity=0.1 - self.assertEqual(props['line_color'], '0,62,186,25') + self.assertEqual(props['line_color'], '0,62,186,25,rgb:0,0.24313725490196078,0.72941176470588232,0.09803921568627451') testLineColor() testLineWidth() @@ -433,7 +433,7 @@ def testLineWidth(): def testLineOpacity(): # stroke-opacity SvgParameter NOT within ogc:Literal # stroke-opacity=0.1 - self.assertEqual(props['line_color'], '0,62,186,24') + self.assertEqual(props['line_color'], '0,62,186,24,rgb:0,0.24313725490196078,0.72941176470588232,0.09411764705882353') testLineColor() testLineWidth() From e3c5359d892f6580f1ff126c70457b37e0d04596 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Thu, 4 Jan 2024 14:10:41 +0700 Subject: [PATCH 6/6] Insure that QgsColorUtils::colorFromString handle hex color strings --- src/core/qgscolorutils.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/core/qgscolorutils.cpp b/src/core/qgscolorutils.cpp index 21c74ee67106..309242fa5a14 100644 --- a/src/core/qgscolorutils.cpp +++ b/src/core/qgscolorutils.cpp @@ -301,16 +301,17 @@ QColor QgsColorUtils::colorFromString( const QString &string ) const QRegularExpressionMatch match = rx.match( string ); if ( !match.hasMatch() ) { - // try reading older color format - const thread_local QRegularExpression rgbArx( QStringLiteral( "^(\\d+),(\\d+),(\\d+),(\\d+)$" ) ); - const QRegularExpressionMatch match = rgbArx.match( string ); - if ( !match.hasMatch() ) - return QColor(); - - const int red = match.captured( 1 ).toInt(); - const int green = match.captured( 2 ).toInt(); - const int blue = match.captured( 3 ).toInt(); - const int alpha = match.captured( 4 ).toInt(); + // try reading older color format and hex strings + const QStringList lst = string.split( ',' ); + if ( lst.count() < 3 ) + { + return QColor( string ); + } + int red, green, blue, alpha; + red = lst[0].toInt(); + green = lst[1].toInt(); + blue = lst[2].toInt(); + alpha = lst.count() > 3 ? lst[3].toInt() : 255; return QColor( red, green, blue, alpha ); }