Skip to content
Permalink
Browse files

Pass QgsReadWriteContext onto QgsColorRampShader read/writeXml methods

  • Loading branch information
nyalldawson committed Dec 18, 2020
1 parent 047788d commit e48286c0d493d4f16906882b60f273dc8960d023
@@ -180,11 +180,11 @@ Sets the stroke width unit used to render edges scalar dataset
.. versionadded:: 3.14
%End

QDomElement writeXml( QDomDocument &doc ) const;
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
%Docstring
Writes configuration to a new DOM element
%End
void readXml( const QDomElement &elem );
void readXml( const QDomElement &elem, const QgsReadWriteContext &context = QgsReadWriteContext() );
%Docstring
Reads configuration from the given DOM element
%End
@@ -613,11 +613,11 @@ Sets settings for vector rendered with traces
.. versionadded:: 3.12
%End

QDomElement writeXml( QDomDocument &doc ) const;
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
%Docstring
Writes configuration to a new DOM element
%End
void readXml( const QDomElement &elem );
void readXml( const QDomElement &elem, const QgsReadWriteContext &context = QgsReadWriteContext() );
%Docstring
Reads configuration from the given DOM element
%End
@@ -712,11 +712,11 @@ Sets averaging method for conversion of 3d stacked mesh data to 2d data
Ownership of the method is not transferred.
%End

QDomElement writeXml( QDomDocument &doc ) const;
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
%Docstring
Writes configuration to a new DOM element
%End
void readXml( const QDomElement &elem );
void readXml( const QDomElement &elem, const QgsReadWriteContext &context = QgsReadWriteContext() );
%Docstring
Reads configuration from the given DOM element
%End
@@ -168,14 +168,14 @@ Generates and new RGB value based on original RGB value
virtual void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems /Out/ ) const;


QDomElement writeXml( QDomDocument &doc ) const;
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
%Docstring
Writes configuration to a new DOM element

.. versionadded:: 3.4
%End

void readXml( const QDomElement &elem );
void readXml( const QDomElement &elem, const QgsReadWriteContext &context = QgsReadWriteContext() );
%Docstring
Reads configuration from the given DOM element

@@ -113,12 +113,12 @@ Sets the minimum ``value`` for the raster shader.
.. seealso:: :py:func:`minimumValue`
%End

