Skip to content

Commit 4c49cf3

Browse files
committedMar 13, 2013
Output units for simple fill symbol layer
1 parent ac3dbea commit 4c49cf3

File tree

6 files changed

+155
-44
lines changed

6 files changed

+155
-44
lines changed
 

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

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,28 @@
2828
#include <QDomElement>
2929

3030
QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2( QColor color, Qt::BrushStyle style, QColor borderColor, Qt::PenStyle borderStyle, double borderWidth )
31-
: mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth )
31+
: mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth ), mBorderWidthUnit( QgsSymbolV2::MM ),
32+
mOffsetUnit( QgsSymbolV2::MM )
3233
{
3334
mColor = color;
3435
}
3536

37+
void QgsSimpleFillSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
38+
{
39+
mBorderWidthUnit = unit;
40+
mOffsetUnit = unit;
41+
}
42+
43+
QgsSymbolV2::OutputUnit QgsSimpleFillSymbolLayerV2::outputUnit() const
44+
{
45+
QgsSymbolV2::OutputUnit unit = mBorderWidthUnit;
46+
if ( mOffsetUnit != unit )
47+
{
48+
return QgsSymbolV2::Mixed;
49+
}
50+
return unit;
51+
}
52+
3653

3754
QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props )
3855
{
@@ -58,6 +75,10 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props
5875

5976
QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( color, style, borderColor, borderStyle, borderWidth );
6077
sl->setOffset( offset );
78+
if ( props.contains( "border_width_unit" ) )
79+
sl->setBorderWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["border_width_unit"] ) );
80+
if ( props.contains( "offset_unit" ) )
81+
sl->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit"] ) );
6182
return sl;
6283
}
6384

@@ -94,7 +115,7 @@ void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context
94115
mPen = QPen( borderColor );
95116
mSelPen = QPen( selPenColor );
96117
mPen.setStyle( mBorderStyle );
97-
mPen.setWidthF( context.outputLineWidth( mBorderWidth ) );
118+
mPen.setWidthF( mBorderWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mBorderWidthUnit ) );
98119
}
99120

100121
void QgsSimpleFillSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
@@ -114,13 +135,20 @@ void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<Q
114135
p->setPen( mPen );
115136
p->setPen( context.selected() ? mSelPen : mPen );
116137

138+
QPointF offset;
117139
if ( !mOffset.isNull() )
118-
p->translate( mOffset );
140+
{
141+
offset.setX( mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit ) );
142+
offset.setY( mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit ) );
143+
p->translate( offset );
144+
}
119145

120146
_renderPolygon( p, points, rings );
121147

122148
if ( !mOffset.isNull() )
123-
p->translate( -mOffset );
149+
{
150+
p->translate( -offset );
151+
}
124152
}
125153

126154
QgsStringMap QgsSimpleFillSymbolLayerV2::properties() const
@@ -131,14 +159,18 @@ QgsStringMap QgsSimpleFillSymbolLayerV2::properties() const
131159
map["color_border"] = QgsSymbolLayerV2Utils::encodeColor( mBorderColor );
132160
map["style_border"] = QgsSymbolLayerV2Utils::encodePenStyle( mBorderStyle );
133161
map["width_border"] = QString::number( mBorderWidth );
162+
map["border_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mBorderWidthUnit );
134163
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
164+
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
135165
return map;
136166
}
137167

138168
QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::clone() const
139169
{
140170
QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( mColor, mBrushStyle, mBorderColor, mBorderStyle, mBorderWidth );
141171
sl->setOffset( mOffset );
172+
sl->setOffsetUnit( mOffsetUnit );
173+
sl->setBorderWidthUnit( mBorderWidthUnit );
142174
return sl;
143175
}
144176

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,28 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
7474
void setOffset( QPointF offset ) { mOffset = offset; }
7575
QPointF offset() { return mOffset; }
7676

