Read/write mesh styling from/to project files

This commit is contained in:
Martin Dobias 2018-08-14 16:04:01 +02:00
parent 9fc2e3e148
commit 358d12946b
10 changed files with 355 additions and 65 deletions

View File

@ -53,6 +53,15 @@ Returns color used for rendering
void setColor( const QColor &color );
%Docstring
Sets color used for rendering of the mesh
%End
QDomElement writeXml( QDomDocument &doc ) const;
%Docstring
Writes configuration to a new DOM element
%End
void readXml( const QDomElement &elem );
%Docstring
Reads configuration from the given DOM element
%End
};
@ -81,6 +90,15 @@ Returns color ramp shader function
void setColorRampShader( const QgsColorRampShader &shader );
%Docstring
Sets color ramp shader function
%End
QDomElement writeXml( QDomDocument &doc ) const;
%Docstring
Writes configuration to a new DOM element
%End
void readXml( const QDomElement &elem );
%Docstring
Reads configuration from the given DOM element
%End
};
@ -242,6 +260,15 @@ Returns ratio of the head length of the arrow (range 0-1)
void setArrowHeadLengthRatio( double arrowHeadLengthRatio );
%Docstring
Sets ratio of the head length of the arrow (range 0-1)
%End
QDomElement writeXml( QDomDocument &doc ) const;
%Docstring
Writes configuration to a new DOM element
%End
void readXml( const QDomElement &elem );
%Docstring
Reads configuration from the given DOM element
%End
};
@ -318,6 +345,15 @@ Returns active vector dataset
void setActiveVectorDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() );
%Docstring
Sets active vector dataset for rendering.
%End
QDomElement writeXml( QDomDocument &doc ) const;
%Docstring
Writes configuration to a new DOM element
%End
void readXml( const QDomElement &elem );
%Docstring
Reads configuration from the given DOM element
%End
};

View File

@ -82,7 +82,7 @@ Returns the custom colormap.
Returns the color ramp type.
%End
QString colorRampTypeAsQString();
QString colorRampTypeAsQString() const;
%Docstring
Returns the color ramp type as a string.
%End
@ -160,6 +160,20 @@ 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;
%Docstring
Writes configuration to a new DOM element
.. versionadded:: 3.4
%End
void readXml( const QDomElement &elem );
%Docstring
Reads configuration from the given DOM element
.. versionadded:: 3.4
%End
void setClassificationMode( ClassificationMode classificationMode );
%Docstring
Sets classification mode

View File

@ -164,11 +164,13 @@ void QgsMeshRendererActiveDatasetWidget::syncToLayer()
if ( mMeshLayer )
{
const QgsMeshRendererSettings rendererSettings = mMeshLayer->rendererSettings();
mActiveDatasetGroup = mDatasetGroupTreeView->activeGroup();
mActiveScalarDataset = rendererSettings.activeScalarDataset();
mActiveVectorDataset = rendererSettings.activeVectorDataset();
}
else
{
mActiveDatasetGroup = -1;
mActiveScalarDataset = QgsMeshDatasetIndex();
mActiveVectorDataset = QgsMeshDatasetIndex();
}

View File