void writeXml( QDomDocument &doc, QDomElement &parent ) const;
void writeXml( QDomDocument &doc, QDomElement &parent, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
%Docstring
Writes shader state to an XML element.
%End

void readXml( const QDomElement &elem );
void readXml( const QDomElement &elem, const QgsReadWriteContext &context = QgsReadWriteContext() );
%Docstring
Reads shader state from an XML element.
%End
@@ -57,8 +57,6 @@ QgsMesh3DSymbol *QgsMesh3DSymbol::clone() const

void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &context ) const
{
Q_UNUSED( context )

QDomDocument doc = elem.ownerDocument();

//Simple symbol
@@ -84,7 +82,7 @@ void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &co
elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-group-index" ), mVerticalDatasetGroupIndex );
elemAdvancedSettings.setAttribute( QStringLiteral( "vertical-relative" ), mIsVerticalMagnitudeRelative ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
elemAdvancedSettings.setAttribute( QStringLiteral( "texture-type" ), mRenderingStyle );
elemAdvancedSettings.appendChild( mColorRampShader.writeXml( doc ) );
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 ) );
@@ -100,8 +98,6 @@ void QgsMesh3DSymbol::writeXml( QDomElement &elem, const QgsReadWriteContext &co

void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{
Q_UNUSED( context )

//Simple symbol
QDomElement elemDataProperties = elem.firstChildElement( QStringLiteral( "data" ) );
mAltClamping = Qgs3DUtils::altClampingFromString( elemDataProperties.attribute( QStringLiteral( "alt-clamping" ) ) );
@@ -123,7 +119,7 @@ void QgsMesh3DSymbol::readXml( const QDomElement &elem, const QgsReadWriteContex
mVerticalDatasetGroupIndex = elemAdvancedSettings.attribute( "vertical-group-index" ).toInt();
mIsVerticalMagnitudeRelative = elemAdvancedSettings.attribute( "vertical-relative" ).toInt();
mRenderingStyle = static_cast<QgsMesh3DSymbol::RenderingStyle>( elemAdvancedSettings.attribute( QStringLiteral( "texture-type" ) ).toInt() );
mColorRampShader.readXml( elemAdvancedSettings.firstChildElement( "colorrampshader" ) );
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" ) ) );
@@ -1047,7 +1047,7 @@ bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage,

QDomElement elemRendererSettings = elem.firstChildElement( "mesh-renderer-settings" );
if ( !elemRendererSettings.isNull() )
mRendererSettings.readXml( elemRendererSettings );
mRendererSettings.readXml( elemRendererSettings, context );

QDomElement elemSimplifySettings = elem.firstChildElement( "mesh-simplify-settings" );
if ( !elemSimplifySettings.isNull() )
@@ -1085,7 +1085,7 @@ bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &e

writeCommonStyle( elem, doc, context, categories );

QDomElement elemRendererSettings = mRendererSettings.writeXml( doc );
QDomElement elemRendererSettings = mRendererSettings.writeXml( doc, context );
elem.appendChild( elemRendererSettings );

QDomElement elemSimplifySettings = mSimplificationSettings.writeXml( doc, context );
@@ -112,9 +112,8 @@ void QgsMeshRendererScalarSettings::setDataResamplingMethod( const QgsMeshRender
mDataResamplingMethod = dataInterpolationMethod;
}

QDomElement QgsMeshRendererScalarSettings::writeXml( QDomDocument &doc ) const
QDomElement QgsMeshRendererScalarSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
{
QgsReadWriteContext readWriteContext;
QDomElement elem = doc.createElement( QStringLiteral( "scalar-settings" ) );
elem.setAttribute( QStringLiteral( "min-val" ), mClassificationMinimum );
elem.setAttribute( QStringLiteral( "max-val" ), mClassificationMaximum );
@@ -131,20 +130,19 @@ QDomElement QgsMeshRendererScalarSettings::writeXml( QDomDocument &doc ) const
break;
}
elem.setAttribute( QStringLiteral( "interpolation-method" ), methodTxt );
QDomElement elemShader = mColorRampShader.writeXml( doc );
QDomElement elemShader = mColorRampShader.writeXml( doc, context );
elem.appendChild( elemShader );

QDomElement elemEdge = doc.createElement( QStringLiteral( "edge-settings" ) );
elemEdge.appendChild( mEdgeStrokeWidth.writeXml( doc, readWriteContext ) );
elemEdge.appendChild( mEdgeStrokeWidth.writeXml( doc, context ) );
elemEdge.setAttribute( QStringLiteral( "stroke-width-unit" ), mEdgeStrokeWidthUnit );
elem.appendChild( elemEdge );

return elem;
}

void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem )
void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{
QgsReadWriteContext readWriteContext;
mClassificationMinimum = elem.attribute( QStringLiteral( "min-val" ) ).toDouble();
mClassificationMaximum = elem.attribute( QStringLiteral( "max-val" ) ).toDouble();
mOpacity = elem.attribute( QStringLiteral( "opacity" ) ).toDouble();
@@ -159,11 +157,11 @@ void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem )
mDataResamplingMethod = DataResamplingMethod::None;
}
QDomElement elemShader = elem.firstChildElement( QStringLiteral( "colorrampshader" ) );
mColorRampShader.readXml( elemShader );
mColorRampShader.readXml( elemShader, context );

QDomElement elemEdge = elem.firstChildElement( QStringLiteral( "edge-settings" ) );
QDomElement elemEdgeStrokeWidth = elemEdge.firstChildElement( QStringLiteral( "mesh-stroke-width" ) );
mEdgeStrokeWidth.readXml( elemEdgeStrokeWidth, readWriteContext );
mEdgeStrokeWidth.readXml( elemEdgeStrokeWidth, context );
mEdgeStrokeWidthUnit = static_cast<QgsUnitTypes::RenderUnit>(
elemEdge.attribute( QStringLiteral( "stroke-width-unit" ) ).toInt() );
}
@@ -406,7 +404,7 @@ void QgsMeshRendererSettings::setAveragingMethod( QgsMesh3dAveragingMethod *meth
mAveragingMethod.reset();
}

QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc ) const
QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
{
QDomElement elem = doc.createElement( QStringLiteral( "mesh-renderer-settings" ) );

@@ -418,15 +416,15 @@ QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc ) const
for ( int groupIndex : mRendererScalarSettings.keys() )
{
const QgsMeshRendererScalarSettings &scalarSettings = mRendererScalarSettings[groupIndex];
QDomElement elemScalar = scalarSettings.writeXml( doc );
QDomElement elemScalar = scalarSettings.writeXml( doc, context );
elemScalar.setAttribute( QStringLiteral( "group" ), groupIndex );
elem.appendChild( elemScalar );
}

