Skip to content

Commit 6c47be6

Browse files
committedMar 12, 2013
Output unit for svg marker
1 parent d6b140a commit 6c47be6

File tree

5 files changed

+191
-52
lines changed

5 files changed

+191
-52
lines changed
 

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ QgsSvgMarkerSymbolLayerV2::QgsSvgMarkerSymbolLayerV2( QString name, double size,
612612
mAngle = angle;
613613
mOffset = QPointF( 0, 0 );
614614
mOutlineWidth = 1.0;
615+
mOutlineWidthUnit = QgsSymbolV2::MM;
615616
mFillColor = QColor( Qt::black );
616617
mOutlineColor = QColor( Qt::black );
617618
}
@@ -653,14 +654,20 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create( const QgsStringMap& props )
653654
}
654655
}
655656

657+
if ( props.contains( "size_unit" ) )
658+
m->setSizeUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( "size_unit" ) );
656659
if ( props.contains( "offset" ) )
657660
m->setOffset( QgsSymbolLayerV2Utils::decodePoint( props["offset"] ) );
661+
if ( props.contains( "offset_unit" ) )
662+
m->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit"] ) );
658663
if ( props.contains( "fill" ) )
659664
m->setFillColor( QColor( props["fill"] ) );
660665
if ( props.contains( "outline" ) )
661666
m->setOutlineColor( QColor( props["outline"] ) );
662667
if ( props.contains( "outline-width" ) )
663668
m->setOutlineWidth( props["outline-width"].toDouble() );
669+
if ( props.contains( "outline_width_unit" ) )
670+
m->setOutlineWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["outline_width_unit"] ) );
664671
return m;
665672
}
666673

@@ -710,15 +717,18 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
710717
return;
711718
}
712719

713-
double size = context.outputLineWidth( mSize );
720+
double size = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );
714721
//don't render symbols with size below one or above 10,000 pixels
715722
if (( int )size < 1 || 10000.0 < size )
716723
{
717724
return;
718725
}
719726

720727
p->save();
721-
QPointF outputOffset = QPointF( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
728+
double offsetX = mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
729+
double offsetY = mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
730+
QPointF outputOffset( offsetX, offsetY );
731+
722732
if ( mAngle )
723733
outputOffset = _rotatedOffset( outputOffset, mAngle );
724734
p->translate( point + outputOffset );
@@ -770,7 +780,7 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
770780
if ( context.selected() )
771781
{
772782
QPen pen( context.selectionColor() );
773-
double penWidth = context.outputLineWidth( 1.0 );
783+
double penWidth = QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), QgsSymbolV2::MM );
774784
if ( penWidth > size / 20 )
775785
{
776786
// keep the pen width from covering symbol
@@ -794,11 +804,14 @@ QgsStringMap QgsSvgMarkerSymbolLayerV2::properties() const
794804
QgsStringMap map;
795805
map["name"] = QgsSymbolLayerV2Utils::symbolPathToName( mPath );
796806
map["size"] = QString::number( mSize );
807+
map["size_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mSizeUnit );
797808
map["angle"] = QString::number( mAngle );
798809
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
810+
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
799811
map["fill"] = mFillColor.name();
800812
map["outline"] = mOutlineColor.name();
801813
map["outline-width"] = QString::number( mOutlineWidth );
814+
map["outline_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOutlineWidthUnit );
802815
return map;
803816
}
804817

@@ -808,10 +821,30 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::clone() const
808821
m->setFillColor( mFillColor );
809822
m->setOutlineColor( mOutlineColor );
810823
m->setOutlineWidth( mOutlineWidth );
824+
m->setOutlineWidthUnit( mOutlineWidthUnit );
811825
m->setOffset( mOffset );
826+
m->setOffsetUnit( mOffsetUnit );
827+
m->setSizeUnit( mSizeUnit );
812828
return m;
813829
}
814830

831+
void QgsSvgMarkerSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
832+
{
833+
mSizeUnit = unit;
834+
mOffsetUnit = unit;
835+
mOutlineWidthUnit = unit;
836+
}
837+
838+
QgsSymbolV2::OutputUnit QgsSvgMarkerSymbolLayerV2::outputUnit() const
839+
{
840+
QgsSymbolV2::OutputUnit unit = mSizeUnit;
841+
if ( unit != mOffsetUnit || unit != mOutlineWidthUnit )
842+
{
843+
return QgsSymbolV2::Mixed;
844+
}
845+
return unit;
846+
}
847+
815848
void QgsSvgMarkerSymbolLayerV2::writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
816849
{
817850
// <Graphic>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
138138
double outlineWidth() const { return mOutlineWidth; }
139139
void setOutlineWidth( double w ) { mOutlineWidth = w; }
140140

141+
void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
142+
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }
143+
144+
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
145+
QgsSymbolV2::OutputUnit outputUnit() const;
146+
141147
protected:
142148
QString mPath;
143149

@@ -146,6 +152,7 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
146152
QColor mFillColor;
147153
QColor mOutlineColor;
148154
double mOutlineWidth;
155+
QgsSymbolV2::OutputUnit mOutlineWidthUnit;
149156
double mOrigSize;
150157
};
151158

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,15 @@ void QgsSvgMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
812812
spinOffsetY->setValue( mLayer->offset().y() );
813813
spinOffsetY->blockSignals( false );
814814

