Skip to content
Permalink
Browse files

SLD support: fix conversion between dash style and dasharray, retriev…

…e displacement offset
  • Loading branch information
brushtyler committed Aug 27, 2012
1 parent 7feb1c3 commit f57a0644e7349da7496622cfbe7065a497656b21
Showing with 37 additions and 26 deletions.
  1. +37 −26 src/core/symbology-ng/qgssymbollayerv2utils.cpp
@@ -1513,11 +1513,12 @@ void QgsSymbolLayerV2Utils::lineToSld( QDomDocument &doc, QDomElement &element,
const QVector<qreal> *customDashPattern, double dashOffset )
{
QVector<qreal> dashPattern;
const QVector<qreal> *pattern = &dashPattern;

if ( penStyle == Qt::CustomDashLine && !customDashPattern )
{
element.appendChild( doc.createComment( "WARNING: Custom dash pattern required but not provided. Using default dash pattern." ) );
penStyle = Qt::DashLine;
customDashPattern = &dashPattern;
}

switch ( penStyle )
@@ -1553,6 +1554,7 @@ void QgsSymbolLayerV2Utils::lineToSld( QDomDocument &doc, QDomElement &element,

case Qt::CustomDashLine:
Q_ASSERT( customDashPattern );
pattern = customDashPattern;
break;

default:
@@ -1573,9 +1575,9 @@ void QgsSymbolLayerV2Utils::lineToSld( QDomDocument &doc, QDomElement &element,
if ( penCapStyle )
element.appendChild( createSvgParameterElement( doc, "stroke-linecap", encodeSldLineCapStyle( *penCapStyle ) ) );

if ( customDashPattern && customDashPattern->size() > 0 )
if ( pattern->size() > 0 )
{
element.appendChild( createSvgParameterElement( doc, "stroke-dasharray", encodeSldRealVector( *customDashPattern ) ) );
element.appendChild( createSvgParameterElement( doc, "stroke-dasharray", encodeSldRealVector( *pattern ) ) );
if ( !doubleNear( dashOffset, 0.0 ) )
element.appendChild( createSvgParameterElement( doc, "stroke-dashoffset", QString::number( dashOffset ) ) );
}
@@ -1636,49 +1638,49 @@ bool QgsSymbolLayerV2Utils::lineFromSld( QDomElement &element,
{
*penCapStyle = decodeSldLineCapStyle( it.value() );
}
else if ( it.key() == "stroke-dasharray" && customDashPattern )
else if ( it.key() == "stroke-dasharray" )
{
*customDashPattern = decodeSldRealVector( it.value() );
if ( customDashPattern->size() > 0 )
QVector<qreal> dashPattern = decodeSldRealVector( it.value() );
if ( dashPattern.size() > 0 )
{
// convert the dasharray to one of the QT pen style,
// if no match is found then set pen style to CustomDashLine
bool dashPatternFound = false;

if ( customDashPattern->count() == 2 )
if ( dashPattern.count() == 2 )
{
if ( customDashPattern->at( 0 ) == 4.0 &&
customDashPattern->at( 1 ) == 2.0 )
if ( dashPattern.at( 0 ) == 4.0 &&
dashPattern.at( 1 ) == 2.0 )
{
penStyle = Qt::DashLine;
dashPatternFound = true;
}
else if ( customDashPattern->at( 0 ) == 1.0 &&
customDashPattern->at( 1 ) == 2.0 )
else if ( dashPattern.at( 0 ) == 1.0 &&
dashPattern.at( 1 ) == 2.0 )
{
penStyle = Qt::DotLine;
dashPatternFound = true;
}
}
else if ( customDashPattern->count() == 4 )
else if ( dashPattern.count() == 4 )
{
if ( customDashPattern->at( 0 ) == 4.0 &&
customDashPattern->at( 1 ) == 2.0 &&
customDashPattern->at( 2 ) == 1.0 &&
customDashPattern->at( 3 ) == 2.0 )
if ( dashPattern.at( 0 ) == 4.0 &&
dashPattern.at( 1 ) == 2.0 &&
dashPattern.at( 2 ) == 1.0 &&
dashPattern.at( 3 ) == 2.0 )
{
penStyle = Qt::DashDotLine;
dashPatternFound = true;
}
}
else if ( customDashPattern->count() == 6 )
else if ( dashPattern.count() == 6 )
{
if ( customDashPattern->at( 0 ) == 4.0 &&
customDashPattern->at( 1 ) == 2.0 &&
customDashPattern->at( 2 ) == 1.0 &&
customDashPattern->at( 3 ) == 2.0 &&
customDashPattern->at( 4 ) == 1.0 &&
customDashPattern->at( 5 ) == 2.0 )
if ( dashPattern.at( 0 ) == 4.0 &&
dashPattern.at( 1 ) == 2.0 &&
dashPattern.at( 2 ) == 1.0 &&
dashPattern.at( 3 ) == 2.0 &&
dashPattern.at( 4 ) == 1.0 &&
dashPattern.at( 5 ) == 2.0 )
{
penStyle = Qt::DashDotDotLine;
dashPatternFound = true;
@@ -1688,7 +1690,16 @@ bool QgsSymbolLayerV2Utils::lineFromSld( QDomElement &element,
// default case: set pen style to CustomDashLine
if ( !dashPatternFound )
{
penStyle = Qt::CustomDashLine;
if ( customDashPattern )
{
penStyle = Qt::CustomDashLine;
*customDashPattern = dashPattern;
}
else
{
QgsDebugMsg( "custom dash pattern required but not provided. Using default dash pattern." );
penStyle = Qt::DashLine;
}
}
}
}
@@ -1974,7 +1985,7 @@ bool QgsSymbolLayerV2Utils::displacementFromSldElement( QDomElement &element, QP
if ( displacementElem.isNull() )
return true;

QDomElement dispXElem = element.firstChildElement( "DisplacementX" );
QDomElement dispXElem = displacementElem.firstChildElement( "DisplacementX" );
if ( !dispXElem.isNull() )
{
bool ok;
@@ -1983,7 +1994,7 @@ bool QgsSymbolLayerV2Utils::displacementFromSldElement( QDomElement &element, QP
offset.setX( offsetX );
}

QDomElement dispYElem = element.firstChildElement( "DisplacementY" );
QDomElement dispYElem = displacementElem.firstChildElement( "DisplacementY" );
if ( !dispYElem.isNull() )
{
bool ok;

0 comments on commit f57a064

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