Skip to content
Permalink
Browse files

sld support: use Title tag (instead of Abstract) exporting styles to …

…SLD (fix #6152)
  • Loading branch information
brushtyler committed Aug 4, 2012
1 parent 3305ccd commit 136a65c7b455ae0d0e1fbcc7c351ebe57ddd45d0
@@ -97,10 +97,10 @@ void QgsRendererCategoryV2::toSld( QDomDocument &doc, QDomElement &element, QgsS
ruleElem.appendChild( nameElem );

QDomElement descrElem = doc.createElement( "se:Description" );
QDomElement abstractElem = doc.createElement( "se:Abstract" );
QDomElement titleElem = doc.createElement( "se:Title" );
QString descrStr = QString( "%1 is '%2'" ).arg( attrName ).arg( mValue.toString() );
abstractElem.appendChild( doc.createTextNode( !mLabel.isEmpty() ? mLabel : descrStr ) );
descrElem.appendChild( abstractElem );
titleElem.appendChild( doc.createTextNode( !mLabel.isEmpty() ? mLabel : descrStr ) );
descrElem.appendChild( titleElem );
ruleElem.appendChild( descrElem );

// create the ogc:Filter for the range
@@ -114,10 +114,10 @@ void QgsRendererRangeV2::toSld( QDomDocument &doc, QDomElement &element, QgsStri
ruleElem.appendChild( nameElem );

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

// create the ogc:Filter for the range
@@ -226,16 +226,27 @@ void QgsRuleBasedRendererV2::Rule::toSld( QDomDocument& doc, QDomElement &elemen
QDomElement ruleElem = doc.createElement( "se:Rule" );
element.appendChild( ruleElem );

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

if ( !mDescription.isEmpty() )
if ( !mLabel.isEmpty() || !mDescription.isEmpty() )
{
QDomElement descrElem = doc.createElement( "se:Description" );
QDomElement abstractElem = doc.createElement( "se:Abstract" );
abstractElem.appendChild( doc.createTextNode( mDescription ) );
descrElem.appendChild( abstractElem );
if ( !mLabel.isEmpty() )
{
QDomElement titleElem = doc.createElement( "se:Title" );
titleElem.appendChild( doc.createTextNode( mLabel ) );
descrElem.appendChild( titleElem );
}
if ( !mDescription.isEmpty() )
{
QDomElement abstractElem = doc.createElement( "se:Abstract" );
abstractElem.appendChild( doc.createTextNode( mDescription ) );
descrElem.appendChild( abstractElem );
}
ruleElem.appendChild( descrElem );
}

@@ -477,33 +488,35 @@ QgsRuleBasedRendererV2::Rule* QgsRuleBasedRendererV2::Rule::createFromSld( QDomE
{
if ( childElem.localName() == "Name" )
{
label = childElem.firstChild().nodeValue();
// <se:Name> tag contains the rule identifier,
// so prefer title tag for the label property value
if ( label.isEmpty() )
label = childElem.firstChild().nodeValue();
}
else if ( childElem.localName() == "Description" )
{
// <se:Description> can contains a title and an abstract
// prefer Abstract if available
QDomElement abstractElem = childElem.firstChildElement( "Abstract" );
QDomElement titleElem = childElem.firstChildElement( "Title" );
if ( !abstractElem.isNull() )
if ( !titleElem.isNull() )
{
description = abstractElem.firstChild().nodeValue();
label = titleElem.firstChild().nodeValue();
}
else if ( !titleElem.isNull() && description.isEmpty() )

QDomElement abstractElem = childElem.firstChildElement( "Abstract" );
if ( !abstractElem.isNull() )
{
description = titleElem.firstChild().nodeValue();
description = abstractElem.firstChild().nodeValue();
}
}
else if ( childElem.localName() == "Abstract" )
{
// <sld:Abstract>
// <sld:Abstract> (v1.0)
description = childElem.firstChild().nodeValue();
}
else if ( childElem.localName() == "Title" )
{
// <sld:Title>
if ( description.isEmpty() )
description = childElem.firstChild().nodeValue();
// <sld:Title> (v1.0)
label = childElem.firstChild().nodeValue();
}
else if ( childElem.localName() == "Filter" )
{
@@ -260,12 +260,36 @@ QgsFeatureRendererV2* QgsSingleSymbolRendererV2::createFromSld( QDomElement& ele
{
if ( childElem.localName() == "Name" )
{
label = childElem.firstChild().nodeValue();
// <se:Name> tag contains the rule identifier,
// so prefer title tag for the label property value
if ( label.isEmpty() )
label = childElem.firstChild().nodeValue();
}
else if ( childElem.localName() == "Description" )
{
// <se:Description> can contains a title and an abstract
QDomElement titleElem = childElem.firstChildElement( "Title" );
if ( !titleElem.isNull() )
{
label = titleElem.firstChild().nodeValue();
}

QDomElement abstractElem = childElem.firstChildElement( "Abstract" );
if ( !abstractElem.isNull() )
{
description = abstractElem.firstChild().nodeValue();
}
}
else if ( childElem.localName() == "Description" || childElem.localName() == "Abstract" )
else if ( childElem.localName() == "Abstract" )
{
// <sld:Abstract> (v1.0)
description = childElem.firstChild().nodeValue();
}
else if ( childElem.localName() == "Title" )
{
// <sld:Title> (v1.0)
label = childElem.firstChild().nodeValue();
}
else if ( childElem.localName().endsWith( "Symbolizer" ) )
{
// create symbol layers for this symbolizer

0 comments on commit 136a65c

Please sign in to comment.
You can’t perform that action at this time.