Skip to content

Commit 9735c13

Browse files
committed
[FEATURE] add outline settings to font markers
1 parent 90613ca commit 9735c13

File tree

12 files changed

+400
-44
lines changed

12 files changed

+400
-44
lines changed

python/core/symbology-ng/qgsmarkersymbollayerv2.sip

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,41 @@ class QgsFontMarkerSymbolLayerV2 : QgsMarkerSymbolLayerV2
221221
QChar character() const;
222222
void setCharacter( QChar ch );
223223

224+
/** Get outline color.
225+
* @note added in 2.16 */
226+
QColor outlineColor() const;
227+
/** Set outline color.
228+
* @note added in 2.16 */
229+
void setOutlineColor( const QColor& color );
230+
231+
/** Get outline width.
232+
* @note added in 2.16 */
233+
double outlineWidth() const;
234+
/** Set outline width.
235+
* @note added in 2.16 */
236+
void setOutlineWidth( double width );
237+
238+
/** Get outline width unit.
239+
* @note added in 2.16 */
240+
QgsSymbolV2::OutputUnit outlineWidthUnit() const;
241+
/** Set outline width unit.
242+
* @note added in 2.16 */
243+
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit );
244+
245+
/** Get outline width map unit scale.
246+
* @note added in 2.16 */
247+
const QgsMapUnitScale& outlineWidthMapUnitScale() const;
248+
/** Set outline width map unit scale.
249+
* @note added in 2.16 */
250+
void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale );
251+
252+
/** Get outline join style.
253+
* @note added in 2.16 */
254+
Qt::PenJoinStyle penJoinStyle() const;
255+
/** Set outline join style.
256+
* @note added in 2.16 */
257+
void setPenJoinStyle( Qt::PenJoinStyle style );
258+
224259
QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context );
225260

226261
};

python/gui/symbology-ng/qgssymbollayerv2widget.sip

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,18 @@ class QgsFontMarkerSymbolLayerV2Widget : QgsSymbolLayerV2Widget
408408
public slots:
409409
void setFontFamily( const QFont& font );
410410
void setColor( const QColor& color );
411+
412+
/** Set outline color.
413+
* @note added in 2.16 */
414+
void setColorBorder( const QColor& color );
411415
void setSize( double size );
412416
void setAngle( double angle );
413417
void setCharacter( QChar chr );
414418
void setOffset();
415419
void on_mSizeUnitWidget_changed();
416420
void on_mOffsetUnitWidget_changed();
421+
void on_mBorderWidthUnitWidget_changed();
422+
void on_mBorderWidthSpinBox_valueChanged( double d );
417423
void on_mHorizontalAnchorComboBox_currentIndexChanged( int index );
418424
void on_mVerticalAnchorComboBox_currentIndexChanged( int index );
419425
};

src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1983,6 +1983,10 @@ QgsFontMarkerSymbolLayerV2::QgsFontMarkerSymbolLayerV2( const QString& fontFamil
19831983
mSizeUnit = QgsSymbolV2::MM;
19841984
mOffset = QPointF( 0, 0 );
19851985
mOffsetUnit = QgsSymbolV2::MM;
1986+
mOutlineColor = DEFAULT_FONTMARKER_BORDERCOLOR;
1987+
mOutlineWidth = 0.0;
1988+
mOutlineWidthUnit = QgsSymbolV2::MM;
1989+
mPenJoinStyle = DEFAULT_FONTMARKER_JOINSTYLE;
19861990
}
19871991