@ -26,6 +26,8 @@ QgsMeshRendererVectorSettingsWidget::QgsMeshRendererVectorSettingsWidget( QWidge
{
setupUi( this );
mShaftLengthComboBox->setCurrentIndex( -1 );
connect( mColorWidget, &QgsColorButton::colorChanged, this, &QgsMeshRendererVectorSettingsWidget::widgetChanged );
connect( mLineWidthSpinBox, qgis::overload<double>::of( &QgsDoubleSpinBox::valueChanged ),
this, &QgsMeshRendererVectorSettingsWidget::widgetChanged );

View File

@ -221,18 +221,26 @@ QgsMapLayerRenderer *QgsMeshLayer::createMapRenderer( QgsRenderContext &renderer
bool QgsMeshLayer::readSymbology( const QDomNode &node, QString &errorMessage, QgsReadWriteContext &context )
{
Q_UNUSED( node );
Q_UNUSED( errorMessage );
Q_UNUSED( context );
QDomElement elem = node.toElement();
QDomElement elemRendererSettings = elem.firstChildElement( "mesh-renderer-settings" );
if ( !elemRendererSettings.isNull() )
mRendererSettings.readXml( elemRendererSettings );
return true;
}
bool QgsMeshLayer::writeSymbology( QDomNode &node, QDomDocument &doc, QString &errorMessage, const QgsReadWriteContext &context ) const
{
Q_UNUSED( node );
Q_UNUSED( doc );
Q_UNUSED( errorMessage );
Q_UNUSED( context );
QDomElement elem = node.toElement();
QDomElement elemRendererSettings = mRendererSettings.writeXml( doc );
elem.appendChild( elemRendererSettings );
return true;
}
@ -258,8 +266,6 @@ QString QgsMeshLayer::encodedSource( const QString &source, const QgsReadWriteCo
bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &context )
{
Q_UNUSED( context );
QgsDebugMsgLevel( QStringLiteral( "Datasource in QgsMeshLayer::readXml: %1" ).arg( mDataSource.toLocal8Bit().data() ), 3 );
//process provider key
@ -296,6 +302,9 @@ bool QgsMeshLayer::readXml( const QDomNode &layer_node, QgsReadWriteContext &con
}
}
QString errorMsg;
readSymbology( layer_node, errorMsg, context );
return mValid; // should be true if read successfully
}

View File

@ -17,6 +17,9 @@
#include "qgsmeshrenderersettings.h"
#include "qgssymbollayerutils.h"
bool QgsMeshRendererMeshSettings::isEnabled() const
{
return mEnabled;
@ -47,11 +50,27 @@ void QgsMeshRendererMeshSettings::setColor( const QColor &color )
mColor = color;
}
QDomElement QgsMeshRendererMeshSettings::writeXml( QDomDocument &doc ) const
{
QDomElement elem = doc.createElement( "mesh-settings" );
elem.setAttribute( "enabled", mEnabled ? "1" : "0" );
elem.setAttribute( "line-width", mLineWidth );
elem.setAttribute( "color", QgsSymbolLayerUtils::encodeColor( mColor ) );
return elem;
}
void QgsMeshRendererMeshSettings::readXml( const QDomElement &elem )
{
mEnabled = elem.attribute( "enabled" ).toInt();
mLineWidth = elem.attribute( "line-width" ).toDouble();
mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( "color" ) );
}
// ---------------------------------------------------------------------
QgsColorRampShader QgsMeshRendererScalarSettings::colorRampShader() const
{
return mColorRampShader;
}
void QgsMeshRendererScalarSettings::setColorRampShader( const QgsColorRampShader &shader )
@ -59,6 +78,22 @@ void QgsMeshRendererScalarSettings::setColorRampShader( const QgsColorRampShader
mColorRampShader = shader;
}
QDomElement QgsMeshRendererScalarSettings::writeXml( QDomDocument &doc ) const
{
QDomElement elem = doc.createElement( "scalar-settings" );
QDomElement elemShader = mColorRampShader.writeXml( doc );
elem.appendChild( elemShader );
return elem;
}
void QgsMeshRendererScalarSettings::readXml( const QDomElement &elem )
{
QDomElement elemShader = elem.firstChildElement( QStringLiteral( "colorrampshader" ) );
mColorRampShader.readXml( elemShader );
}
// ---------------------------------------------------------------------
double QgsMeshRendererVectorSettings::lineWidth() const
{
return mLineWidth;
@ -168,3 +203,153 @@ void QgsMeshRendererVectorSettings::setArrowHeadLengthRatio( double vectorHeadLe
{
mArrowHeadLengthRatio = vectorHeadLengthRatio;
}
QDomElement QgsMeshRendererVectorSettings::writeXml( QDomDocument &doc ) const
{
QDomElement elem = doc.createElement( "vector-settings" );
elem.setAttribute( "line-width", mLineWidth );
elem.setAttribute( "color", QgsSymbolLayerUtils::encodeColor( mColor ) );
elem.setAttribute( "filter-min", mFilterMin );
elem.setAttribute( "filter-max", mFilterMax );
elem.setAttribute( "arrow-head-width-ratio", mArrowHeadWidthRatio );
elem.setAttribute( "arrow-head-length-ratio", mArrowHeadLengthRatio );
QDomElement elemShaft = doc.createElement( "shaft-length" );
QString methodTxt;
switch ( mShaftLengthMethod )
{
case MinMax:
methodTxt = "minmax";
elemShaft.setAttribute( "min", mMinShaftLength );
elemShaft.setAttribute( "max", mMaxShaftLength );
break;
case Scaled:
methodTxt = "scaled";
elemShaft.setAttribute( "scale-factor", mScaleFactor );
break;
case Fixed:
methodTxt = "fixed";
elemShaft.setAttribute( "fixed-length", mFixedShaftLength );
break;
}
elemShaft.setAttribute( "method", methodTxt );
elem.appendChild( elemShaft );
return elem;
}
void QgsMeshRendererVectorSettings::readXml( const QDomElement &elem )
{
mLineWidth = elem.attribute( "line-width" ).toDouble();
mColor = QgsSymbolLayerUtils::decodeColor( elem.attribute( "color" ) );
mFilterMin = elem.attribute( "filter-min" ).toDouble();
mFilterMax = elem.attribute( "filter-max" ).toDouble();
mArrowHeadWidthRatio = elem.attribute( "arrow-head-width-ratio" ).toDouble();
mArrowHeadLengthRatio = elem.attribute( "arrow-head-length-ratio" ).toDouble();
QDomElement elemShaft = elem.firstChildElement( "shaft-length" );
QString methodTxt = elemShaft.attribute( "method" );
if ( methodTxt == "minmax" )
{
mShaftLengthMethod = MinMax;
mMinShaftLength = elemShaft.attribute( "min" ).toDouble();
mMaxShaftLength = elemShaft.attribute( "max" ).toDouble();
}
else if ( methodTxt == "scaled" )
{
mShaftLengthMethod = Scaled;
mScaleFactor = elemShaft.attribute( "scale-factor" ).toDouble();
}
else // fixed
{
mShaftLengthMethod = Fixed;
mFixedShaftLength = elemShaft.attribute( "fixed-length" ).toDouble();
}
}
// ---------------------------------------------------------------------
QDomElement QgsMeshRendererSettings::writeXml( QDomDocument &doc ) const
{
QDomElement elem = doc.createElement( "mesh-renderer-settings" );
QDomElement elemActiveDataset = doc.createElement( "active-dataset" );
if ( mActiveScalarDataset.isValid() )
elemActiveDataset.setAttribute( "scalar", QString( "%1,%2" ).arg( mActiveScalarDataset.group() ).arg( mActiveScalarDataset.dataset() ) );
if ( mActiveVectorDataset.isValid() )
elemActiveDataset.setAttribute( "vector", QString( "%1,%2" ).arg( mActiveVectorDataset.group() ).arg( mActiveVectorDataset.dataset() ) );
elem.appendChild( elemActiveDataset );
for ( int groupIndex : mRendererScalarSettings.keys() )
{
const QgsMeshRendererScalarSettings &scalarSettings = mRendererScalarSettings[groupIndex];
QDomElement elemScalar = scalarSettings.writeXml( doc );
elemScalar.setAttribute( "group", groupIndex );
elem.appendChild( elemScalar );
}
for ( int groupIndex : mRendererVectorSettings.keys() )
{
const QgsMeshRendererVectorSettings &vectorSettings = mRendererVectorSettings[groupIndex];
QDomElement elemVector = vectorSettings.writeXml( doc );
elemVector.setAttribute( "group", groupIndex );
elem.appendChild( elemVector );
}
QDomElement elemNativeMesh = mRendererNativeMeshSettings.writeXml( doc );
elemNativeMesh.setTagName( "mesh-settings-native" );
elem.appendChild( elemNativeMesh );
QDomElement elemTriangularMesh = mRendererTriangularMeshSettings.writeXml( doc );
elemTriangularMesh.setTagName( "mesh-settings-triangular" );
elem.appendChild( elemTriangularMesh );
return elem;
}
void QgsMeshRendererSettings::readXml( const QDomElement &elem )
{
mRendererScalarSettings.clear();
mRendererVectorSettings.clear();
QDomElement elemActiveDataset = elem.firstChildElement( "active-dataset" );
if ( elemActiveDataset.hasAttribute( "scalar" ) )
{
QStringList lst = elemActiveDataset.attribute( "scalar" ).split( QChar( ',' ) );
if ( lst.count() == 2 )
mActiveScalarDataset = QgsMeshDatasetIndex( lst[0].toInt(), lst[1].toInt() );
}
if ( elemActiveDataset.hasAttribute( "vector" ) )
{
QStringList lst = elemActiveDataset.attribute( "vector" ).split( QChar( ',' ) );
if ( lst.count() == 2 )
mActiveVectorDataset = QgsMeshDatasetIndex( lst[0].toInt(), lst[1].toInt() );
}
QDomElement elemScalar = elem.firstChildElement( "scalar-settings" );
while ( !elemScalar.isNull() )
{
int groupIndex = elemScalar.attribute( "group" ).toInt();
QgsMeshRendererScalarSettings scalarSettings;
scalarSettings.readXml( elemScalar );
mRendererScalarSettings.insert( groupIndex, scalarSettings );
elemScalar = elemScalar.nextSiblingElement( "scalar-settings" );
}
QDomElement elemVector = elem.firstChildElement( "vector-settings" );
while ( !elemVector.isNull() )
{
int groupIndex = elemVector.attribute( "group" ).toInt();
QgsMeshRendererVectorSettings vectorSettings;
vectorSettings.readXml( elemVector );
mRendererVectorSettings.insert( groupIndex, vectorSettings );
elemVector = elemVector.nextSiblingElement( "vector-settings" );
}
QDomElement elemNativeMesh = elem.firstChildElement( "mesh-settings-native" );
mRendererNativeMeshSettings.readXml( elemNativeMesh );
QDomElement elemTriangularMesh = elem.firstChildElement( "mesh-settings-triangular" );
mRendererTriangularMeshSettings.readXml( elemTriangularMesh );
}

View File

@ -53,6 +53,11 @@ class CORE_EXPORT QgsMeshRendererMeshSettings
//! Sets color used for rendering of the mesh
void setColor( const QColor &color );
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
private:
bool mEnabled = false;
double mLineWidth = DEFAULT_LINE_WIDTH;
@ -76,6 +81,11 @@ class CORE_EXPORT QgsMeshRendererScalarSettings
//! Sets color ramp shader function
void setColorRampShader( const QgsColorRampShader &shader );
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
private:
QgsColorRampShader mColorRampShader;
};
@ -222,6 +232,11 @@ class CORE_EXPORT QgsMeshRendererVectorSettings
//! Sets ratio of the head length of the arrow (range 0-1)
void setArrowHeadLengthRatio( double arrowHeadLengthRatio );
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
private:
double mLineWidth = DEFAULT_LINE_WIDTH; //in milimeters
QColor mColor = Qt::black;
@ -282,6 +297,11 @@ class CORE_EXPORT QgsMeshRendererSettings
//! Sets active vector dataset for rendering.
void setActiveVectorDataset( QgsMeshDatasetIndex index = QgsMeshDatasetIndex() ) { mActiveVectorDataset = index; }
//! Writes configuration to a new DOM element
QDomElement writeXml( QDomDocument &doc ) const;
//! Reads configuration from the given DOM element
void readXml( const QDomElement &elem );
private:
QgsMeshRendererMeshSettings mRendererNativeMeshSettings;
QgsMeshRendererMeshSettings mRendererTriangularMeshSettings;

View File

@ -28,6 +28,7 @@ originally part of the larger QgsRasterLayer class
#include "qgscolorrampshader.h"
#include "qgsrasterinterface.h"
#include "qgsrasterminmaxorigin.h"
#include "qgssymbollayerutils.h"
#include <cmath>
QgsColorRampShader::QgsColorRampShader( double minimumValue, double maximumValue, QgsColorRamp *colorRamp, Type type, ClassificationMode classificationMode )
@ -73,7 +74,7 @@ QgsColorRampShader &QgsColorRampShader::operator=( const QgsColorRampShader &oth
return *this;
}
QString QgsColorRampShader::colorRampTypeAsQString()
QString QgsColorRampShader::colorRampTypeAsQString() const
{
switch ( mColorRampType )
{
@ -491,3 +492,66 @@ void QgsColorRampShader::legendSymbologyItems( QList< QPair< QString, QColor > >
symbolItems.push_back( qMakePair( colorRampIt->label, colorRampIt->color ) );
}
}
QDomElement QgsColorRampShader::writeXml( QDomDocument &doc ) const
{
QDomElement colorRampShaderElem = doc.createElement( QStringLiteral( "colorrampshader" ) );
colorRampShaderElem.setAttribute( QStringLiteral( "colorRampType" ), colorRampTypeAsQString() );
colorRampShaderElem.setAttribute( QStringLiteral( "classificationMode" ), classificationMode() );
colorRampShaderElem.setAttribute( QStringLiteral( "clip" ), clip() );
// save source color ramp
if ( sourceColorRamp() )
{
QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QStringLiteral( "[source]" ), sourceColorRamp(), doc );
colorRampShaderElem.appendChild( colorRampElem );
}
//items
QList<QgsColorRampShader::ColorRampItem> itemList = colorRampItemList();
QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList.constBegin();
for ( ; itemIt != itemList.constEnd(); ++itemIt )
{
QDomElement itemElem = doc.createElement( QStringLiteral( "item" ) );
itemElem.setAttribute( QStringLiteral( "label" ), itemIt->label );
itemElem.setAttribute( QStringLiteral( "value" ), QgsRasterBlock::printValue( itemIt->value ) );
itemElem.setAttribute( QStringLiteral( "color" ), itemIt->color.name() );
itemElem.setAttribute( QStringLiteral( "alpha" ), itemIt->color.alpha() );
colorRampShaderElem.appendChild( itemElem );
}
return colorRampShaderElem;
}
void QgsColorRampShader::readXml( const QDomElement &colorRampShaderElem )
{
// try to load color ramp (optional)
QDomElement sourceColorRampElem = colorRampShaderElem.firstChildElement( QStringLiteral( "colorramp" ) );
if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral( "name" ) ) == QLatin1String( "[source]" ) )
{
setSourceColorRamp( QgsSymbolLayerUtils::loadColorRamp( sourceColorRampElem ) );
}
setColorRampType( colorRampShaderElem.attribute( QStringLiteral( "colorRampType" ), QStringLiteral( "INTERPOLATED" ) ) );
setClassificationMode( static_cast< QgsColorRampShader::ClassificationMode >( colorRampShaderElem.attribute( QStringLiteral( "classificationMode" ), QStringLiteral( "1" ) ).toInt() ) );
setClip( colorRampShaderElem.attribute( QStringLiteral( "clip" ), QStringLiteral( "0" ) ) == QLatin1String( "1" ) );
QList<QgsColorRampShader::ColorRampItem> itemList;
QDomElement itemElem;
QString itemLabel;
double itemValue;
QColor itemColor;
QDomNodeList itemNodeList = colorRampShaderElem.elementsByTagName( QStringLiteral( "item" ) );
itemList.reserve( itemNodeList.size() );
for ( int i = 0; i < itemNodeList.size(); ++i )
{
itemElem = itemNodeList.at( i ).toElement();
itemValue = itemElem.attribute( QStringLiteral( "value" ) ).toDouble();
itemLabel = itemElem.attribute( QStringLiteral( "label" ) );
itemColor.setNamedColor( itemElem.attribute( QStringLiteral( "color" ) ) );
itemColor.setAlpha( itemElem.attribute( QStringLiteral( "alpha" ), QStringLiteral( "255" ) ).toInt() );
itemList.push_back( QgsColorRampShader::ColorRampItem( itemValue, itemColor, itemLabel ) );
}
setColorRampItemList( itemList );
}

