Skip to content

Commit d6b140a

Browse files
committedMar 11, 2013
Output unit for simple marker
1 parent c771505 commit d6b140a

File tree

7 files changed

+144
-60
lines changed

7 files changed

+144
-60
lines changed
 

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ QgsSimpleMarkerSymbolLayerV2::QgsSimpleMarkerSymbolLayerV2( QString name, QColor
5555
mAngle = angle;
5656
mOffset = QPointF( 0, 0 );
5757
mScaleMethod = scaleMethod;
58+
mSizeUnit = QgsSymbolV2::MM;
59+
mOffsetUnit = QgsSymbolV2::MM;
5860
}
5961

6062
QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create( const QgsStringMap& props )
@@ -82,6 +84,10 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create( const QgsStringMap& prop
8284
QgsSimpleMarkerSymbolLayerV2* m = new QgsSimpleMarkerSymbolLayerV2( name, color, borderColor, size, angle, scaleMethod );
8385
if ( props.contains( "offset" ) )
8486
m->setOffset( QgsSymbolLayerV2Utils::decodePoint( props["offset"] ) );
87+
if ( props.contains( "offset_unit" ) )
88+
m->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit"] ) );
89+
if ( props.contains( "size_unit" ) )
90+
m->setSizeUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["size_unit"] ) );
8591
return m;
8692
}
8793

@@ -146,7 +152,7 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
146152
// scale the shape (if the size is not going to be modified)
147153
if ( !hasDataDefinedSize )
148154
{
149-
double scaledSize = context.outputLineWidth( mSize );
155+
double scaledSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );
150156
if ( mUsingCache )
151157
scaledSize *= context.renderContext().rasterScaleFactor();
152158
double half = scaledSize / 2.0;
@@ -178,7 +184,7 @@ void QgsSimpleMarkerSymbolLayerV2::startRender( QgsSymbolV2RenderContext& contex
178184

179185
void QgsSimpleMarkerSymbolLayerV2::prepareCache( QgsSymbolV2RenderContext& context )
180186
{
181-
double scaledSize = context.outputPixelSize( mSize );
187+
double scaledSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );
182188

183189
// calculate necessary image size for the cache
184190
double pw = (( mPen.widthF() == 0 ? 1 : mPen.widthF() ) + 1 ) / 2 * 2; // make even (round up); handle cosmetic pen
@@ -375,7 +381,9 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
375381
return;
376382
}
377383

378-
QPointF off( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
384+
double offsetX = mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
385+
double offsetY = mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
386+
QPointF off( offsetX, offsetY );
379387
if ( mAngle )
380388
off = _rotatedOffset( off, mAngle );
381389

@@ -401,7 +409,7 @@ void QgsSimpleMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV
401409
// resize if necessary
402410
if ( hasDataDefinedSize )
403411
{
404-
double scaledSize = context.outputLineWidth( mSize );
412+
double scaledSize = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );
405413

406414
switch ( mScaleMethod )
407415
{
@@ -440,8 +448,10 @@ QgsStringMap QgsSimpleMarkerSymbolLayerV2::properties() const
440448
map["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
441449
map["color_border"] = QgsSymbolLayerV2Utils::encodeColor( mBorderColor );
442450
map["size"] = QString::number( mSize );
451+
map["size_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mSizeUnit );
443452
map["angle"] = QString::number( mAngle );
444453
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
454+
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
445455
map["scale_method"] = QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod );
446456
return map;
447457
}
@@ -450,6 +460,8 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::clone() const
450460
{
451461
QgsSimpleMarkerSymbolLayerV2* m = new QgsSimpleMarkerSymbolLayerV2( mName, mColor, mBorderColor, mSize, mAngle, mScaleMethod );
452462
m->setOffset( mOffset );
463+
m->setSizeUnit( mSizeUnit );
464+
m->setOffsetUnit( mOffsetUnit );
453465
return m;
454466
}
455467

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727

2828
QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked )
29-
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked )
29+
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked ), mSizeUnit( QgsSymbolV2::MM ), mOffsetUnit( QgsSymbolV2::MM )
3030
{
3131
}
3232

@@ -47,6 +47,22 @@ void QgsMarkerSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context,
4747
stopRender( context );
4848
}
4949

