Skip to content

Commit

Permalink
#9254: Support for OutlineStyle in SLD files
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed Jan 2, 2014
1 parent 8a1d769 commit 4f6c9cd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions python/core/symbology-ng/qgssymbollayerv2utils.sip
Expand Up @@ -112,10 +112,10 @@ class QgsSymbolLayerV2Utils
QColor &color, double &size );

static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
QString name, QColor color, QColor borderColor = QColor(),
QString name, QColor color, QColor borderColor = QColor(), Qt::PenStyle borderStyle = Qt::SolidLine,
double borderWidth = -1, double size = -1 );
static bool wellKnownMarkerFromSld( QDomElement &element,
QString &name, QColor &color, QColor &borderColor,
QString &name, QColor &color, QColor &borderColor, Qt::PenStyle &borderStyle,
double &borderWidth, double &size );

static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
Expand Down
6 changes: 4 additions & 2 deletions src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Expand Up @@ -301,7 +301,7 @@ void QgsEllipseSymbolLayerV2::writeSldMarker( QDomDocument &doc, QDomElement &el
QDomElement graphicElem = doc.createElement( "se:Graphic" );
element.appendChild( graphicElem );

QgsSymbolLayerV2Utils::wellKnownMarkerToSld( doc, graphicElem, mSymbolName, mFillColor, mOutlineColor, mOutlineWidth, mSymbolWidth );
QgsSymbolLayerV2Utils::wellKnownMarkerToSld( doc, graphicElem, mSymbolName, mFillColor, mOutlineColor, mOutlineStyle, mOutlineWidth, mSymbolWidth );

// store w/h factor in a <VendorOption>
double widthHeightFactor = mSymbolWidth / mSymbolHeight;
Expand Down Expand Up @@ -356,6 +356,7 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::createFromSld( QDomElement &element )
QColor fillColor, borderColor;
double borderWidth, size;
double widthHeightFactor = 1.0;
Qt::PenStyle borderStyle;

QgsStringMap vendorOptions = QgsSymbolLayerV2Utils::getVendorOptionList( graphicElem );
for ( QgsStringMap::iterator it = vendorOptions.begin(); it != vendorOptions.end(); ++it )
Expand All @@ -369,7 +370,7 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::createFromSld( QDomElement &element )
}
}

if ( !QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderWidth, size ) )
if ( !QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderStyle, borderWidth, size ) )
return NULL;

