Skip to content

Commit

Permalink
sld support: use Title tag (instead of Abstract) exporting styles to …
Browse files Browse the repository at this point in the history
…SLD (fix #6152)
  • Loading branch information
brushtyler committed Aug 4, 2012
1 parent 3305ccd commit 136a65c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgscategorizedsymbolrendererv2.cpp
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/core/symbology-ng/qgsgraduatedsymbolrendererv2.cpp
Expand Up @@ -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
Expand Down
43 changes: 28 additions & 15 deletions src/core/symbology-ng/qgsrulebasedrendererv2.cpp
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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" )
{
Expand Down
28 changes: 26 additions & 2 deletions src/core/symbology-ng/qgssinglesymbolrendererv2.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 136a65c

Please sign in to comment.