50+
void QgsMarkerSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
51+
{
52+
mSizeUnit = unit;
53+
mOffsetUnit = unit;
54+
}
55+
56+
QgsSymbolV2::OutputUnit QgsMarkerSymbolLayerV2::outputUnit() const
57+
{
58+
QgsSymbolV2::OutputUnit unit = mSizeUnit;
59+
if ( mOffsetUnit != unit )
60+
{
61+
return QgsSymbolV2::Mixed;
62+
}
63+
return unit;
64+
}
65+
5066
void QgsLineSymbolLayerV2::drawPreviewIcon( QgsSymbolV2RenderContext& context, QSize size )
5167
{
5268
QPolygonF points;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,23 @@ class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
121121
virtual void writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
122122
{ Q_UNUSED( props ); element.appendChild( doc.createComment( QString( "QgsMarkerSymbolLayerV2 %1 not implemented yet" ).arg( layerType() ) ) ); }
123123

124+
void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
125+
QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }
126+
127+
void setSizeUnit( QgsSymbolV2::OutputUnit unit ) { mSizeUnit = unit; }
128+
QgsSymbolV2::OutputUnit sizeUnit() const { return mSizeUnit; }
129+
130+
virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit );
131+
virtual QgsSymbolV2::OutputUnit outputUnit() const;
132+
124133
protected:
125134
QgsMarkerSymbolLayerV2( bool locked = false );
126135

127136
double mAngle;
128137
double mSize;
138+
QgsSymbolV2::OutputUnit mSizeUnit;
129139
QPointF mOffset;
140+
QgsSymbolV2::OutputUnit mOffsetUnit;
130141
QgsSymbolV2::ScaleMethod mScaleMethod;
131142
};
132143

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ void QgsMarkerSymbolV2::renderPoint( const QPointF& point, const QgsFeature* f,
554554
QgsSymbolV2* QgsMarkerSymbolV2::clone() const
555555
{
556556
QgsSymbolV2* cloneSymbol = new QgsMarkerSymbolV2( cloneLayers() );
557-
cloneSymbol->setOutputUnit( outputUnit() );
558557
cloneSymbol->setAlpha( mAlpha );
559558
return cloneSymbol;
560559
}

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer
277277
spinOffsetY->blockSignals( true );
278278
spinOffsetY->setValue( mLayer->offset().y() );
279279
spinOffsetY->blockSignals( false );
280+
281+
mSizeUnitComboBox->blockSignals( true );
282+
mSizeUnitComboBox->setCurrentIndex( mLayer->sizeUnit() );
283+
mSizeUnitComboBox->blockSignals( false );
284+
mOffsetUnitComboBox->blockSignals( true );
285+
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
286+
mOffsetUnitComboBox->blockSignals( false );
280287
}
281288

282289
QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2Widget::symbolLayer()
@@ -342,6 +349,22 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setOffset()
342349
emit changed();
343350
}
344351

352+
void QgsSimpleMarkerSymbolLayerV2Widget::on_mSizeUnitComboBox_currentIndexChanged( int index )
353+
{
354+
if ( mLayer )
355+
{
356+
mLayer->setSizeUnit(( QgsSymbolV2::OutputUnit ) index );
357+
}
358+
}
359+
360+
void QgsSimpleMarkerSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChanged( int index )
361+
{
362+
if ( mLayer )
363+
{
364+
mLayer->setOffsetUnit(( QgsSymbolV2::OutputUnit ) index );
365+
}
366+
}
367+
345368

346369
///////////
347370

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class GUI_EXPORT QgsSimpleMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Wid
105105
void setSize();
106106
void setAngle();
107107
void setOffset();
108+
void on_mSizeUnitComboBox_currentIndexChanged( int index );
109+
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
108110

109111
protected:
110112
QgsSimpleMarkerSymbolLayerV2* mLayer;

‎src/ui/symbollayer/widget_simplemarker.ui