double angle = 0.0;
Expand All @@ -386,6 +387,7 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::createFromSld( QDomElement &element )
m->setSymbolName( name );
m->setFillColor( fillColor );
m->setOutlineColor( borderColor );
m->setOutlineStyle( borderStyle );
m->setOutlineWidth( borderWidth );
m->setSymbolWidth( size );
m->setSymbolHeight( size / widthHeightFactor );
Expand Down
5 changes: 3 additions & 2 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -1597,7 +1597,7 @@ void QgsLinePatternFillSymbolLayer::toSld( QDomDocument &doc, QDomElement &eleme
QDomElement graphicElem = doc.createElement( "se:Graphic" );
graphicFillElem.appendChild( graphicElem );

QgsSymbolLayerV2Utils::wellKnownMarkerToSld( doc, graphicElem, "horline", QColor(), mColor, mLineWidth, mDistance );
QgsSymbolLayerV2Utils::wellKnownMarkerToSld( doc, graphicElem, "horline", QColor(), mColor, Qt::SolidLine, mLineWidth, mDistance );

// <Rotation>
QString angleFunc;
Expand Down Expand Up @@ -1682,6 +1682,7 @@ QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::createFromSld( QDomElement &ele
QString name;
QColor fillColor, lineColor;
double size, lineWidth;
Qt::PenStyle lineStyle;

QDomElement fillElem = element.firstChildElement( "Fill" );
if ( fillElem.isNull() )
Expand All @@ -1695,7 +1696,7 @@ QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::createFromSld( QDomElement &ele
if ( graphicElem.isNull() )
return NULL;

if ( !QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( graphicElem, name, fillColor, lineColor, lineWidth, size ) )
if ( !QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( graphicElem, name, fillColor, lineColor, lineStyle, lineWidth, size ) )
return NULL;

if ( name != "horline" )
Expand Down
8 changes: 5 additions & 3 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -605,7 +605,7 @@ void QgsSimpleMarkerSymbolLayerV2::writeSldMarker( QDomDocument &doc, QDomElemen
QDomElement graphicElem = doc.createElement( "se:Graphic" );
element.appendChild( graphicElem );

QgsSymbolLayerV2Utils::wellKnownMarkerToSld( doc, graphicElem, mName, mColor, mBorderColor, -1, mSize );
QgsSymbolLayerV2Utils::wellKnownMarkerToSld( doc, graphicElem, mName, mColor, mBorderColor, mOutlineStyle, mOutlineWidth, mSize );

// <Rotation>
QString angleFunc;
Expand Down Expand Up @@ -698,8 +698,9 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::createFromSld( QDomElement &elem
QString name = "square";
QColor color, borderColor;
double borderWidth, size;
Qt::PenStyle borderStyle;

if ( !QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( graphicElem, name, color, borderColor, borderWidth, size ) )
if ( !QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( graphicElem, name, color, borderColor, borderStyle, borderWidth, size ) )
return NULL;

double angle = 0.0;
Expand All @@ -715,9 +716,10 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::createFromSld( QDomElement &elem
QPointF offset;
QgsSymbolLayerV2Utils::displacementFromSldElement( graphicElem, offset );

QgsMarkerSymbolLayerV2 *m = new QgsSimpleMarkerSymbolLayerV2( name, color, borderColor, size );
QgsSimpleMarkerSymbolLayerV2 *m = new QgsSimpleMarkerSymbolLayerV2( name, color, borderColor, size );
m->setAngle( angle );
m->setOffset( offset );
m->setOutlineStyle( borderStyle );
return m;
}

Expand Down
15 changes: 8 additions & 7 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -1180,7 +1180,8 @@ bool QgsSymbolLayerV2Utils::needLinePatternFill( QDomElement &element )
QString name;
QColor fillColor, borderColor;
double size, borderWidth;
if ( !wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderWidth, size ) )
Qt::PenStyle borderStyle;
if ( !wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderStyle, borderWidth, size ) )
return false;

if ( name != "horline" )
Expand Down Expand Up @@ -1561,7 +1562,8 @@ bool QgsSymbolLayerV2Utils::fillFromSld( QDomElement &element, Qt::BrushStyle &b
QString patternName = "square";
QColor fillColor, borderColor;
double borderWidth, size;
if ( !wellKnownMarkerFromSld( graphicElem, patternName, fillColor, borderColor, borderWidth, size ) )
Qt::PenStyle borderStyle;
if ( !wellKnownMarkerFromSld( graphicElem, patternName, fillColor, borderColor, borderStyle, borderWidth, size ) )
return false;

brushStyle = decodeSldBrushStyle( patternName );
Expand Down Expand Up @@ -1904,7 +1906,7 @@ bool QgsSymbolLayerV2Utils::externalMarkerFromSld( QDomElement &element,
}

void QgsSymbolLayerV2Utils::wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
QString name, QColor color, QColor borderColor,
QString name, QColor color, QColor borderColor, Qt::PenStyle borderStyle,
double borderWidth, double size )
{
QDomElement markElem = doc.createElement( "se:Mark" );
Expand All @@ -1926,7 +1928,7 @@ void QgsSymbolLayerV2Utils::wellKnownMarkerToSld( QDomDocument &doc, QDomElement
if ( borderColor.isValid() )
{
QDomElement strokeElem = doc.createElement( "se:Stroke" );
lineToSld( doc, strokeElem, Qt::SolidLine, borderColor, borderWidth );
lineToSld( doc, strokeElem, borderStyle, borderColor, borderWidth );
markElem.appendChild( strokeElem );
}

Expand All @@ -1940,7 +1942,7 @@ void QgsSymbolLayerV2Utils::wellKnownMarkerToSld( QDomDocument &doc, QDomElement
}

bool QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( QDomElement &element,
QString &name, QColor &color, QColor &borderColor,
QString &name, QColor &color, QColor &borderColor, Qt::PenStyle &borderStyle,
double &borderWidth, double &size )
{
QgsDebugMsg( "Entered." );
Expand Down Expand Up @@ -1970,8 +1972,7 @@ bool QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( QDomElement &element,

// <Stroke>
QDomElement strokeElem = markElem.firstChildElement( "Stroke" );
Qt::PenStyle p = Qt::SolidLine;
lineFromSld( strokeElem, p, borderColor, borderWidth );
lineFromSld( strokeElem, borderStyle, borderColor, borderWidth );
// ignore border style, solid expected

// <Size>
Expand Down
4 changes: 2 additions & 2 deletions src/core/symbology-ng/qgssymbollayerv2utils.h
Expand Up @@ -147,10 +147,10 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
QColor &color, double &size );

static void wellKnownMarkerToSld( QDomDocument &doc, QDomElement &element,
QString name, QColor color, QColor borderColor = QColor(),
QString name, QColor color, QColor borderColor = QColor(), Qt::PenStyle borderStyle = Qt::SolidLine,
double borderWidth = -1, double size = -1 );
static bool wellKnownMarkerFromSld( QDomElement &element,
QString &name, QColor &color, QColor &borderColor,
QString &name, QColor &color, QColor &borderColor, Qt::PenStyle &borderStyle,
double &borderWidth, double &size );

static void externalMarkerToSld( QDomDocument &doc, QDomElement &element,
Expand Down

0 comments on commit 4f6c9cd

Please sign in to comment.