77+
void setBorderWidthUnit( QgsSymbolV2::OutputUnit unit ) { mBorderWidthUnit = unit; }
78+
QgsSymbolV2::OutputUnit borderWidthUnit() const { return mBorderWidthUnit; }
79+
80+
void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
81+
QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
82+
83+
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
84+
QgsSymbolV2::OutputUnit outputUnit() const;
85+
7786
protected:
7887
QBrush mBrush;
7988
QBrush mSelBrush;
8089
Qt::BrushStyle mBrushStyle;
8190
QColor mBorderColor;
8291
Qt::PenStyle mBorderStyle;
8392
double mBorderWidth;
93+
QgsSymbolV2::OutputUnit mBorderWidthUnit;
8494
QPen mPen;
8595
QPen mSelPen;
8696

8797
QPointF mOffset;
98+
QgsSymbolV2::OutputUnit mOffsetUnit;
8899
};
89100

90101
/**Base class for polygon renderers generating texture images*/

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,6 @@ void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>*
673673
QgsSymbolV2* QgsFillSymbolV2::clone() const
674674
{
675675
QgsSymbolV2* cloneSymbol = new QgsFillSymbolV2( cloneLayers() );
676-
cloneSymbol->setOutputUnit( outputUnit() );
677676
cloneSymbol->setAlpha( mAlpha );
678677
return cloneSymbol;
679678
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,13 @@ void QgsSimpleFillSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
408408
spinOffsetY->blockSignals( true );
409409
spinOffsetY->setValue( mLayer->offset().y() );
410410
spinOffsetY->blockSignals( false );
411+
412+
mBorderWidthUnitComboBox->blockSignals( true );
413+
mBorderWidthUnitComboBox->setCurrentIndex( mLayer->borderWidthUnit() );
414+
mBorderWidthUnitComboBox->blockSignals( false );
415+
mOffsetUnitComboBox->blockSignals( true );
416+
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
417+
mOffsetUnitComboBox->blockSignals( false );
411418
}
412419

413420
QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2Widget::symbolLayer()
@@ -473,6 +480,24 @@ void QgsSimpleFillSymbolLayerV2Widget::offsetChanged()
473480
emit changed();
474481
}
475482

483+
void QgsSimpleFillSymbolLayerV2Widget::on_mBorderWidthUnitComboBox_currentIndexChanged( int index )
484+
{
485+
if ( mLayer )
486+
{
487+
mLayer->setBorderWidthUnit(( QgsSymbolV2::OutputUnit ) index );
488+
emit changed();
489+
}
490+
}
491+
492+
void QgsSimpleFillSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChanged( int index )
493+
{
494+
if ( mLayer )
495+
{
496+
mLayer->setOffsetUnit(( QgsSymbolV2::OutputUnit ) index );
497+
emit changed();
498+
}
499+
}
500+
476501
///////////
477502

478503
QgsMarkerLineSymbolLayerV2Widget::QgsMarkerLineSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent )

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ class GUI_EXPORT QgsSimpleFillSymbolLayerV2Widget : public QgsSymbolLayerV2Widge
138138
void borderWidthChanged();
139139
void borderStyleChanged();
140140
void offsetChanged();
141+
void on_mBorderWidthUnitComboBox_currentIndexChanged( int index );
142+
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
141143

142144
protected:
143145
QgsSimpleFillSymbolLayerV2* mLayer;

‎src/ui/symbollayer/widget_simplefill.ui

