Skip to content

Commit

Permalink
Expose outline join style as a parameter for simple fill symbol type
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Apr 3, 2014
1 parent d01acce commit 6836a7d
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 113 deletions.
9 changes: 7 additions & 2 deletions python/core/symbology-ng/qgsfillsymbollayerv2.sip
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ class QgsSimpleFillSymbolLayerV2 : QgsFillSymbolLayerV2
Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE,
QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR,
Qt::PenStyle borderStyle = DEFAULT_SIMPLEFILL_BORDERSTYLE,
double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH );

double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH,
Qt::PenJoinStyle penJoinStyle = DEFAULT_SIMPLEFILL_JOINSTYLE
);

// static stuff

static QgsSymbolLayerV2* create( const QgsStringMap& properties = QgsStringMap() ) /Factory/;
Expand Down Expand Up @@ -59,6 +61,9 @@ class QgsSimpleFillSymbolLayerV2 : QgsFillSymbolLayerV2

double borderWidth() const;
void setBorderWidth( double borderWidth );

Qt::PenJoinStyle penJoinStyle() const;
void setPenJoinStyle( Qt::PenJoinStyle style );

void setOffset( QPointF offset );
QPointF offset();
Expand Down
23 changes: 17 additions & 6 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@
#include <QDomDocument>
#include <QDomElement>

QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2( QColor color, Qt::BrushStyle style, QColor borderColor, Qt::PenStyle borderStyle, double borderWidth )
: mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth ), mBorderWidthUnit( QgsSymbolV2::MM ),
QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2( QColor color, Qt::BrushStyle style, QColor borderColor, Qt::PenStyle borderStyle, double borderWidth,
Qt::PenJoinStyle penJoinStyle ) :
mBrushStyle( style ),
mBorderColor( borderColor ),
mBorderStyle( borderStyle ),
mBorderWidth( borderWidth ),
mBorderWidthUnit( QgsSymbolV2::MM ),
mPenJoinStyle( penJoinStyle ),
mOffsetUnit( QgsSymbolV2::MM )
{
mColor = color;
Expand Down Expand Up @@ -84,6 +90,7 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props
QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR;
Qt::PenStyle borderStyle = DEFAULT_SIMPLEFILL_BORDERSTYLE;
double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH;
Qt::PenJoinStyle penJoinStyle = DEFAULT_SIMPLEFILL_JOINSTYLE;
QPointF offset;

if ( props.contains( "color" ) )
Expand All @@ -98,8 +105,10 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props
borderWidth = props["width_border"].toDouble();
if ( props.contains( "offset" ) )
offset = QgsSymbolLayerV2Utils::decodePoint( props["offset"] );
if ( props.contains( "joinstyle" ) )
penJoinStyle = QgsSymbolLayerV2Utils::decodePenJoinStyle( props["joinstyle"] );

QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( color, style, borderColor, borderStyle, borderWidth );
QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( color, style, borderColor, borderStyle, borderWidth, penJoinStyle );
sl->setOffset( offset );
if ( props.contains( "border_width_unit" ) )
sl->setBorderWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["border_width_unit"] ) );
Expand Down Expand Up @@ -155,6 +164,7 @@ void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context
mSelPen = QPen( selPenColor );
mPen.setStyle( mBorderStyle );
mPen.setWidthF( mBorderWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mBorderWidthUnit ) );
mPen.setJoinStyle( mPenJoinStyle );
prepareExpressions( context.fields(), context.renderContext().rendererScale() );
}

