Skip to content

Commit 180c4fb

Browse files
committed
writeXML for single band pseudo color renderer
1 parent b9d4b6d commit 180c4fb

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/core/raster/qgsrastershader.cpp

+32-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ email : ersts@amnh.org
1717
***************************************************************************/
1818

1919
#include "qgslogger.h"
20-
20+
#include "qgscolorrampshader.h"
2121
#include "qgsrastershader.h"
22+
#include <QDomDocument>
23+
#include <QDomElement>
2224

2325
QgsRasterShader::QgsRasterShader( double theMinimumValue, double theMaximumValue )
2426
{
@@ -124,3 +126,32 @@ void QgsRasterShader::setMinimumValue( double theValue )
124126
mRasterShaderFunction->setMinimumValue( theValue );
125127
}
126128
}
129+
130+
void QgsRasterShader::writeXML( QDomDocument& doc, QDomElement& parent ) const
131+
{
132+
if( parent.isNull() || !mRasterShaderFunction )
133+
{
134+
return;
135+
}
136+
137+
QDomElement rasterShaderElem = doc.createElement( "rastershader" );
138+
QgsColorRampShader* colorRampShader = dynamic_cast<QgsColorRampShader*>( mRasterShaderFunction );
139+
if( colorRampShader )
140+
{
141+
QDomElement colorRampShaderElem = doc.createElement( "colorrampshader" );
142+
colorRampShaderElem.setAttribute( "colorRampType", colorRampShader->colorRampTypeAsQString() );
143+
//items
144+
QList<QgsColorRampShader::ColorRampItem> itemList = colorRampShader->colorRampItemList();
145+
QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList.constBegin();
146+
for(; itemIt != itemList.constEnd(); ++itemIt )
147+
{
148+
QDomElement itemElem = doc.createElement( "item" );
149+
itemElem.setAttribute( "label", itemIt->label );
150+
itemElem.setAttribute( "value", itemIt->value );
151+
itemElem.setAttribute( "color", itemIt->color.name() );
152+
colorRampShaderElem.appendChild( itemElem );
153+
}
154+
rasterShaderElem.appendChild( colorRampShaderElem );
155+
}
156+
parent.appendChild( rasterShaderElem );
157+
}

src/core/raster/qgsrastershader.h

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ email : ersts@amnh.org
2222

2323
#include "qgsrastershaderfunction.h"
2424

25+
class QDomDocument;
26+
class QDomElement;
27+
2528
/** \ingroup core
2629
* Interface for all raster shaders.
2730
*/
@@ -66,6 +69,8 @@ class CORE_EXPORT QgsRasterShader
6669
/** \brief Return the minimum value */
6770
void setMinimumValue( double );
6871

72+
void writeXML( QDomDocument& doc, QDomElement& parent ) const;
73+
6974
private:
7075
/** \brief User defineable minimum value for the raster shader */
7176
double mMinimumValue;

src/core/raster/qgssinglebandpseudocolorrenderer.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -158,5 +158,9 @@ void QgsSingleBandPseudoColorRenderer::writeXML( QDomDocument& doc, QDomElement&
158158
QDomElement rasterRendererElem = doc.createElement( "rasterrenderer" );
159159
_writeXML( doc, rasterRendererElem );
160160
rasterRendererElem.setAttribute( "band", mBand );
161+
if( mShader )
162+
{
163+
mShader->writeXML( doc, rasterRendererElem ); //todo: include color ramp items directly in this renderer
164+
}
161165
parentElem.appendChild( rasterRendererElem );
162166
}

0 commit comments

Comments
 (0)