19881992
QgsFontMarkerSymbolLayerV2::~QgsFontMarkerSymbolLayerV2()
@@ -2010,6 +2014,11 @@ QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::create( const QgsStringMap& props
20102014
angle = props["angle"].toDouble();
20112015

20122016
QgsFontMarkerSymbolLayerV2* m = new QgsFontMarkerSymbolLayerV2( fontFamily, chr, pointSize, color, angle );
2017+
2018+
if ( props.contains( "outline_color" ) )
2019+
m->setOutlineColor( QgsSymbolLayerV2Utils::decodeColor( props["outline_color"] ) );
2020+
if ( props.contains( "outline_width" ) )
2021+
m->setOutlineWidth( props["outline_width"].toDouble() );
20132022
if ( props.contains( "offset" ) )
20142023
m->setOffset( QgsSymbolLayerV2Utils::decodePoint( props["offset"] ) );
20152024
if ( props.contains( "offset_unit" ) )
@@ -2020,14 +2029,16 @@ QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::create( const QgsStringMap& props
20202029
m->setSizeUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["size_unit"] ) );
20212030
if ( props.contains( "size_map_unit_scale" ) )
20222031
m->setSizeMapUnitScale( QgsSymbolLayerV2Utils::decodeMapUnitScale( props["size_map_unit_scale"] ) );
2032+
if ( props.contains( "outline_width_unit" ) )
2033+
m->setOutlineWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["outline_width_unit"] ) );
2034+
if ( props.contains( "outline_width_map_unit_scale" ) )
2035+
m->setOutlineWidthMapUnitScale( QgsSymbolLayerV2Utils::decodeMapUnitScale( props["outline_width_map_unit_scale"] ) );
2036+
if ( props.contains( "joinstyle" ) )
2037+
m->setPenJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( props["joinstyle"] ) );
20232038
if ( props.contains( "horizontal_anchor_point" ) )
2024-
{
20252039
m->setHorizontalAnchorPoint( QgsMarkerSymbolLayerV2::HorizontalAnchorPoint( props[ "horizontal_anchor_point" ].toInt() ) );
2026-
}
20272040
if ( props.contains( "vertical_anchor_point" ) )
2028-
{
20292041
m->setVerticalAnchorPoint( QgsMarkerSymbolLayerV2::VerticalAnchorPoint( props[ "vertical_anchor_point" ].toInt() ) );
2030-
}
20312042

20322043
m->restoreDataDefinedProperties( props );
20332044

@@ -2041,6 +2052,17 @@ QString QgsFontMarkerSymbolLayerV2::layerType() const
20412052

20422053
void QgsFontMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context )
20432054
{
2055+
QColor brushColor = mColor;
2056+
QColor penColor = mOutlineColor;
2057+
2058+
brushColor.setAlphaF( mColor.alphaF() * context.alpha() );
2059+
penColor.setAlphaF( mOutlineColor.alphaF() * context.alpha() );
2060+
2061+
mBrush = QBrush( brushColor );
2062+
mPen = QPen( penColor );
2063+
mPen.setJoinStyle( mPenJoinStyle );
2064+
mPen.setWidthF( QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mOutlineWidth, mOutlineWidthUnit, mOutlineWidthMapUnitScale ) );
2065+
20442066
mFont = QFont( mFontFamily );
20452067
mFont.setPixelSize( QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mSize, mSizeUnit, mSizeMapUnitScale ) );
20462068
delete mFontMetrics;
@@ -2152,20 +2174,63 @@ void QgsFontMarkerSymbolLayerV2::renderPoint( QPointF point, QgsSymbolV2RenderCo
21522174
if ( !p )
21532175
return;
21542176

2155-
QColor penColor = mColor;
2177+
QTransform transform;
2178+
21562179
bool ok;
2180+
QColor brushColor = mColor;
21572181
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR ) )
21582182
{
21592183
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mColor ) );
21602184
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR, context, QVariant(), &ok ).toString();
2185+
if ( ok )
2186+
brushColor = QgsSymbolLayerV2Utils::decodeColor( colorString );
2187+
}
2188+
brushColor = context.selected() ? context.renderContext().selectionColor() : brushColor;
2189+
brushColor.setAlphaF( brushColor.alphaF() * context.alpha() );
2190+
mBrush.setColor( brushColor );
2191+
2192+
QColor penColor = mOutlineColor;
2193+
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR_BORDER ) )
2194+
{
2195+
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodeColor( mOutlineColor ) );
2196+
QString colorString = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_COLOR_BORDER, context, QVariant(), &ok ).toString();
21612197
if ( ok )
21622198
penColor = QgsSymbolLayerV2Utils::decodeColor( colorString );
21632199
}
2164-
penColor = context.selected() ? context.renderContext().selectionColor() : penColor;
21652200
penColor.setAlphaF( penColor.alphaF() * context.alpha() );
21662201