Expand Down Expand Up @@ -201,6 +211,7 @@ QgsStringMap QgsSimpleFillSymbolLayerV2::properties() const
map["style_border"] = QgsSymbolLayerV2Utils::encodePenStyle( mBorderStyle );
map["width_border"] = QString::number( mBorderWidth );
map["border_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mBorderWidthUnit );
map["joinstyle"] = QgsSymbolLayerV2Utils::encodePenJoinStyle( mPenJoinStyle );
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
saveDataDefinedProperties( map );
Expand All @@ -209,7 +220,7 @@ QgsStringMap QgsSimpleFillSymbolLayerV2::properties() const

QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::clone() const
{
QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( mColor, mBrushStyle, mBorderColor, mBorderStyle, mBorderWidth );
QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( mColor, mBrushStyle, mBorderColor, mBorderStyle, mBorderWidth, mPenJoinStyle );
sl->setOffset( mOffset );
sl->setOffsetUnit( mOffsetUnit );
sl->setBorderWidthUnit( mBorderWidthUnit );
Expand Down Expand Up @@ -243,7 +254,7 @@ void QgsSimpleFillSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &element,
// <Stroke>
QDomElement strokeElem = doc.createElement( "se:Stroke" );
symbolizerElem.appendChild( strokeElem );
QgsSymbolLayerV2Utils::lineToSld( doc, strokeElem, mBorderStyle, mBorderColor, mBorderWidth );
QgsSymbolLayerV2Utils::lineToSld( doc, strokeElem, mBorderStyle, mBorderColor, mBorderWidth, &mPenJoinStyle );
}

// <se:Displacement>
Expand All @@ -257,7 +268,7 @@ QString QgsSimpleFillSymbolLayerV2::ogrFeatureStyle( double mmScaleFactor, doubl
symbolStyle.append( QgsSymbolLayerV2Utils::ogrFeatureStyleBrush( mColor ) );
symbolStyle.append( ";" );
//pen
symbolStyle.append( QgsSymbolLayerV2Utils::ogrFeatureStylePen( mBorderWidth, mmScaleFactor, mapUnitScaleFactor, mBorderColor ) );
symbolStyle.append( QgsSymbolLayerV2Utils::ogrFeatureStylePen( mBorderWidth, mmScaleFactor, mapUnitScaleFactor, mBorderColor, mPenJoinStyle ) );
return symbolStyle;
}

Expand Down
9 changes: 8 additions & 1 deletion src/core/symbology-ng/qgsfillsymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define DEFAULT_SIMPLEFILL_BORDERCOLOR QColor(0,0,0)
#define DEFAULT_SIMPLEFILL_BORDERSTYLE Qt::SolidLine
#define DEFAULT_SIMPLEFILL_BORDERWIDTH DEFAULT_LINE_WIDTH
#define DEFAULT_SIMPLEFILL_JOINSTYLE Qt::BevelJoin

#define INF 1E20

Expand All @@ -36,7 +37,9 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE,
QColor borderColor = DEFAULT_SIMPLEFILL_BORDERCOLOR,
Qt::PenStyle borderStyle = DEFAULT_SIMPLEFILL_BORDERSTYLE,
double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH );
double borderWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH,
Qt::PenJoinStyle penJoinStyle = DEFAULT_SIMPLEFILL_JOINSTYLE
);

// static stuff

Expand Down Expand Up @@ -87,6 +90,9 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
double borderWidth() const { return mBorderWidth; }
void setBorderWidth( double borderWidth ) { mBorderWidth = borderWidth; }

Qt::PenJoinStyle penJoinStyle() const { return mPenJoinStyle; }
void setPenJoinStyle( Qt::PenJoinStyle style ) { mPenJoinStyle = style; }

void setOffset( QPointF offset ) { mOffset = offset; }
QPointF offset() { return mOffset; }

Expand All @@ -113,6 +119,7 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
Qt::PenStyle mBorderStyle;
double mBorderWidth;
QgsSymbolV2::OutputUnit mBorderWidthUnit;
Qt::PenJoinStyle mPenJoinStyle;
QPen mPen;
QPen mSelPen;

Expand Down
5 changes: 5 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ QgsSimpleFillSymbolLayerV2Widget::QgsSimpleFillSymbolLayerV2Widget( const QgsVec
connect( btnChangeBorderColor, SIGNAL( colorChanged( const QColor& ) ), this, SLOT( setBorderColor( const QColor& ) ) );
connect( spinBorderWidth, SIGNAL( valueChanged( double ) ), this, SLOT( borderWidthChanged() ) );
connect( cboBorderStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( borderStyleChanged() ) );
connect( cboJoinStyle, SIGNAL( currentIndexChanged( int ) ), this, SLOT( borderStyleChanged() ) );
connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( offsetChanged() ) );
}
Expand All @@ -558,6 +559,9 @@ void QgsSimpleFillSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
btnChangeBorderColor->setColorDialogOptions( QColorDialog::ShowAlphaChannel );
cboBorderStyle->setPenStyle( mLayer->borderStyle() );
spinBorderWidth->setValue( mLayer->borderWidth() );
cboJoinStyle->blockSignals( true );
cboJoinStyle->setPenJoinStyle( mLayer->penJoinStyle() );
cboJoinStyle->blockSignals( false );
spinOffsetX->blockSignals( true );
spinOffsetX->setValue( mLayer->offset().x() );
spinOffsetX->blockSignals( false );
Expand Down Expand Up @@ -605,6 +609,7 @@ void QgsSimpleFillSymbolLayerV2Widget::borderWidthChanged()
void QgsSimpleFillSymbolLayerV2Widget::borderStyleChanged()
{
mLayer->setBorderStyle( cboBorderStyle->penStyle() );
mLayer->setPenJoinStyle( cboJoinStyle->penJoinStyle() );
emit changed();
}

Expand Down
Loading

0 comments on commit 6836a7d

Please sign in to comment.