Lines changed: 81 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>335</width>
10-
<height>212</height>
10+
<height>220</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -19,51 +19,35 @@
1919
</property>
2020
<item>
2121
<layout class="QGridLayout" name="gridLayout">
22-
<item row="3" column="1">
23-
<widget class="QgsPenStyleComboBox" name="cboBorderStyle"/>
24-
</item>
25-
<item row="2" column="0">
26-
<widget class="QLabel" name="label_3">
22+
<item row="0" column="1">
23+
<widget class="QgsColorButtonV2" name="btnChangeColor">
2724
<property name="text">
28-
<string>Border color</string>
25+
<string>Change</string>
2926
</property>
3027
</widget>
3128
</item>
32-
<item row="1" column="0">
33-
<widget class="QLabel" name="label_2">
29+
<item row="6" column="0">
30+
<widget class="QLabel" name="label_6">
3431
<property name="text">
35-
<string>Fill style</string>
32+
<string>Offset X,Y</string>
3633
</property>
3734
</widget>
3835
</item>
39-
<item row="1" column="1">
40-
<widget class="QgsBrushStyleComboBox" name="cboFillStyle"/>
41-
</item>
42-
<item row="0" column="0">
43-
<widget class="QLabel" name="label">
36+
<item row="2" column="0">
37+
<widget class="QLabel" name="label_3">
4438
<property name="text">
45-
<string>Color</string>
46-
</property>
47-
</widget>
48-
</item>
49-
<item row="4" column="1">
50-
<widget class="QDoubleSpinBox" name="spinBorderWidth">
51-
<property name="decimals">
52-
<number>5</number>
53-
</property>
54-
<property name="maximum">
55-
<double>100000.000000000000000</double>
39+
<string>Border color</string>
5640
</property>
5741
</widget>
5842
</item>
59-
<item row="5" column="0">
60-
<widget class="QLabel" name="label_6">
43+
<item row="2" column="1">
44+
<widget class="QgsColorButtonV2" name="btnChangeBorderColor">
6145
<property name="text">
62-
<string>Offset X,Y</string>
46+
<string>Change</string>
6347
</property>
6448
</widget>
6549
</item>
66-
<item row="5" column="1">
50+
<item row="6" column="1">
6751
<layout class="QHBoxLayout" name="horizontalLayout">
6852
<item>
6953
<widget class="QDoubleSpinBox" name="spinOffsetX">
@@ -93,17 +77,40 @@
9377
</item>
9478
</layout>
9579
</item>
96-
<item row="2" column="1">
97-
<widget class="QgsColorButtonV2" name="btnChangeBorderColor">
80+
<item row="0" column="0">
81+
<widget class="QLabel" name="label">
9882
<property name="text">
99-
<string>Change</string>
83+
<string>Color</string>
10084
</property>
10185
</widget>
10286
</item>
103-
<item row="0" column="1">
104-
<widget class="QgsColorButtonV2" name="btnChangeColor">
87+
<item row="1" column="1">
88+
<widget class="QgsBrushStyleComboBox" name="cboFillStyle"/>
89+
</item>
90+
<item row="4" column="0">
91+
<widget class="QLabel" name="label_5">
10592
<property name="text">
106-
<string>Change</string>
93+
<string>Border width</string>
94+
</property>
95+
</widget>
96+
</item>
97+
<item row="3" column="1">
98+
<widget class="QgsPenStyleComboBox" name="cboBorderStyle"/>
99+
</item>
100+
<item row="4" column="1">
101+
<widget class="QDoubleSpinBox" name="spinBorderWidth">
102+
<property name="decimals">
103+
<number>5</number>
104+
</property>
105+
<property name="maximum">
106+
<double>100000.000000000000000</double>
107+
</property>
108+
</widget>
109+
</item>
110+
<item row="1" column="0">
111+
<widget class="QLabel" name="label_2">
112+
<property name="text">
113+
<string>Fill style</string>
107114
</property>
108115
</widget>
109116
</item>
@@ -114,10 +121,45 @@
114121
</property>
115122
</widget>
116123
</item>
117-
<item row="4" column="0">
118-
<widget class="QLabel" name="label_5">
124+
<item row="5" column="1">
125+
<widget class="QComboBox" name="mBorderWidthUnitComboBox">
126+
<item>
127+
<property name="text">
128+
<string>Millimeter</string>
129+
</property>
130+
</item>
131+
<item>
132+
<property name="text">
133+
<string>Map unit</string>
134+
</property>
135+
</item>
136+
</widget>
137+
</item>
138+
<item row="5" column="0">
139+
<widget class="QLabel" name="mBorderWidthUnitLabel">
119140
<property name="text">
120-
<string>Border width</string>
141+
<string>Border width unit</string>
142+
</property>
143+
</widget>
144+
</item>
145+
<item row="7" column="1">
146+
<widget class="QComboBox" name="mOffsetUnitComboBox">
147+
<item>
148+
<property name="text">
149+
<string>Millimeter</string>
150+
</property>
151+
</item>
152+
<item>
153+
<property name="text">
154+
<string>Map unit</string>
155+
</property>
156+
</item>
157+
</widget>
158+
</item>
159+
<item row="7" column="0">
160+
<widget class="QLabel" name="mOffsetUnitLabel">
161+
<property name="text">
162+
<string>Offset unit</string>
121163
</property>
122164
</widget>
123165
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.