Skip to content

Commit 136a65c

Browse files
committed
sld support: use Title tag (instead of Abstract) exporting styles to SLD (fix #6152)
1 parent 3305ccd commit 136a65c

4 files changed

+60
-23
lines changed

src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ void QgsRendererCategoryV2::toSld( QDomDocument &doc, QDomElement &element, QgsS
9797
ruleElem.appendChild( nameElem );
9898

9999
QDomElement descrElem = doc.createElement( "se:Description" );
100-
QDomElement abstractElem = doc.createElement( "se:Abstract" );
100+
QDomElement titleElem = doc.createElement( "se:Title" );
101101
QString descrStr = QString( "%1 is '%2'" ).arg( attrName ).arg( mValue.toString() );
102-
abstractElem.appendChild( doc.createTextNode( !mLabel.isEmpty() ? mLabel : descrStr ) );
103-
descrElem.appendChild( abstractElem );
102+
titleElem.appendChild( doc.createTextNode( !mLabel.isEmpty() ? mLabel : descrStr ) );
103+
descrElem.appendChild( titleElem );
104104
ruleElem.appendChild( descrElem );
105105

106106
// create the ogc:Filter for the range

src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ void QgsRendererRangeV2::toSld( QDomDocument &doc, QDomElement &element, QgsStri
114114
ruleElem.appendChild( nameElem );
115115

116116
QDomElement descrElem = doc.createElement( "se:Description" );
117-
QDomElement abstractElem = doc.createElement( "se:Abstract" );
117+
QDomElement titleElem = doc.createElement( "se:Title" );
118118
QString descrStr = QString( "range: %1 - %2" ).arg( mLowerValue ).arg( mUpperValue );
119-
abstractElem.appendChild( doc.createTextNode( !mLabel.isEmpty() ? mLabel : descrStr ) );
120-
descrElem.appendChild( abstractElem );
119+
titleElem.appendChild( doc.createTextNode( !mLabel.isEmpty() ? mLabel : descrStr ) );
120+
descrElem.appendChild( titleElem );
121121
ruleElem.appendChild( descrElem );
122122

123123
// create the ogc:Filter for the range

src/core/symbology-ng/qgsrulebasedrendererv2.cpp

+28-15
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,27 @@ void QgsRuleBasedRendererV2::Rule::toSld( QDomDocument& doc, QDomElement &elemen
226226
QDomElement ruleElem = doc.createElement( "se:Rule" );
227227
element.appendChild( ruleElem );
228228

229+
//XXX: <se:Name> is the rule identifier, but our the Rule objects
230+
// have no properties could be used as identifier. Use the label.
229231
QDomElement nameElem = doc.createElement( "se:Name" );
230232
nameElem.appendChild( doc.createTextNode( mLabel ) );
231233
ruleElem.appendChild( nameElem );
232234

233-
if ( !mDescription.isEmpty() )
235+
if ( !mLabel.isEmpty() || !mDescription.isEmpty() )
234236
{
235237
QDomElement descrElem = doc.createElement( "se:Description" );
236-
QDomElement abstractElem = doc.createElement( "se:Abstract" );
237-
abstractElem.appendChild( doc.createTextNode( mDescription ) );
238-
descrElem.appendChild( abstractElem );
238+
if ( !mLabel.isEmpty() )
239+
{
240+
QDomElement titleElem = doc.createElement( "se:Title" );
241+
titleElem.appendChild( doc.createTextNode( mLabel ) );
242+
descrElem.appendChild( titleElem );
243+
}
244+
if ( !mDescription.isEmpty() )
245+
{
246+
QDomElement abstractElem = doc.createElement( "se:Abstract" );
247+
abstractElem.appendChild( doc.createTextNode( mDescription ) );
248+
descrElem.appendChild( abstractElem );
249+
}
239250
ruleElem.appendChild( descrElem );
240251
}
241252

@@ -477,33 +488,35 @@ QgsRuleBasedRendererV2::Rule* QgsRuleBasedRendererV2::Rule::createFromSld( QDomE
477488
{
478489
if ( childElem.localName() == "Name" )
479490
{
480-
label = childElem.firstChild().nodeValue();
491+
// <se:Name> tag contains the rule identifier,
492+
// so prefer title tag for the label property value
493+
if ( label.isEmpty() )
494+
label = childElem.firstChild().nodeValue();
481495
}
482496
else if ( childElem.localName() == "Description" )
483497
{
484498
// <se:Description> can contains a title and an abstract
485-
// prefer Abstract if available
486-
QDomElement abstractElem = childElem.firstChildElement( "Abstract" );
487499
QDomElement titleElem = childElem.firstChildElement( "Title" );
488-
if ( !abstractElem.isNull() )
500+
if ( !titleElem.isNull() )
489501
{
490-
description = abstractElem.firstChild().nodeValue();
502+
label = titleElem.firstChild().nodeValue();
491503
}
492-
else if ( !titleElem.isNull() && description.isEmpty() )
504+
505+
QDomElement abstractElem = childElem.firstChildElement( "Abstract" );
506+
if ( !abstractElem.isNull() )
493507
{
494-
description = titleElem.firstChild().nodeValue();
508+
description = abstractElem.firstChild().nodeValue();
495509
}
496510
}
497511
else if ( childElem.localName() == "Abstract" )
498512
{
499-
// <sld:Abstract>
513+
// <sld:Abstract> (v1.0)
500514
description = childElem.firstChild().nodeValue();
501515
}
502516
else if ( childElem.localName() == "Title" )
503517
{
504-
// <sld:Title>
505-
if ( description.isEmpty() )
506-
description = childElem.firstChild().nodeValue();
518+
// <sld:Title> (v1.0)
519+
label = childElem.firstChild().nodeValue();
507520
}
508521
else if ( childElem.localName() == "Filter" )
509522
{

src/core/symbology-ng/qgssinglesymbolrendererv2.cpp

+26-2
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,36 @@ QgsFeatureRendererV2* QgsSingleSymbolRendererV2::createFromSld( QDomElement& ele
260260
{
261261
if ( childElem.localName() == "Name" )
262262
{
263-
label = childElem.firstChild().nodeValue();
263+
// <se:Name> tag contains the rule identifier,
264+
// so prefer title tag for the label property value
265+
if ( label.isEmpty() )
266+
label = childElem.firstChild().nodeValue();
267+
}
268+
else if ( childElem.localName() == "Description" )
269+
{
270+
// <se:Description> can contains a title and an abstract
271+
QDomElement titleElem = childElem.firstChildElement( "Title" );
272+
if ( !titleElem.isNull() )
273+
{
274+
label = titleElem.firstChild().nodeValue();
275+
}
276+
277+
QDomElement abstractElem = childElem.firstChildElement( "Abstract" );
278+
if ( !abstractElem.isNull() )
279+
{
280+
description = abstractElem.firstChild().nodeValue();
281+
}
264282
}
265-
else if ( childElem.localName() == "Description" || childElem.localName() == "Abstract" )
283+
else if ( childElem.localName() == "Abstract" )
266284
{
285+
// <sld:Abstract> (v1.0)
267286
description = childElem.firstChild().nodeValue();
268287
}
288+
else if ( childElem.localName() == "Title" )
289+
{
290+
// <sld:Title> (v1.0)
291+
label = childElem.firstChild().nodeValue();
292+
}
269293
else if ( childElem.localName().endsWith( "Symbolizer" ) )
270294
{
271295
// create symbol layers for this symbolizer

0 commit comments

Comments
 (0)