for ( int groupIndex : mRendererVectorSettings.keys() )
{
const QgsMeshRendererVectorSettings &vectorSettings = mRendererVectorSettings[groupIndex];
QDomElement elemVector = vectorSettings.writeXml( doc );
QDomElement elemVector = vectorSettings.writeXml( doc, context );
elemVector.setAttribute( QStringLiteral( "group" ), groupIndex );
elem.appendChild( elemVector );
}
@@ -455,7 +453,7 @@ QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc ) const
return elem;
}

void QgsMeshRendererSettings::readXml( const QDomElement &elem )
void QgsMeshRendererSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{
mRendererScalarSettings.clear();
mRendererVectorSettings.clear();
@@ -473,7 +471,7 @@ void QgsMeshRendererSettings::readXml( const QDomElement &elem )
{
int groupIndex = elemScalar.attribute( QStringLiteral( "group" ) ).toInt();
QgsMeshRendererScalarSettings scalarSettings;
scalarSettings.readXml( elemScalar );
scalarSettings.readXml( elemScalar, context );
mRendererScalarSettings.insert( groupIndex, scalarSettings );

elemScalar = elemScalar.nextSiblingElement( QStringLiteral( "scalar-settings" ) );
@@ -484,7 +482,7 @@ void QgsMeshRendererSettings::readXml( const QDomElement &elem )
{
int groupIndex = elemVector.attribute( QStringLiteral( "group" ) ).toInt();
QgsMeshRendererVectorSettings vectorSettings;
vectorSettings.readXml( elemVector );
vectorSettings.readXml( elemVector, context );
mRendererVectorSettings.insert( groupIndex, vectorSettings );

elemVector = elemVector.nextSiblingElement( QStringLiteral( "vector-settings" ) );
@@ -594,15 +592,15 @@ void QgsMeshRendererVectorSettings::setStreamLinesSettings( const QgsMeshRendere
mStreamLinesSettings = streamLinesSettings;
}

QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc ) const
QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
{
QDomElement elem = doc.createElement( QStringLiteral( "vector-settings" ) );
elem.setAttribute( QStringLiteral( "symbology" ), mDisplayingMethod );

elem.setAttribute( QStringLiteral( "line-width" ), mLineWidth );
elem.setAttribute( QStringLiteral( "coloring-method" ), coloringMethod() );
elem.setAttribute( QStringLiteral( "color" ), QgsSymbolLayerUtils::encodeColor( mColor ) );
QDomElement elemShader = mColorRampShader.writeXml( doc );
QDomElement elemShader = mColorRampShader.writeXml( doc, context );
elem.appendChild( elemShader );
elem.setAttribute( QStringLiteral( "filter-min" ), mFilterMin );
elem.setAttribute( QStringLiteral( "filter-max" ), mFilterMax );
@@ -618,7 +616,7 @@ QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc ) const
return elem;
}

void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem )
void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem, const QgsReadWriteContext &context )
{
mDisplayingMethod = static_cast<QgsMeshRendererVectorSettings::Symbology>(
elem.attribute( QStringLiteral( "symbology" ) ).toInt() );
@@ -627,7 +625,7 @@ void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem )
mColoringMethod = static_cast<QgsInterpolatedLineColor::ColoringMethod>(
elem.attribute( QStringLiteral( "coloring-method" ) ).toInt() );
mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( QStringLiteral( "color" ) ) );
mColorRampShader.readXml( elem.firstChildElement( "colorrampshader" ) );
mColorRampShader.readXml( elem.firstChildElement( "colorrampshader" ), context );
mFilterMin = elem.attribute( QStringLiteral( "filter-min" ) ).toDouble();
mFilterMax = elem.attribute( QStringLiteral( "filter-max" ) ).toDouble();

@@ -178,9 +178,9 @@ class CORE_EXPORT QgsMeshRendererScalarSettings
void setEdgeStrokeWidthUnit( const QgsUnitTypes::RenderUnit &edgeStrokeWidthUnit );

//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
void readXml( const QDomElement &elem, const QgsReadWriteContext &context = QgsReadWriteContext() );