Lines changed: 75 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>378</width>
10-
<height>275</height>
10+
<height>290</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -19,19 +19,6 @@
1919
</property>
2020
<item>
2121
<layout class="QGridLayout" name="gridLayout">
22-
<item row="4" 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>
32-
</property>
33-
</widget>
34-
</item>
3522
<item row="3" column="1">
3623
<widget class="QDoubleSpinBox" name="spinSize">
3724
<property name="decimals">
@@ -45,17 +32,17 @@
4532
</property>
4633
</widget>
4734
</item>
48-
<item row="0" column="1">
49-
<widget class="QgsColorButtonV2" name="btnChangeColorBorder">
35+
<item row="0" column="0">
36+
<widget class="QLabel" name="label">
5037
<property name="text">
51-
<string>Change</string>
38+
<string>Border color</string>
5239
</property>
5340
</widget>
5441
</item>
55-
<item row="1" column="0">
56-
<widget class="QLabel" name="label_2">
42+
<item row="0" column="1">
43+
<widget class="QgsColorButtonV2" name="btnChangeColorBorder">
5744
<property name="text">
58-
<string>Fill color</string>
45+
<string>Change</string>
5946
</property>
6047
</widget>
6148
</item>
@@ -66,35 +53,7 @@
6653
</property>
6754
</widget>
6855
</item>
69-
<item row="5" column="0">
70-
<widget class="QLabel" name="label_5">
71-
<property name="text">
72-
<string>Offset X,Y</string>
73-
</property>
74-
</widget>
75-
</item>
76-
<item row="1" column="1">
77-
<widget class="QgsColorButtonV2" name="btnChangeColorFill">
78-
<property name="text">
79-
<string>Change</string>
80-
</property>
81-
</widget>
82-
</item>
83-
<item row="4" column="0">
84-
<widget class="QLabel" name="label_4">
85-
<property name="text">
86-
<string>Angle</string>
87-
</property>
88-
</widget>
89-
</item>
90-
<item row="0" column="0">
91-
<widget class="QLabel" name="label">
92-
<property name="text">
93-
<string>Border color</string>
94-
</property>
95-
</widget>
96-
</item>
97-
<item row="5" column="1">
56+
<item row="6" column="1">
9857
<layout class="QHBoxLayout" name="horizontalLayout">
9958
<item>
10059
<widget class="QDoubleSpinBox" name="spinOffsetX">
@@ -118,8 +77,28 @@
11877
</item>
11978
</layout>
12079
</item>
121-
<item row="2" column="1">
122-
<widget class="QComboBox" name="mUnitComboBox">
80+
<item row="4" column="0">
81+
<widget class="QLabel" name="mSizeUnitLabel">
82+
<property name="text">
83+
<string>Size unit</string>
84+
</property>
85+
</widget>
86+
</item>
87+
<item row="5" column="1">
88+
<widget class="QDoubleSpinBox" name="spinAngle">
89+
<property name="decimals">
90+
<number>2</number>
91+
</property>
92+
<property name="maximum">
93+
<double>360.000000000000000</double>
94+
</property>
95+
<property name="singleStep">
96+
<double>5.000000000000000</double>
97+
</property>
98+
</widget>
99+
</item>
100+
<item row="4" column="1">
101+
<widget class="QComboBox" name="mSizeUnitComboBox">
123102
<item>
124103
<property name="text">
125104
<string>Millimeter</string>
@@ -132,13 +111,55 @@
132111
</item>
133112
</widget>
134113
</item>
135-
<item row="2" column="0">
136-
<widget class="QLabel" name="mOutputUnitLabel">
114+
<item row="1" column="0">
115+
<widget class="QLabel" name="label_2">
116+
<property name="text">
117+
<string>Fill color</string>
118+
</property>
119+
</widget>
120+
</item>
121+
<item row="5" column="0">
122+
<widget class="QLabel" name="label_4">
123+
<property name="text">
124+
<string>Angle</string>
125+
</property>
126+
</widget>
127+
</item>
128+
<item row="1" column="1">
129+
<widget class="QgsColorButtonV2" name="btnChangeColorFill">
130+
<property name="text">
131+
<string>Change</string>
132+
</property>
133+
</widget>
134+
</item>
135+
<item row="6" column="0">
136+
<widget class="QLabel" name="label_5">
137+
<property name="text">
138+
<string>Offset X,Y</string>
139+
</property>
140+
</widget>
141+
</item>
142+
<item row="7" column="0">
143+
<widget class="QLabel" name="mOffsetUnitLabel">
137144
<property name="text">
138-
<string>Unit</string>
145+
<string>Offset unit</string>
139146
</property>
140147
</widget>
141148
</item>
149+
<item row="7" column="1">
150+
<widget class="QComboBox" name="mOffsetUnitComboBox">
151+
<item>
152+
<property name="text">
153+
<string>Millimeter</string>
154+
</property>
155+
</item>
156+
<item>
157+
<property name="text">
158+
<string>Map unit</string>
159+
</property>
160+
</item>
161+
</widget>
162+
</item>
142163
</layout>
143164
</item>
144165
<item>

0 commit comments

Comments
 (0)
Please sign in to comment.