@@ -129,21 +129,21 @@ void QgsRasterShader::setMinimumValue( double theValue )
129
129
130
130
void QgsRasterShader::writeXML ( QDomDocument& doc, QDomElement& parent ) const
131
131
{
132
- if ( parent.isNull () || !mRasterShaderFunction )
132
+ if ( parent.isNull () || !mRasterShaderFunction )
133
133
{
134
134
return ;
135
135
}
136
136
137
137
QDomElement rasterShaderElem = doc.createElement ( " rastershader" );
138
138
QgsColorRampShader* colorRampShader = dynamic_cast <QgsColorRampShader*>( mRasterShaderFunction );
139
- if ( colorRampShader )
139
+ if ( colorRampShader )
140
140
{
141
141
QDomElement colorRampShaderElem = doc.createElement ( " colorrampshader" );
142
142
colorRampShaderElem.setAttribute ( " colorRampType" , colorRampShader->colorRampTypeAsQString () );
143
143
// items
144
144
QList<QgsColorRampShader::ColorRampItem> itemList = colorRampShader->colorRampItemList ();
145
145
QList<QgsColorRampShader::ColorRampItem>::const_iterator itemIt = itemList.constBegin ();
146
- for ( ; itemIt != itemList.constEnd (); ++itemIt )
146
+ for ( ; itemIt != itemList.constEnd (); ++itemIt )
147
147
{
148
148
QDomElement itemElem = doc.createElement ( " item" );
149
149
itemElem.setAttribute ( " label" , itemIt->label );
@@ -155,3 +155,32 @@ void QgsRasterShader::writeXML( QDomDocument& doc, QDomElement& parent ) const
155
155
}
156
156
parent.appendChild ( rasterShaderElem );
157
157
}
158
+
159
+ void QgsRasterShader::readXML ( const QDomElement& elem )
160
+ {
161
+ // only colorrampshader
162
+ QDomElement colorRampShaderElem = elem.firstChildElement ( " colorrampshader" );
163
+ if ( !colorRampShaderElem.isNull () )
164
+ {
165
+ QgsColorRampShader* colorRampShader = new QgsColorRampShader ();
166
+ colorRampShader->setColorRampType ( colorRampShaderElem.attribute ( " colorRampType" , " INTERPOLATED" ) );
167
+
168
+ QList<QgsColorRampShader::ColorRampItem> itemList;
169
+ QDomElement itemElem;
170
+ QString itemLabel;
171
+ double itemValue;
172
+ QColor itemColor;
173
+
174
+ QDomNodeList itemNodeList = colorRampShaderElem.elementsByTagName ( " item" );
175
+ for ( int i = 0 ; i < itemNodeList.size (); ++i )
176
+ {
177
+ itemElem = itemNodeList.at ( i ).toElement ();
178
+ itemValue = itemElem.attribute ( " value" ).toDouble ();
179
+ itemLabel = itemElem.attribute ( " label" );
180
+ itemColor.setNamedColor ( itemElem.attribute ( " color" ) );
181
+ itemList.push_back ( QgsColorRampShader::ColorRampItem ( itemValue, itemColor, itemLabel ) );
182
+ }
183
+ colorRampShader->setColorRampItemList ( itemList );
184
+ setRasterShaderFunction ( colorRampShader );
185
+ }
186
+ }
0 commit comments