View File

@ -108,7 +108,7 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
Type colorRampType() const { return mColorRampType; }
//! Returns the color ramp type as a string.
QString colorRampTypeAsQString();
QString colorRampTypeAsQString() const;
//! Sets a custom colormap
void setColorRampItemList( const QList<QgsColorRampShader::ColorRampItem> &list ); //TODO: sort on set
@ -167,6 +167,18 @@ class CORE_EXPORT QgsColorRampShader : public QgsRasterShaderFunction
void legendSymbologyItems( QList< QPair< QString, QColor > > &symbolItems SIP_OUT ) const override;
/**
* Writes configuration to a new DOM element
* \since QGIS 3.4
*/
QDomElement writeXml( QDomDocument &doc ) const;
/**
* Reads configuration from the given DOM element
* \since QGIS 3.4
*/
void readXml( const QDomElement &elem );
//! Sets classification mode
void setClassificationMode( ClassificationMode classificationMode ) { mClassificationMode = classificationMode; }

View File

@ -99,31 +99,7 @@ void QgsRasterShader::writeXml( QDomDocument &doc, QDomElement &parent ) const
QgsColorRampShader *colorRampShader = dynamic_cast<QgsColorRampShader *>( mRasterShaderFunction.get() );
if ( colorRampShader )
{
QDomElement colorRampShaderElem = doc.createElement( QStringLiteral( "colorrampshader" ) );
colorRampShaderElem.setAttribute( QStringLiteral( "colorRampType" ), colorRampShader->colorRampTypeAsQString() );
colorRampShaderElem.setAttribute( QStringLiteral( "classificationMode" ), colorRampShader->classificationMode() );
colorRampShaderElem.setAttribute( QStringLiteral( "clip" ), colorRampShader->clip() );
// save source color ramp
if ( colorRampShader->sourceColorRamp() )
{
QDomElement colorRampElem = QgsSymbolLayerUtils::saveColorRamp( QStringLiteral( "[source]" ), colorRampShader->sourceColorRamp(), doc );
colorRampShaderElem.appendChild( colorRampElem );
}
//items
QList<QgsColorRampShader::ColorRampItem> itemList = colorRampShader->colorRampItemList();
QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList.constBegin();
for ( ; itemIt != itemList.constEnd(); ++itemIt )
{
QDomElement itemElem = doc.createElement( QStringLiteral( "item" ) );
itemElem.setAttribute( QStringLiteral( "label" ), itemIt->label );
itemElem.setAttribute( QStringLiteral( "value" ), QgsRasterBlock::printValue( itemIt->value ) );
itemElem.setAttribute( QStringLiteral( "color" ), itemIt->color.name() );
itemElem.setAttribute( QStringLiteral( "alpha" ), itemIt->color.alpha() );
colorRampShaderElem.appendChild( itemElem );
}
rasterShaderElem.appendChild( colorRampShaderElem );
rasterShaderElem.appendChild( colorRampShader->writeXml( doc ) );
}
parent.appendChild( rasterShaderElem );
}
@ -135,37 +111,7 @@ void QgsRasterShader::readXml( const QDomElement &elem )
if ( !colorRampShaderElem.isNull() )
{
QgsColorRampShader *colorRampShader = new QgsColorRampShader();
// try to load color ramp (optional)
QDomElement sourceColorRampElem = colorRampShaderElem.firstChildElement( QStringLiteral( "colorramp" ) );
if ( !sourceColorRampElem.isNull() && sourceColorRampElem.attribute( QStringLiteral( "name" ) ) == QLatin1String( "[source]" ) )
{
colorRampShader->setSourceColorRamp( QgsSymbolLayerUtils::loadColorRamp( sourceColorRampElem ) );
}
colorRampShader->setColorRampType( colorRampShaderElem.attribute( QStringLiteral( "colorRampType" ), QStringLiteral( "INTERPOLATED" ) ) );
colorRampShader->setClassificationMode( static_cast< QgsColorRampShader::ClassificationMode >( colorRampShaderElem.attribute( QStringLiteral( "classificationMode" ), QStringLiteral( "1" ) ).toInt() ) );
colorRampShader->setClip( colorRampShaderElem.attribute( QStringLiteral( "clip" ), QStringLiteral( "0" ) ) == QLatin1String( "1" ) );
QList<QgsColorRampShader::ColorRampItem> itemList;
QDomElement itemElem;
QString itemLabel;
double itemValue;
QColor itemColor;
QDomNodeList itemNodeList = colorRampShaderElem.elementsByTagName( QStringLiteral( "item" ) );
itemList.reserve( itemNodeList.size() );
for ( int i = 0; i < itemNodeList.size(); ++i )
{
itemElem = itemNodeList.at( i ).toElement();
itemValue = itemElem.attribute( QStringLiteral( "value" ) ).toDouble();
itemLabel = itemElem.attribute( QStringLiteral( "label" ) );
itemColor.setNamedColor( itemElem.attribute( QStringLiteral( "color" ) ) );
itemColor.setAlpha( itemElem.attribute( QStringLiteral( "alpha" ), QStringLiteral( "255" ) ).toInt() );
itemList.push_back( QgsColorRampShader::ColorRampItem( itemValue, itemColor, itemLabel ) );
}
colorRampShader->setColorRampItemList( itemList );
colorRampShader->readXml( colorRampShaderElem );
setRasterShaderFunction( colorRampShader );
}
}