diff --git a/src/core/symbology-ng/qgslinesymbollayerv2.cpp b/src/core/symbology-ng/qgslinesymbollayerv2.cpp index 76d424adebc4..ca6fbcb48838 100644 --- a/src/core/symbology-ng/qgslinesymbollayerv2.cpp +++ b/src/core/symbology-ng/qgslinesymbollayerv2.cpp @@ -920,7 +920,14 @@ QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2::create( const QgsStringMap& pr if ( props.contains( "width" ) ) width = props["width"].toDouble(); - return new QgsLineDecorationSymbolLayerV2( color, width ); + + QgsLineDecorationSymbolLayerV2* layer = new QgsLineDecorationSymbolLayerV2( color, width ); + if ( props.contains( "width_unit" ) ) + { + layer->setWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["width_unit"] ) ); + } + return layer; + } QString QgsLineDecorationSymbolLayerV2::layerType() const @@ -932,12 +939,14 @@ void QgsLineDecorationSymbolLayerV2::startRender( QgsSymbolV2RenderContext& cont { QColor penColor = mColor; penColor.setAlphaF( context.alpha() ); - mPen.setWidth( context.outputLineWidth( mWidth ) ); + + double width = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit ); + mPen.setWidth( context.outputLineWidth( width ) ); mPen.setColor( penColor ); QColor selColor = context.selectionColor(); if ( ! selectionIsOpaque ) selColor.setAlphaF( context.alpha() ); - mSelPen.setWidth( context.outputLineWidth( mWidth ) ); + mSelPen.setWidth( context.outputLineWidth( width ) ); mSelPen.setColor( selColor ); } @@ -973,7 +982,7 @@ void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, Qg } double angle = atan2( p2.y() - p1.y(), p2.x() - p1.x() ); - double size = context.outputLineWidth( mWidth * 8 ); + double size = ( mWidth * 8 ) * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit ); double angle1 = angle + M_PI / 6; double angle2 = angle - M_PI / 6; @@ -990,12 +999,15 @@ QgsStringMap QgsLineDecorationSymbolLayerV2::properties() const QgsStringMap map; map["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor ); map["width"] = QString::number( mWidth ); + map["width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mWidthUnit ); return map; } QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2::clone() const { - return new QgsLineDecorationSymbolLayerV2( mColor, mWidth ); + QgsLineDecorationSymbolLayerV2* layer = new QgsLineDecorationSymbolLayerV2( mColor, mWidth ); + layer->setWidthUnit( mWidthUnit ); + return layer; } void QgsLineDecorationSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const @@ -1028,3 +1040,13 @@ void QgsLineDecorationSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &elem // use to draw the decoration at end of the line symbolizerElem.appendChild( QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "placement", "lastPoint" ) ); } + +void QgsLineDecorationSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit ) +{ + mWidthUnit = unit; +} + +QgsSymbolV2::OutputUnit QgsLineDecorationSymbolLayerV2::outputUnit() const +{ + return mWidthUnit; +} diff --git a/src/core/symbology-ng/qgslinesymbollayerv2.h b/src/core/symbology-ng/qgslinesymbollayerv2.h index e14ba48a293a..706c093d1267 100644 --- a/src/core/symbology-ng/qgslinesymbollayerv2.h +++ b/src/core/symbology-ng/qgslinesymbollayerv2.h @@ -226,6 +226,9 @@ class CORE_EXPORT QgsLineDecorationSymbolLayerV2 : public QgsLineSymbolLayerV2 void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const; + void setOutputUnit( QgsSymbolV2::OutputUnit unit ); + QgsSymbolV2::OutputUnit outputUnit() const; + protected: QPen mPen; QPen mSelPen; diff --git a/src/gui/symbology-ng/qgssymbollayerv2widget.cpp b/src/gui/symbology-ng/qgssymbollayerv2widget.cpp index a7a8edc6fa6f..f6c9abb450e2 100644 --- a/src/gui/symbology-ng/qgssymbollayerv2widget.cpp +++ b/src/gui/symbology-ng/qgssymbollayerv2widget.cpp @@ -936,6 +936,10 @@ void QgsLineDecorationSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* lay // set values btnChangeColor->setColor( mLayer->color() ); spinWidth->setValue( mLayer->width() ); + + mWidthUnitComboBox->blockSignals( true ); + mWidthUnitComboBox->setCurrentIndex( mLayer->widthUnit() ); + mWidthUnitComboBox->blockSignals( false ); } QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2Widget::symbolLayer() @@ -966,6 +970,14 @@ void QgsLineDecorationSymbolLayerV2Widget::penWidthChanged() emit changed(); } +void QgsLineDecorationSymbolLayerV2Widget::on_mWidthUnitComboBox_currentIndexChanged( int index ) +{ + if ( mLayer ) + { + mLayer->setWidthUnit(( QgsSymbolV2::OutputUnit ) index ); + } +} + ///////////// #include diff --git a/src/gui/symbology-ng/qgssymbollayerv2widget.h b/src/gui/symbology-ng/qgssymbollayerv2widget.h index 390977c5199c..d9e9ba2510e0 100644 --- a/src/gui/symbology-ng/qgssymbollayerv2widget.h +++ b/src/gui/symbology-ng/qgssymbollayerv2widget.h @@ -240,6 +240,7 @@ class GUI_EXPORT QgsLineDecorationSymbolLayerV2Widget : public QgsSymbolLayerV2W public slots: void colorChanged(); void penWidthChanged(); + void on_mWidthUnitComboBox_currentIndexChanged( int index ); protected: QgsLineDecorationSymbolLayerV2* mLayer; diff --git a/src/ui/symbollayer/widget_linedecoration.ui b/src/ui/symbollayer/widget_linedecoration.ui index 835c46b41e44..317b8f240ecf 100644 --- a/src/ui/symbollayer/widget_linedecoration.ui +++ b/src/ui/symbollayer/widget_linedecoration.ui @@ -19,6 +19,13 @@ + + + + Color + + + @@ -32,6 +39,13 @@ + + + + Pen width + + + @@ -48,17 +62,24 @@ - - - - Pen width - + + + + + Millimeter + + + + + Map unit + + - - + + - Color + Width unit