Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add custom dash dot pattern to symbol layer utils function
  • Loading branch information
mhugent committed Dec 25, 2012
1 parent 5327da9 commit 22731aa
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -182,7 +182,7 @@ QString QgsSimpleFillSymbolLayerV2::ogrFeatureStyle( double widthScaleFactor ) c
symbolStyle.append( QgsSymbolLayerV2Utils::ogrFeatureStyleBrush( mColor ) );
symbolStyle.append( ";" );
//pen
symbolStyle.append( QgsSymbolLayerV2Utils::ogrFeatureStylePen( mBorderWidth * widthScaleFactor, mBorderColor ) );
symbolStyle.append( QgsSymbolLayerV2Utils::ogrFeatureStylePen( mBorderWidth, widthScaleFactor, mBorderColor ) );
return symbolStyle;
}

Expand Down
34 changes: 6 additions & 28 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -197,36 +197,14 @@ void QgsSimpleLineSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &element,

QString QgsSimpleLineSymbolLayerV2::ogrFeatureStyle( double widthScaleFactor ) const
{
QString symbolStyle;

//pen
symbolStyle.append( "PEN(" );
symbolStyle.append( "c:" );
symbolStyle.append( mPen.color().name() );
symbolStyle.append( ",w:" );
//dxf driver writes ground units as mm? Should probably be changed in ogr
symbolStyle.append( QString::number( mWidth * widthScaleFactor ) );
symbolStyle.append( "mm" );

//dash dot vector
if ( mUseCustomDashPattern && mCustomDashVector.size() > 0 )
{
symbolStyle.append( ",p:\"" );
QVector<qreal>::const_iterator pIt = mCustomDashVector.constBegin();
for ( ; pIt != mCustomDashVector.constEnd(); ++pIt )
if( mUseCustomDashPattern )
{
if ( pIt != mCustomDashVector.constBegin() )
{
symbolStyle.append( " " );
}
symbolStyle.append( QString::number( *pIt * widthScaleFactor ) );
symbolStyle.append( "mm" );
return QgsSymbolLayerV2Utils::ogrFeatureStylePen( mWidth, widthScaleFactor, mPen.color(), &mCustomDashVector );
}
else
{
return QgsSymbolLayerV2Utils::ogrFeatureStylePen( mWidth, widthScaleFactor, mPen.color() );
}
symbolStyle.append( "\"" );
}
symbolStyle.append( ")" );

return symbolStyle;
}

QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::createFromSld( QDomElement &element )
Expand Down
23 changes: 21 additions & 2 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -2095,16 +2095,35 @@ void QgsSymbolLayerV2Utils::labelTextToSld( QDomDocument &doc, QDomElement &elem
}
}

QString QgsSymbolLayerV2Utils::ogrFeatureStylePen( double width, const QColor& c )
QString QgsSymbolLayerV2Utils::ogrFeatureStylePen( double width, double widthScaleFactor, const QColor& c, const QVector<qreal>* dashPattern )
{
QString penStyle;
penStyle.append( "PEN(" );
penStyle.append( "c:" );
penStyle.append( c.name() );
penStyle.append( ",w:" );
//dxf driver writes ground units as mm? Should probably be changed in ogr
penStyle.append( QString::number( width ) );
penStyle.append( QString::number( width * widthScaleFactor ) );
penStyle.append( "mm" );

//dash dot vector
if ( dashPattern && dashPattern->size() > 0 )
{
penStyle.append( ",p:\"" );
QVector<qreal>::const_iterator pIt = dashPattern->constBegin();
for ( ; pIt != dashPattern->constEnd(); ++pIt )
{
if ( pIt != dashPattern->constBegin() )
{
penStyle.append( " " );
}
penStyle.append( QString::number( *pIt * widthScaleFactor ) );
penStyle.append( "mm" );
}
penStyle.append( "\"" );
}

penStyle.append( ")" );
return penStyle;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbollayerv2utils.h
Expand Up @@ -167,7 +167,7 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
/**Create ogr feature style string for pen
@param width linewidth in mm
@param c line color*/
static QString ogrFeatureStylePen( double width, const QColor& c );
static QString ogrFeatureStylePen( double width, double widthScaleFactor, const QColor& c, const QVector<qreal>* dashPattern = 0 );
/**Create ogr feature syle string for brush
@param fillColr fill color*/
static QString ogrFeatureStyleBrush( const QColor& fillColr );
Expand Down

0 comments on commit 22731aa

Please sign in to comment.