815+
mSizeUnitComboBox->blockSignals( true );
816+
mSizeUnitComboBox->setCurrentIndex( mLayer->sizeUnit() );
817+
mSizeUnitComboBox->blockSignals( false );
818+
mBorderWidthUnitComboBox->blockSignals( true );
819+
mBorderWidthUnitComboBox->setCurrentIndex( mLayer->outlineWidthUnit() );
820+
mBorderWidthUnitComboBox->blockSignals( false );
821+
mOffsetUnitComboBox->blockSignals( true );
822+
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
823+
mOffsetUnitComboBox->blockSignals( false );
815824
setGuiForSvg( mLayer );
816825
}
817826

@@ -935,6 +944,30 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mBorderWidthSpinBox_valueChanged( doubl
935944
}
936945
}
937946

947+
void QgsSvgMarkerSymbolLayerV2Widget::on_mSizeUnitComboBox_currentIndexChanged( int index )
948+
{
949+
if ( mLayer )
950+
{
951+
mLayer->setSizeUnit(( QgsSymbolV2::OutputUnit ) index );
952+
}
953+
}
954+
955+
void QgsSvgMarkerSymbolLayerV2Widget::on_mBorderWidthUnitComboBox_currentIndexChanged( int index )
956+
{
957+
if ( mLayer )
958+
{
959+
mLayer->setOutlineWidthUnit(( QgsSymbolV2::OutputUnit ) index );
960+
}
961+
}
962+
963+
void QgsSvgMarkerSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChanged( int index )
964+
{
965+
if ( mLayer )
966+
{
967+
mLayer->setOffsetUnit(( QgsSymbolV2::OutputUnit ) index );
968+
}
969+
}
970+
938971
///////////////
939972

940973
QgsLineDecorationSymbolLayerV2Widget::QgsLineDecorationSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent )

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ class GUI_EXPORT QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget
209209
void on_mChangeColorButton_clicked();
210210
void on_mChangeBorderColorButton_clicked();
211211
void on_mBorderWidthSpinBox_valueChanged( double d );
212+
void on_mSizeUnitComboBox_currentIndexChanged( int index );
213+
void on_mBorderWidthUnitComboBox_currentIndexChanged( int index );
214+
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
212215

213216
protected:
214217

‎src/ui/symbollayer/widget_svgmarker.ui