2167-
p->setPen( penColor );
2168-
p->setFont( mFont );
2202+
double penWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), mOutlineWidth, mOutlineWidthUnit, mOutlineWidthMapUnitScale );
2203+
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH ) )
2204+
{
2205+
context.setOriginalValueVariable( mOutlineWidth );
2206+
double outlineWidth = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_OUTLINE_WIDTH, context, QVariant(), &ok ).toDouble();
2207+
if ( ok )
2208+
{
2209+
penWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), outlineWidth, mOutlineWidthUnit, mOutlineWidthMapUnitScale );
2210+
}
2211+
}
2212+
2213+
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_JOIN_STYLE ) )
2214+
{
2215+
context.setOriginalValueVariable( QgsSymbolLayerV2Utils::encodePenJoinStyle( mPenJoinStyle ) );
2216+
QString style = evaluateDataDefinedProperty( QgsSymbolLayerV2::EXPR_JOIN_STYLE, context, QVariant(), &ok ).toString();
2217+
if ( ok )
2218+
{
2219+
mPen.setJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( style ) );
2220+
}
2221+
}
2222+
2223+
p->setBrush( mBrush );
2224+
if ( !qgsDoubleNear( penWidth, 0.0 ) )
2225+
{
2226+
mPen.setColor( penColor );
2227+
mPen.setWidthF( penWidth );
2228+
p->setPen( mPen );
2229+
}
2230+
else
2231+
{
2232+
p->setPen( Qt::NoPen );
2233+
}
21692234
p->save();
21702235

21712236
QPointF chrOffset = mChrOffset;
@@ -2179,18 +2244,20 @@ void QgsFontMarkerSymbolLayerV2::renderPoint( QPointF point, QgsSymbolV2RenderCo
21792244
double angle = 0;
21802245
calculateOffsetAndRotation( context, sizeToRender, hasDataDefinedRotation, offset, angle );
21812246

2182-
p->translate( point + offset );
2247+
transform.translate( point.x() + offset.x(), point.y() + offset.y() );
2248+
2249+
if ( !qgsDoubleNear( angle, 0.0 ) )
2250+
transform.rotate( angle );
21832251

21842252
if ( !qgsDoubleNear( sizeToRender, mOrigSize ) )
21852253
{
21862254
double s = sizeToRender / mOrigSize;
2187-
p->scale( s, s );
2255+
transform.scale( s, s );
21882256
}
21892257

2190-
if ( !qgsDoubleNear( angle, 0 ) )
2191-
p->rotate( angle );
2192-
2193-
p->drawText( -chrOffset, charToRender );
2258+
QPainterPath path;
2259+
path.addText( -chrOffset.x(), -chrOffset.y(), mFont, charToRender );
2260+
p->drawPath( transform.map( path ) );
21942261
p->restore();
21952262
}
21962263