private:
QgsColorRampShader mColorRampShader;
@@ -555,9 +555,9 @@ class CORE_EXPORT QgsMeshRendererVectorSettings
void setTracesSettings( const QgsMeshRendererVectorTracesSettings &tracesSettings );

//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
void readXml( const QDomElement &elem, const QgsReadWriteContext &context = QgsReadWriteContext() );

private:

@@ -645,9 +645,9 @@ class CORE_EXPORT QgsMeshRendererSettings
void setAveragingMethod( QgsMesh3dAveragingMethod *method );

//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
void readXml( const QDomElement &elem, const QgsReadWriteContext &context = QgsReadWriteContext() );

/**
* Returns the active scalar dataset group
@@ -136,7 +136,7 @@ QgsPointCloudRenderer *QgsPointCloudAttributeByRampRenderer::create( QDomElement
r->setAttribute( element.attribute( QStringLiteral( "attribute" ), QStringLiteral( "Intensity" ) ) );

QDomElement elemShader = element.firstChildElement( QStringLiteral( "colorrampshader" ) );
r->mColorRampShader.readXml( elemShader );
r->mColorRampShader.readXml( elemShader, context );

r->setMinimum( element.attribute( QStringLiteral( "min" ), QStringLiteral( "0" ) ).toDouble() );
r->setMaximum( element.attribute( QStringLiteral( "max" ), QStringLiteral( "100" ) ).toDouble() );
@@ -156,7 +156,7 @@ QDomElement QgsPointCloudAttributeByRampRenderer::save( QDomDocument &doc, const

rendererElem.setAttribute( QStringLiteral( "attribute" ), mAttribute );

QDomElement elemShader = mColorRampShader.writeXml( doc );
QDomElement elemShader = mColorRampShader.writeXml( doc, context );
rendererElem.appendChild( elemShader );

saveCommonProperties( rendererElem, context );
@@ -29,6 +29,8 @@ originally part of the larger QgsRasterLayer class
#include "qgsrasterinterface.h"
#include "qgsrasterminmaxorigin.h"
#include "qgssymbollayerutils.h"
#include "qgsreadwritecontext.h"
#include "qgscolorramplegendnodesettings.h"

#include <cmath>
QgsColorRampShader::QgsColorRampShader( double minimumValue, double maximumValue, QgsColorRamp *colorRamp, Type type, ClassificationMode classificationMode )
@@ -502,7 +504,7 @@ void QgsColorRampShader::legendSymbologyItems( QList< QPair< QString, QColor > >
}
}

QDomElement QgsColorRampShader::writeXml( QDomDocument &doc ) const
QDomElement QgsColorRampShader::writeXml( QDomDocument &doc, const QgsReadWriteContext &context ) const
{
QDomElement colorRampShaderElem = doc.createElement( QStringLiteral( "colorrampshader" ) );
colorRampShaderElem.setAttribute( QStringLiteral( "colorRampType" ), colorRampTypeAsQString() );
@@ -534,7 +536,7 @@ QDomElement QgsColorRampShader::writeXml( QDomDocument &doc ) const
return colorRampShaderElem;
}

void QgsColorRampShader::readXml( const QDomElement &colorRampShaderElem )
void QgsColorRampShader::readXml( const QDomElement &colorRampShaderElem, const QgsReadWriteContext &context )
{
// try to load color ramp (optional)
QDomElement sourceColorRampElem = colorRampShaderElem.firstChildElement( QStringLiteral( "colorramp" ) );
@@ -29,6 +29,7 @@ originally part of the larger QgsRasterLayer class

#include "qgsrastershaderfunction.h"
#include "qgsrectangle.h"
#include "qgsreadwritecontext.h"

class QgsColorRamp;
class QgsRasterInterface;
@@ -198,13 +199,13 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
* Writes configuration to a new DOM element
* \since QGIS 3.4
*/
QDomElement writeXml( QDomDocument &doc ) const;
QDomElement writeXml( QDomDocument &doc, const QgsReadWriteContext &context = QgsReadWriteContext() ) const;

/**
* Reads configuration from the given DOM element
* \since QGIS 3.4
*/
void readXml( const QDomElement &elem );
void readXml( const QDomElement &elem, const QgsReadWriteContext &context = QgsReadWriteContext() );

//! Sets classification mode
void setClassificationMode( ClassificationMode classificationMode ) { mClassificationMode = classificationMode; }

0 comments on commit e48286c

Please sign in to comment.
You can’t perform that action at this time.