Skip to content

Commit

Permalink
writeXML for single band pseudo color renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Apr 1, 2012
1 parent b9d4b6d commit 180c4fb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/core/raster/qgsrastershader.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 );
}
5 changes: 5 additions & 0 deletions src/core/raster/qgsrastershader.h
Expand Up @@ -22,6 +22,9 @@ email : ersts@amnh.org

#include "qgsrastershaderfunction.h"

class QDomDocument;
class QDomElement;

/** \ingroup core
* Interface for all raster shaders.
*/
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/core/raster/qgssinglebandpseudocolorrenderer.cpp
Expand Up @@ -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.