Lines changed: 112 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,109 @@
1919
</property>
2020
<item row="0" column="0" colspan="2">
2121
<layout class="QGridLayout">
22-
<item row="0" column="0">
23-
<widget class="QLabel" name="label_2">
24-
<property name="sizePolicy">
25-
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
26-
<horstretch>0</horstretch>
27-
<verstretch>0</verstretch>
28-
</sizepolicy>
22+
<item row="2" column="1">
23+
<widget class="QDoubleSpinBox" name="spinAngle">
24+
<property name="decimals">
25+
<number>2</number>
26+
</property>
27+
<property name="maximum">
28+
<double>360.000000000000000</double>
29+
</property>
30+
<property name="singleStep">
31+
<double>5.000000000000000</double>
2932
</property>
33+
</widget>
34+
</item>
35+
<item row="1" column="1">
36+
<widget class="QComboBox" name="mSizeUnitComboBox">
37+
<item>
38+
<property name="text">
39+
<string>Millimeter</string>
40+
</property>
41+
</item>
42+
<item>
43+
<property name="text">
44+
<string>Map unit</string>
45+
</property>
46+
</item>
47+
</widget>
48+
</item>
49+
<item row="7" column="0">
50+
<widget class="QLabel" name="label_4">
3051
<property name="text">
31-
<string>Size</string>
52+
<string>Offset X,Y</string>
3253
</property>
3354
</widget>
3455
</item>
35-
<item row="3" column="1">
56+
<item row="4" column="1">
3657
<widget class="QgsColorButtonV2" name="mChangeBorderColorButton">
3758
<property name="text">
3859
<string>Change</string>
3960
</property>
4061
</widget>
4162
</item>
63+
<item row="1" column="0">
64+
<widget class="QLabel" name="mSizeUnitLabel">
65+
<property name="text">
66+
<string>Size unit</string>
67+
</property>
68+
</widget>
69+
</item>
70+
<item row="3" column="0">
71+
<widget class="QLabel" name="mColorLabel">
72+
<property name="text">
73+
<string>Color</string>
74+
</property>
75+
</widget>
76+
</item>
4277
<item row="5" column="0">
43-
<widget class="QLabel" name="label_4">
78+
<widget class="QLabel" name="mBorderWidthLabel">
4479
<property name="text">
45-
<string>Offset X,Y</string>
80+
<string>Border width</string>
4681
</property>
4782
</widget>
4883
</item>
49-
<item row="1" column="0">
84+
<item row="3" column="1">
85+
<widget class="QgsColorButtonV2" name="mChangeColorButton">
86+
<property name="text">
87+
<string>Change</string>
88+
</property>
89+
</widget>
90+
</item>
91+
<item row="5" column="1">
92+
<widget class="QDoubleSpinBox" name="mBorderWidthSpinBox">
93+
<property name="decimals">
94+
<number>5</number>
95+
</property>
96+
</widget>
97+
</item>
98+
<item row="2" column="0">
5099
<widget class="QLabel" name="label_3">
51100
<property name="text">
52101
<string>Angle</string>
53102
</property>
54103
</widget>
55104
</item>
105+
<item row="4" column="0">
106+
<widget class="QLabel" name="mBorderColorLabel">
107+
<property name="text">
108+
<string>Border color</string>
109+
</property>
110+
</widget>
111+
</item>
112+
<item row="0" column="0">
113+
<widget class="QLabel" name="label_2">
114+
<property name="sizePolicy">
115+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
116+
<horstretch>0</horstretch>
117+
<verstretch>0</verstretch>
118+
</sizepolicy>
119+
</property>
120+
<property name="text">
121+
<string>Size</string>
122+
</property>
123+
</widget>
124+
</item>
56125
<item row="0" column="1">
57126
<widget class="QDoubleSpinBox" name="spinSize">
58127
<property name="sizePolicy">
@@ -72,7 +141,7 @@
72141
</property>
73142
</widget>
74143
</item>
75-
<item row="5" column="1">
144+
<item row="7" column="1">
76145
<layout class="QHBoxLayout" name="horizontalLayout">
77146
<item>
78147
<widget class="QDoubleSpinBox" name="spinOffsetX">
@@ -102,51 +171,45 @@
102171
</item>
103172
</layout>
104173
</item>
105-
<item row="3" column="0">
106-
<widget class="QLabel" name="mBorderColorLabel">
174+
<item row="6" column="0">
175+
<widget class="QLabel" name="mBorderWidthUnit">
107176
<property name="text">
108-
<string>Border color</string>
177+
<string>Border width unit</string>
109178
</property>
110179
</widget>
111180
</item>
112-
<item row="4" column="0">
113-
<widget class="QLabel" name="mBorderWidthLabel">
114-
<property name="text">
115-
<string>Border width</string>
116-
</property>
181+
<item row="6" column="1">
182+
<widget class="QComboBox" name="mBorderWidthUnitComboBox">
183+
<item>
184+
<property name="text">
185+
<string>Millimeter</string>
186+
</property>
187+
</item>
188+
<item>
189+
<property name="text">
190+
<string>Map unit</string>
191+
</property>
192+
</item>
117193
</widget>
118194
</item>
119-
<item row="2" column="0">
120-
<widget class="QLabel" name="mColorLabel">
121-
<property name="text">
122-
<string>Color</string>
123-
</property>
195+
<item row="8" column="1">
196+
<widget class="QComboBox" name="mOffsetUnitComboBox">
197+
<item>
198+
<property name="text">
199+
<string>Millimeter</string>
200+
</property>
201+
</item>
202+
<item>
203+
<property name="text">
204+
<string>Map unit</string>
205+
</property>
206+
</item>
124207
</widget>
125208
</item>
126-
<item row="2" column="1">
127-
<widget class="QgsColorButtonV2" name="mChangeColorButton">
209+
<item row="8" column="0">
210+
<widget class="QLabel" name="mOffsetUnitLabel">
128211
<property name="text">
129-
<string>Change</string>
130-
</property>
131-
</widget>
132-
</item>
133-
<item row="1" column="1">
134-
<widget class="QDoubleSpinBox" name="spinAngle">
135-
<property name="decimals">
136-
<number>2</number>
137-
</property>
138-
<property name="maximum">
139-
<double>360.000000000000000</double>
140-
</property>
141-
<property name="singleStep">
142-
<double>5.000000000000000</double>
143-
</property>
144-
</widget>
145-
</item>
146-
<item row="4" column="1">
147-
<widget class="QDoubleSpinBox" name="mBorderWidthSpinBox">
148-
<property name="decimals">
149-
<number>5</number>
212+
<string>Offset unit</string>
150213
</property>
151214
</widget>
152215
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.