Skip to content
Permalink
Browse files
writeXML for single band pseudo color renderer
  • Loading branch information
mhugent committed Apr 1, 2012
1 parent b9d4b6d commit 180c4fbc768f1bff951adc2229ac94a289fec9fe
Showing with 41 additions and 1 deletion.
  1. +32 −1 src/core/raster/qgsrastershader.cpp
  2. +5 −0 src/core/raster/qgsrastershader.h
  3. +4 −0 src/core/raster/qgssinglebandpseudocolorrenderer.cpp
@@ -17,8 +17,10 @@ email : ersts@amnh.org
***************************************************************************/

#include "qgslogger.h"

#include "qgscolorrampshader.h"
#include "qgsrastershader.h"
#include <QDomDocument>
#include <QDomElement>

QgsRasterShader::QgsRasterShader( double theMinimumValue, double theMaximumValue )
{
@@ -124,3 +126,32 @@ void QgsRasterShader::setMinimumValue( double theValue )
mRasterShaderFunction->setMinimumValue( theValue );
}
}

void QgsRasterShader::writeXML( QDomDocument& doc, QDomElement& parent ) const
{
if( parent.isNull() || !mRasterShaderFunction )
{
return;
}

QDomElement rasterShaderElem = doc.createElement( "rastershader" );
QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( mRasterShaderFunction );
if( colorRampShader )
{
QDomElement colorRampShaderElem = doc.createElement( "colorrampshader" );
colorRampShaderElem.setAttribute( "colorRampType", colorRampShader->colorRampTypeAsQString() );
//items
QList<QgsColorRampShader::ColorRampItem> itemList = colorRampShader->colorRampItemList();
QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList.constBegin();
for(; itemIt != itemList.constEnd(); ++itemIt )
{
QDomElement itemElem = doc.createElement( "item" );
itemElem.setAttribute( "label", itemIt->label );
itemElem.setAttribute( "value", itemIt->value );
itemElem.setAttribute( "color", itemIt->color.name() );
colorRampShaderElem.appendChild( itemElem );
}
rasterShaderElem.appendChild( colorRampShaderElem );
}
parent.appendChild( rasterShaderElem );
}
@@ -22,6 +22,9 @@ email : ersts@amnh.org

#include "qgsrastershaderfunction.h"

class QDomDocument;
class QDomElement;

/** \ingroup core
* Interface for all raster shaders.
*/
@@ -66,6 +69,8 @@ class CORE_EXPORT QgsRasterShader
/** \brief Return the minimum value */
void setMinimumValue( double );

void writeXML( QDomDocument& doc, QDomElement& parent ) const;

private:
/** \brief User defineable minimum value for the raster shader */
double mMinimumValue;
@@ -158,5 +158,9 @@ void QgsSingleBandPseudoColorRenderer::writeXML( QDomDocument& doc, QDomElement&
QDomElement rasterRendererElem = doc.createElement( "rasterrenderer" );
_writeXML( doc, rasterRendererElem );
rasterRendererElem.setAttribute( "band", mBand );
if( mShader )
{
mShader->writeXML( doc, rasterRendererElem ); //todo: include color ramp items directly in this renderer
}
parentElem.appendChild( rasterRendererElem );
}

0 comments on commit 180c4fb

Please sign in to comment.