Skip to content

Commit ac3dbea

Browse files
committedMar 12, 2013
Distance unit for vector field symbol layer
1 parent 588ceb9 commit ac3dbea

File tree

6 files changed

+83
-23
lines changed

6 files changed

+83
-23
lines changed
 

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "qgsvectorfieldsymbollayer.h"
1919
#include "qgsvectorlayer.h"
2020

21-
QgsVectorFieldSymbolLayer::QgsVectorFieldSymbolLayer(): mXAttribute( "" ), mYAttribute( "" ), mScale( 1.0 ),
21+
QgsVectorFieldSymbolLayer::QgsVectorFieldSymbolLayer(): mXAttribute( "" ), mYAttribute( "" ), mDistanceUnit( QgsSymbolV2::MM ), mScale( 1.0 ),
2222
mVectorFieldType( Cartesian ), mAngleOrientation( ClockwiseFromNorth ), mAngleUnits( Degrees ), mXIndex( -1 ), mYIndex( -1 )
2323
{
2424
setSubSymbol( new QgsLineSymbolV2() );
@@ -28,6 +28,16 @@ QgsVectorFieldSymbolLayer::~QgsVectorFieldSymbolLayer()
2828
{
2929
}
3030

31+
void QgsVectorFieldSymbolLayer::setOutputUnit( QgsSymbolV2::OutputUnit unit )
32+
{
33+
mDistanceUnit = unit; //other units are not used
34+
}
35+
36+
QgsSymbolV2::OutputUnit QgsVectorFieldSymbolLayer::outputUnit() const
37+
{
38+
return mDistanceUnit;
39+
}
40+
3141
QgsSymbolLayerV2* QgsVectorFieldSymbolLayer::create( const QgsStringMap& properties )
3242
{
3343
QgsVectorFieldSymbolLayer* symbolLayer = new QgsVectorFieldSymbolLayer();
@@ -39,6 +49,10 @@ QgsSymbolLayerV2* QgsVectorFieldSymbolLayer::create( const QgsStringMap& propert
3949
{
4050
symbolLayer->setYAttribute( properties["y_attribute"] );
4151
}
52+
if ( properties.contains( "distance_unit" ) )
53+
{
54+
symbolLayer->setDistanceUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["distance_unit"] ) );
55+
}
4256
if ( properties.contains( "scale" ) )
4357
{
4458
symbolLayer->setScale( properties["scale"].toDouble() );
@@ -75,6 +89,8 @@ void QgsVectorFieldSymbolLayer::renderPoint( const QPointF& point, QgsSymbolV2Re
7589
return;
7690
}
7791

92+
const QgsRenderContext& ctx = context.renderContext();
93+
7894
const QgsFeature* f = context.feature();
7995
if ( !f )
8096
{
@@ -102,17 +118,17 @@ void QgsVectorFieldSymbolLayer::renderPoint( const QPointF& point, QgsSymbolV2Re
102118
switch ( mVectorFieldType )
103119
{
104120
case Cartesian:
105-
xComponent = context.outputLineWidth( xVal );
106-
yComponent = context.outputLineWidth( yVal );
121+
xComponent = xVal * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
122+
yComponent = yVal * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
107123
break;
108124
case Polar:
109125
convertPolarToCartesian( xVal, yVal, xComponent, yComponent );
110-
xComponent = context.outputLineWidth( xComponent );
111-
yComponent = context.outputLineWidth( yComponent );
126+
xComponent = xComponent * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
127+
yComponent = yComponent * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
112128
break;
113129
case Height:
114130
xComponent = 0;
115-
yComponent = context.outputLineWidth( yVal );
131+
yComponent = yVal * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
116132
break;
117133
default:
118134
break;
@@ -170,6 +186,7 @@ QgsStringMap QgsVectorFieldSymbolLayer::properties() const
170186
QgsStringMap properties;
171187
properties["x_attribute"] = mXAttribute;
172188
properties["y_attribute"] = mYAttribute;
189+
properties["distance_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mDistanceUnit );
173190
properties["scale"] = QString::number( mScale );
174191
properties["vector_field_type"] = QString::number( mVectorFieldType );
175192
properties["angle_orientation"] = QString::number( mAngleOrientation );

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,16 @@ class CORE_EXPORT QgsVectorFieldSymbolLayer: public QgsMarkerSymbolLayerV2
8181
void setAngleUnits( AngleUnits units ) { mAngleUnits = units; }
8282
AngleUnits angleUnits() const { return mAngleUnits; }
8383

84+
void setOutputUnit( QgsSymbolV2::OutputUnit unit );
85+
QgsSymbolV2::OutputUnit outputUnit() const;
86+
87+
void setDistanceUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceUnit = unit; }
88+
QgsSymbolV2::OutputUnit distanceUnit() const { return mDistanceUnit; }
89+
8490
private:
8591
QString mXAttribute;
8692
QString mYAttribute;
93+
QgsSymbolV2::OutputUnit mDistanceUnit;
8794
double mScale;
8895
VectorFieldType mVectorFieldType;
8996
AngleOrientation mAngleOrientation;

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ void QgsVectorFieldSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer )
8686
{
8787
mRadiansRadioButton->setChecked( true );
8888
}
89+
90+
mDistanceUnitComboBox->blockSignals( true );
91+
mDistanceUnitComboBox->setCurrentIndex( mLayer->distanceUnit() );
92+
mDistanceUnitComboBox->blockSignals( false );
93+
8994
emit changed();
9095
}
9196

@@ -194,3 +199,12 @@ void QgsVectorFieldSymbolLayerWidget::on_mCounterclockwiseFromEastRadioButton_to
194199
emit changed();
195200
}
196201
}
202+
203+
void QgsVectorFieldSymbolLayerWidget::on_mDistanceUnitComboBox_currentIndexChanged( int index )
204+
{
205+
if ( mLayer )
206+
{
207+
mLayer->setDistanceUnit(( QgsSymbolV2::OutputUnit ) index );
208+
emit changed();
209+
}
210+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class GUI_EXPORT QgsVectorFieldSymbolLayerWidget: public QgsSymbolLayerV2Widget,
4747
void on_mRadiansRadioButton_toggled( bool checked );
4848
void on_mClockwiseFromNorthRadioButton_toggled( bool checked );
4949
void on_mCounterclockwiseFromEastRadioButton_toggled( bool checked );
50+
void on_mDistanceUnitComboBox_currentIndexChanged( int index );
5051
};
5152

5253
#endif // QGSVECTORFIELDSYMBOLLAYERWIDGET_H

‎src/ui/symbollayer/widget_ellipse.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>336</width>
10-
<height>336</height>
10+
<height>357</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">

‎src/ui/symbollayer/widget_vectorfield.ui

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,34 @@
1717
<property name="margin">
1818
<number>1</number>
1919
</property>
20-
<item row="0" column="0">
21-
<widget class="QLabel" name="mXAttributeLabel">
22-
<property name="text">
23-
<string>X attribute</string>
24-
</property>
25-
</widget>
26-
</item>
27-
<item row="0" column="1">
28-
<widget class="QComboBox" name="mXAttributeComboBox"/>
29-
</item>
3020
<item row="1" column="0">
3121
<widget class="QLabel" name="mYAttributeLabel">
3222
<property name="text">
3323
<string>Y attribute</string>
3424
</property>
3525
</widget>
3626
</item>
37-
<item row="1" column="1">
38-
<widget class="QComboBox" name="mYAttributeComboBox"/>
27+
<item row="0" column="1">
28+
<widget class="QComboBox" name="mXAttributeComboBox"/>
3929
</item>
40-
<item row="2" column="0">
30+
<item row="3" column="1">
31+
<widget class="QDoubleSpinBox" name="mScaleSpinBox"/>
32+
</item>
33+
<item row="3" column="0">
4134
<widget class="QLabel" name="mScaleLabel">
4235
<property name="text">
4336
<string>Scale</string>
4437
</property>
4538
</widget>
4639
</item>
47-
<item row="2" column="1">
48-
<widget class="QDoubleSpinBox" name="mScaleSpinBox"/>
40+
<item row="0" column="0">
41+
<widget class="QLabel" name="mXAttributeLabel">
42+
<property name="text">
43+
<string>X attribute</string>
44+
</property>
45+
</widget>
4946
</item>
50-
<item row="3" column="0" colspan="2">
47+
<item row="4" column="0" colspan="2">
5148
<layout class="QGridLayout" name="gridLayout_2">
5249
<item row="0" column="0">
5350
<layout class="QHBoxLayout" name="horizontalLayout">
@@ -141,6 +138,30 @@
141138
</item>
142139
</layout>
143140
</item>
141+
<item row="1" column="1">
142+
<widget class="QComboBox" name="mYAttributeComboBox"/>
143+
</item>
144+
<item row="2" column="1">
145+
<widget class="QComboBox" name="mDistanceUnitComboBox">
146+
<item>
147+
<property name="text">
148+
<string>Millimeter</string>
149+
</property>
150+
</item>
151+
<item>
152+
<property name="text">
153+
<string>Map unit</string>
154+
</property>
155+
</item>
156+
</widget>
157+
</item>
158+
<item row="2" column="0">
159+
<widget class="QLabel" name="mDistanceUnitLabel">
160+
<property name="text">
161+
<string>Distance unit</string>
162+
</property>
163+
</widget>
164+
</item>
144165
</layout>
145166
</widget>
146167
<resources/>

0 commit comments

Comments
 (0)
Please sign in to comment.