Skip to content

Commit 22731aa

Browse files
committed
Add custom dash dot pattern to symbol layer utils function
1 parent 5327da9 commit 22731aa

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ QString QgsSimpleFillSymbolLayerV2::ogrFeatureStyle( double widthScaleFactor ) c
182182
symbolStyle.append( QgsSymbolLayerV2Utils::ogrFeatureStyleBrush( mColor ) );
183183
symbolStyle.append( ";" );
184184
//pen
185-
symbolStyle.append( QgsSymbolLayerV2Utils::ogrFeatureStylePen( mBorderWidth * widthScaleFactor, mBorderColor ) );
185+
symbolStyle.append( QgsSymbolLayerV2Utils::ogrFeatureStylePen( mBorderWidth, widthScaleFactor, mBorderColor ) );
186186
return symbolStyle;
187187
}
188188

src/core/symbology-ng/qgslinesymbollayerv2.cpp

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -197,36 +197,14 @@ void QgsSimpleLineSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &element,
197197

198198
QString QgsSimpleLineSymbolLayerV2::ogrFeatureStyle( double widthScaleFactor ) const
199199
{
200-
QString symbolStyle;
201-
202-
//pen
203-
symbolStyle.append( "PEN(" );
204-
symbolStyle.append( "c:" );
205-
symbolStyle.append( mPen.color().name() );
206-
symbolStyle.append( ",w:" );
207-
//dxf driver writes ground units as mm? Should probably be changed in ogr
208-
symbolStyle.append( QString::number( mWidth * widthScaleFactor ) );
209-
symbolStyle.append( "mm" );
210-
211-
//dash dot vector
212-
if ( mUseCustomDashPattern && mCustomDashVector.size() > 0 )
213-
{
214-
symbolStyle.append( ",p:\"" );
215-
QVector<qreal>::const_iterator pIt = mCustomDashVector.constBegin();
216-
for ( ; pIt != mCustomDashVector.constEnd(); ++pIt )
200+
if( mUseCustomDashPattern )
217201
{
218-
if ( pIt != mCustomDashVector.constBegin() )
219-
{
220-
symbolStyle.append( " " );
221-
}
222-
symbolStyle.append( QString::number( *pIt * widthScaleFactor ) );
223-
symbolStyle.append( "mm" );
202+
return QgsSymbolLayerV2Utils::ogrFeatureStylePen( mWidth, widthScaleFactor, mPen.color(), &mCustomDashVector );
203+
}
204+
else
205+
{
206+
return QgsSymbolLayerV2Utils::ogrFeatureStylePen( mWidth, widthScaleFactor, mPen.color() );
224207
}
225-
symbolStyle.append( "\"" );
226-
}
227-
symbolStyle.append( ")" );
228-
229-
return symbolStyle;
230208
}
231209

232210
QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::createFromSld( QDomElement &element )

src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,16 +2095,35 @@ void QgsSymbolLayerV2Utils::labelTextToSld( QDomDocument &doc, QDomElement &elem
20952095
}
20962096
}
20972097

2098-
QString QgsSymbolLayerV2Utils::ogrFeatureStylePen( double width, const QColor& c )
2098+
QString QgsSymbolLayerV2Utils::ogrFeatureStylePen( double width, double widthScaleFactor, const QColor& c, const QVector<qreal>* dashPattern )
20992099
{
21002100
QString penStyle;
21012101
penStyle.append( "PEN(" );
21022102
penStyle.append( "c:" );
21032103
penStyle.append( c.name() );
21042104
penStyle.append( ",w:" );
21052105
//dxf driver writes ground units as mm? Should probably be changed in ogr
2106-
penStyle.append( QString::number( width ) );
2106+
penStyle.append( QString::number( width * widthScaleFactor ) );
21072107
penStyle.append( "mm" );
2108+
2109+
//dash dot vector
2110+
if ( dashPattern && dashPattern->size() > 0 )
2111+
{
2112+
penStyle.append( ",p:\"" );
2113+
QVector<qreal>::const_iterator pIt = dashPattern->constBegin();
2114+
for ( ; pIt != dashPattern->constEnd(); ++pIt )
2115+
{
2116+
if ( pIt != dashPattern->constBegin() )
2117+
{
2118+
penStyle.append( " " );
2119+
}
2120+
penStyle.append( QString::number( *pIt * widthScaleFactor ) );
2121+
penStyle.append( "mm" );
2122+
}
2123+
penStyle.append( "\"" );
2124+
}
2125+
2126+
penStyle.append( ")" );
21082127
return penStyle;
21092128
}
21102129

src/core/symbology-ng/qgssymbollayerv2utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
167167
/**Create ogr feature style string for pen
168168
@param width linewidth in mm
169169
@param c line color*/
170-
static QString ogrFeatureStylePen( double width, const QColor& c );
170+
static QString ogrFeatureStylePen( double width, double widthScaleFactor, const QColor& c, const QVector<qreal>* dashPattern = 0 );
171171
/**Create ogr feature syle string for brush
172172
@param fillColr fill color*/
173173
static QString ogrFeatureStyleBrush( const QColor& fillColr );

0 commit comments

Comments
 (0)