@@ -2203,6 +2270,10 @@ QgsStringMap QgsFontMarkerSymbolLayerV2::properties() const
22032270
props["size_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mSizeUnit );
22042271
props["size_map_unit_scale"] = QgsSymbolLayerV2Utils::encodeMapUnitScale( mSizeMapUnitScale );
22052272
props["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
2273+
props["outline_color"] = QgsSymbolLayerV2Utils::encodeColor( mOutlineColor );
2274+
props["outline_width"] = QString::number( mOutlineWidth );
2275+
props["outline_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOutlineWidthUnit );
2276+
props["outline_width_map_unit_scale"] = QgsSymbolLayerV2Utils::encodeMapUnitScale( mOutlineWidthMapUnitScale );
22062277
props["angle"] = QString::number( mAngle );
22072278
props["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
22082279
props["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
@@ -2219,6 +2290,11 @@ QgsStringMap QgsFontMarkerSymbolLayerV2::properties() const
22192290
QgsFontMarkerSymbolLayerV2* QgsFontMarkerSymbolLayerV2::clone() const
22202291
{
22212292
QgsFontMarkerSymbolLayerV2* m = new QgsFontMarkerSymbolLayerV2( mFontFamily, mChr, mSize, mColor, mAngle );
2293+
m->setOutlineColor( mOutlineColor );
2294+
m->setOutlineWidth( mOutlineWidth );
2295+
m->setOutlineWidthUnit( mOutlineWidthUnit );
2296+
m->setOutlineWidthMapUnitScale( mOutlineWidthMapUnitScale );
2297+
m->setPenJoinStyle( mPenJoinStyle );
22222298
m->setOffset( mOffset );
22232299
m->setOffsetUnit( mOffsetUnit );
22242300
m->setOffsetMapUnitScale( mOffsetMapUnitScale );

src/core/symbology-ng/qgsmarkersymbollayerv2.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
260260
#define DEFAULT_FONTMARKER_CHR QChar('A')
261261
#define DEFAULT_FONTMARKER_SIZE POINT2MM(12)
262262
#define DEFAULT_FONTMARKER_COLOR QColor(Qt::black)
263+
#define DEFAULT_FONTMARKER_BORDERCOLOR QColor(Qt::white)
264+
#define DEFAULT_FONTMARKER_JOINSTYLE Qt::MiterJoin
263265
#define DEFAULT_FONTMARKER_ANGLE 0
264266

265267
class CORE_EXPORT QgsFontMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
@@ -302,6 +304,41 @@ class CORE_EXPORT QgsFontMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
302304
QChar character() const { return mChr; }
303305
void setCharacter( QChar ch ) { mChr = ch; }
304306

307+
/** Get outline color.
308+
* @note added in 2.16 */
309+
QColor outlineColor() const override { return mOutlineColor; }
310+
/** Set outline color.
311+
* @note added in 2.16 */
312+
void setOutlineColor( const QColor& color ) override { mOutlineColor = color; }
313+
314+
/** Get outline width.
315+
* @note added in 2.16 */
316+
double outlineWidth() const { return mOutlineWidth; }
317+
/** Set outline width.
318+
* @note added in 2.16 */
319+
void setOutlineWidth( double width ) { mOutlineWidth = width; }
320+
321+
/** Get outline width unit.
322+
* @note added in 2.16 */
323+
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
324+
/** Set outline width unit.
325+
* @note added in 2.16 */
326+
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
327+
328+
/** Get outline width map unit scale.
329+
* @note added in 2.16 */
330+
const QgsMapUnitScale& outlineWidthMapUnitScale() const { return mOutlineWidthMapUnitScale; }
331+
/** Set outline width map unit scale.
332+
* @note added in 2.16 */
333+
void setOutlineWidthMapUnitScale( const QgsMapUnitScale& scale ) { mOutlineWidthMapUnitScale = scale; }
334+
335+
/** Get outline join style.
336+
* @note added in 2.16 */
337+
Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
338+
/** Set outline join style.
339+
* @note added in 2.16 */
340+
void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }
341+
305342
QRectF bounds( QPointF point, QgsSymbolV2RenderContext& context ) override;
306343

307344
protected:
@@ -317,6 +354,15 @@ class CORE_EXPORT QgsFontMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
317354

318355
private:
319356

357+
QColor mOutlineColor;
358+
double mOutlineWidth;
359+
QgsSymbolV2::OutputUnit mOutlineWidthUnit;
360+
QgsMapUnitScale mOutlineWidthMapUnitScale;
361+
Qt::PenJoinStyle mPenJoinStyle;
362+
363+
QPen mPen;
364+
QBrush mBrush;
365+
320366
QString characterToRender( QgsSymbolV2RenderContext& context, QPointF& charOffset, double& charWidth );
321367
void calculateOffsetAndRotation( QgsSymbolV2RenderContext& context, double scaledSize, bool& hasDataDefinedRotation, QPointF& offset, double& angle ) const;
322368
double calculateSize( QgsSymbolV2RenderContext& context );

0 commit comments

Comments
 (0)