Skip to content
Permalink
Browse files
Implement readXML for singleband pseudo color
  • Loading branch information
mhugent committed Apr 4, 2012
1 parent a6eaf71 commit 4da0c038b9c78739eea5563276c2f663c373dac6
Showing with 50 additions and 4 deletions.
  1. +32 −3 src/core/raster/qgsrastershader.cpp
  2. +2 −0 src/core/raster/qgsrastershader.h
  3. +16 −1 src/core/raster/qgssinglebandpseudocolorrenderer.cpp
@@ -129,21 +129,21 @@ void QgsRasterShader::setMinimumValue( double theValue )

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

QDomElement rasterShaderElem = doc.createElement( "rastershader" );
QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( mRasterShaderFunction );
if( colorRampShader )
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 )
for ( ; itemIt != itemList.constEnd(); ++itemIt )
{
QDomElement itemElem = doc.createElement( "item" );
itemElem.setAttribute( "label", itemIt->label );
@@ -155,3 +155,32 @@ void QgsRasterShader::writeXML( QDomDocument& doc, QDomElement& parent ) const
}
parent.appendChild( rasterShaderElem );
}

void QgsRasterShader::readXML( const QDomElement& elem )
{
//only colorrampshader
QDomElement colorRampShaderElem = elem.firstChildElement( "colorrampshader" );
if ( !colorRampShaderElem.isNull() )
{
QgsColorRampShader* colorRampShader = new QgsColorRampShader();
colorRampShader->setColorRampType( colorRampShaderElem.attribute( "colorRampType", "INTERPOLATED" ) );

QList<QgsColorRampShader::ColorRampItem> itemList;
QDomElement itemElem;
QString itemLabel;
double itemValue;
QColor itemColor;

QDomNodeList itemNodeList = colorRampShaderElem.elementsByTagName( "item" );
for ( int i = 0; i < itemNodeList.size(); ++i )
{
itemElem = itemNodeList.at( i ).toElement();
itemValue = itemElem.attribute( "value" ).toDouble();
itemLabel = itemElem.attribute( "label" );
itemColor.setNamedColor( itemElem.attribute( "color" ) );
itemList.push_back( QgsColorRampShader::ColorRampItem( itemValue, itemColor, itemLabel ) );
}
colorRampShader->setColorRampItemList( itemList );
setRasterShaderFunction( colorRampShader );
}
}
@@ -71,6 +71,8 @@ class CORE_EXPORT QgsRasterShader

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

void readXML( const QDomElement& elem );

private:
/** \brief User defineable minimum value for the raster shader */
double mMinimumValue;
@@ -41,7 +41,22 @@ void QgsSingleBandPseudoColorRenderer::setShader( QgsRasterShader* shader )

QgsRasterRenderer* QgsSingleBandPseudoColorRenderer::create( const QDomElement& elem, QgsRasterDataProvider* provider )
{
return 0;
if ( elem.isNull() )
{
return 0;
}

int band = elem.attribute( "band", "-1" ).toInt();
QgsRasterShader* shader = 0;
QDomElement rasterShaderElem = elem.firstChildElement( "rastershader" );
if ( !rasterShaderElem.isNull() )
{
shader = new QgsRasterShader();
shader->readXML( rasterShaderElem );
}
QgsRasterRenderer* r = new QgsSingleBandPseudoColorRenderer( provider, band, shader );
r->readXML( elem );
return r;
}

void QgsSingleBandPseudoColorRenderer::draw( QPainter* p, QgsRasterViewPort* viewPort, const QgsMapToPixel* theQgsMapToPixel )

0 comments on commit 4da0c03

Please sign in to comment.