Skip to content

Commit c771505

Browse files
committedMar 11, 2013
Output units for line decoration symbol layer
1 parent 460a471 commit c771505

File tree

5 files changed

+72
-13
lines changed

5 files changed

+72
-13
lines changed
 

‎src/core/symbology-ng/qgslinesymbollayerv2.cpp

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,14 @@ QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2::create( const QgsStringMap& pr
920920
if ( props.contains( "width" ) )
921921
width = props["width"].toDouble();
922922

923-
return new QgsLineDecorationSymbolLayerV2( color, width );
923+
924+
QgsLineDecorationSymbolLayerV2* layer = new QgsLineDecorationSymbolLayerV2( color, width );
925+
if ( props.contains( "width_unit" ) )
926+
{
927+
layer->setWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["width_unit"] ) );
928+
}
929+
return layer;
930+
924931
}
925932

926933
QString QgsLineDecorationSymbolLayerV2::layerType() const
@@ -932,12 +939,14 @@ void QgsLineDecorationSymbolLayerV2::startRender( QgsSymbolV2RenderContext& cont
932939
{
933940
QColor penColor = mColor;
934941
penColor.setAlphaF( context.alpha() );
935-
mPen.setWidth( context.outputLineWidth( mWidth ) );
942+
943+
double width = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
944+
mPen.setWidth( context.outputLineWidth( width ) );
936945
mPen.setColor( penColor );
937946
QColor selColor = context.selectionColor();
938947
if ( ! selectionIsOpaque )
939948
selColor.setAlphaF( context.alpha() );
940-
mSelPen.setWidth( context.outputLineWidth( mWidth ) );
949+
mSelPen.setWidth( context.outputLineWidth( width ) );
941950
mSelPen.setColor( selColor );
942951
}
943952

@@ -973,7 +982,7 @@ void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, Qg
973982
}
974983

975984
double angle = atan2( p2.y() - p1.y(), p2.x() - p1.x() );
976-
double size = context.outputLineWidth( mWidth * 8 );
985+
double size = ( mWidth * 8 ) * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
977986
double angle1 = angle + M_PI / 6;
978987
double angle2 = angle - M_PI / 6;
979988

@@ -990,12 +999,15 @@ QgsStringMap QgsLineDecorationSymbolLayerV2::properties() const
990999
QgsStringMap map;
9911000
map["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
9921001
map["width"] = QString::number( mWidth );
1002+
map["width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mWidthUnit );
9931003
return map;
9941004
}
9951005

9961006
QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2::clone() const
9971007
{
998-
return new QgsLineDecorationSymbolLayerV2( mColor, mWidth );
1008+
QgsLineDecorationSymbolLayerV2* layer = new QgsLineDecorationSymbolLayerV2( mColor, mWidth );
1009+
layer->setWidthUnit( mWidthUnit );
1010+
return layer;
9991011
}
10001012

10011013
void QgsLineDecorationSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
@@ -1028,3 +1040,13 @@ void QgsLineDecorationSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &elem
10281040
// use <VendorOption> to draw the decoration at end of the line
10291041
symbolizerElem.appendChild( QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "placement", "lastPoint" ) );
10301042
}
1043+
1044+
void QgsLineDecorationSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
1045+
{
1046+
mWidthUnit = unit;
1047+
}
1048+
1049+
QgsSymbolV2::OutputUnit QgsLineDecorationSymbolLayerV2::outputUnit() const
1050+
{
1051+
return mWidthUnit;
1052+
}

‎src/core/symbology-ng/qgslinesymbollayerv2.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ class CORE_EXPORT QgsLineDecorationSymbolLayerV2 : public QgsLineSymbolLayerV2
226226

227227
void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;
228228

229+
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
230+
QgsSymbolV2::OutputUnit outputUnit() const;
231+
229232
protected:
230233
QPen mPen;
231234
QPen mSelPen;

‎src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,10 @@ void QgsLineDecorationSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* lay
936936
// set values
937937
btnChangeColor->setColor( mLayer->color() );
938938
spinWidth->setValue( mLayer->width() );
939+
940+
mWidthUnitComboBox->blockSignals( true );
941+
mWidthUnitComboBox->setCurrentIndex( mLayer->widthUnit() );
942+
mWidthUnitComboBox->blockSignals( false );
939943
}
940944

941945
QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2Widget::symbolLayer()
@@ -966,6 +970,14 @@ void QgsLineDecorationSymbolLayerV2Widget::penWidthChanged()
966970
emit changed();
967971
}
968972

973+
void QgsLineDecorationSymbolLayerV2Widget::on_mWidthUnitComboBox_currentIndexChanged( int index )
974+
{
975+
if ( mLayer )
976+
{
977+
mLayer->setWidthUnit(( QgsSymbolV2::OutputUnit ) index );
978+
}
979+
}
980+
969981
/////////////
970982

971983
#include <QFileDialog>

‎src/gui/symbology-ng/qgssymbollayerv2widget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class GUI_EXPORT QgsLineDecorationSymbolLayerV2Widget : public QgsSymbolLayerV2W
240240
public slots:
241241
void colorChanged();
242242
void penWidthChanged();
243+
void on_mWidthUnitComboBox_currentIndexChanged( int index );
243244

244245
protected:
245246
QgsLineDecorationSymbolLayerV2* mLayer;

‎src/ui/symbollayer/widget_linedecoration.ui

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@
1919
</property>
2020
<item>
2121
<layout class="QGridLayout" name="gridLayout">
22+
<item row="0" column="0">
23+
<widget class="QLabel" name="label">
24+
<property name="text">
25+
<string>Color</string>
26+
</property>
27+
</widget>
28+
</item>
2229
<item row="0" column="1">
2330
<widget class="QgsColorButtonV2" name="btnChangeColor">
2431
<property name="sizePolicy">
@@ -32,6 +39,13 @@
3239
</property>
3340
</widget>
3441
</item>
42+
<item row="1" column="0">
43+
<widget class="QLabel" name="label_2">
44+
<property name="text">
45+
<string>Pen width</string>
46+
</property>
47+
</widget>
48+
</item>
3549
<item row="1" column="1">
3650
<widget class="QDoubleSpinBox" name="spinWidth">
3751
<property name="alignment">
@@ -48,17 +62,24 @@
4862
</property>
4963
</widget>
5064
</item>
51-
<item row="1" column="0">
52-
<widget class="QLabel" name="label_2">
53-
<property name="text">
54-
<string>Pen width</string>
55-
</property>
65+
<item row="2" column="1">
66+
<widget class="QComboBox" name="mWidthUnitComboBox">
67+
<item>
68+
<property name="text">
69+
<string>Millimeter</string>
70+
</property>
71+
</item>
72+
<item>
73+
<property name="text">
74+
<string>Map unit</string>
75+
</property>
76+
</item>
5677
</widget>
5778
</item>
58-
<item row="0" column="0">
59-
<widget class="QLabel" name="label">
79+
<item row="2" column="0">
80+
<widget class="QLabel" name="mWidthUnitLabel">
6081
<property name="text">
61-
<string>Color</string>
82+
<string>Width unit</string>
6283
</property>
6384
</widget>
6485
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.