Skip to content

Commit 186b6bd

Browse files
committedSep 23, 2013
Make Anchor points usable from ellipse symbol layer too
1 parent 97ce0c2 commit 186b6bd

File tree

6 files changed

+174
-80
lines changed

6 files changed

+174
-80
lines changed
 

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
9292
{
9393
layer->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["offset_unit"] ) );
9494
}
95+
if ( properties.contains( "horizontal_anchor_point" ) )
96+
{
97+
layer->setHorizontalAnchorPoint( QgsMarkerSymbolLayerV2::HorizontalAnchorPoint( properties[ "horizontal_anchor_point" ].toInt() ) );
98+
}
99+
if ( properties.contains( "vertical_anchor_point" ) )
100+
{
101+
layer->setVerticalAnchorPoint( QgsMarkerSymbolLayerV2::VerticalAnchorPoint( properties[ "vertical_anchor_point" ].toInt() ) );
102+
}
95103

96104
//data defined properties
97105
if ( properties.contains( "width_expression" ) )
@@ -126,6 +134,14 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
126134
{
127135
layer->setDataDefinedProperty( "offset", properties["offset_expression"] );
128136
}
137+
if ( properties.contains( "horizontal_anchor_point_expression" ) )
138+
{
139+
layer->setDataDefinedProperty( "horizontal_anchor_point", properties[ "horizontal_anchor_point_expression" ] );
140+
}
141+
if ( properties.contains( "vertical_anchor_point_expression" ) )
142+
{
143+
layer->setDataDefinedProperty( "vertical_anchor_point", properties[ "vertical_anchor_point_expression" ] );
144+
}
129145

130146
//compatibility with old project file format
131147
if ( !properties["width_field"].isEmpty() )
@@ -199,7 +215,7 @@ void QgsEllipseSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Rend
199215
//offset
200216
double offsetX = 0;
201217
double offsetY = 0;
202-
markerOffset( context, offsetX, offsetY );
218+
markerOffset( context, mSymbolWidth, mSymbolHeight, mSymbolWidthUnit, mSymbolHeightUnit, offsetX, offsetY );
203219
QPointF off( offsetX, offsetY );
204220

205221
QPainter* p = context.renderContext().painter();
@@ -385,6 +401,8 @@ QgsStringMap QgsEllipseSymbolLayerV2::properties() const
385401
map["outline_color"] = QgsSymbolLayerV2Utils::encodeColor( mOutlineColor );
386402
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
387403
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
404+
map["horizontal_anchor_point"] = QString::number( mHorizontalAnchorPoint );
405+
map["vertical_anchor_point"] = QString::number( mVerticalAnchorPoint );
388406
saveDataDefinedProperties( map );
389407
return map;
390408
}

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ void QgsMarkerSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
177177
}
178178

179179
void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY )
180+
{
181+
markerOffset( context, mSize, mSize, mSizeUnit, mSizeUnit, offsetX, offsetY );
182+
}
183+
184+
void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, double width, double height,
185+
QgsSymbolV2::OutputUnit widthUnit, QgsSymbolV2::OutputUnit heightUnit,
186+
double& offsetX, double& offsetY )
180187
{
181188
offsetX = mOffset.x();
182189
offsetY = mOffset.y();
@@ -211,24 +218,25 @@ void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, do
211218
return;
212219
}
213220

214-
double anchorPointCorrection = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit ) / 2.0;
221+
double anchorPointCorrectionX = width * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), widthUnit ) / 2.0;
222+
double anchorPointCorrectionY = height * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), heightUnit ) / 2.0;
215223
if ( horizontalAnchorPoint == Left )
216224
{
217-
offsetX += anchorPointCorrection;
225+
offsetX += anchorPointCorrectionX;
218226
}
219227
else if ( horizontalAnchorPoint == Right )
220228
{
221-
offsetX -= anchorPointCorrection;
229+
offsetX -= anchorPointCorrectionX;
222230
}
223231

224232
//correct vertical position according to anchor point
225233
if ( verticalAnchorPoint == Top )
226234
{
227-
offsetY += anchorPointCorrection;
235+
offsetY += anchorPointCorrectionY;
228236
}
229237
else if ( verticalAnchorPoint == Bottom )
230238
{
231-
offsetY -= anchorPointCorrection;
239+
offsetY -= anchorPointCorrectionY;
232240
}
233241
}
234242

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
176176
QgsMarkerSymbolLayerV2( bool locked = false );
177177
//handles marker offset and anchor point shift together
178178
void markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY );
179+
void markerOffset( QgsSymbolV2RenderContext& context, double width, double height,
180+
QgsSymbolV2::OutputUnit widthUnit, QgsSymbolV2::OutputUnit heightUnit,
181+
double& offsetX, double& offsetY );
179182
static QPointF _rotatedOffset( const QPointF& offset, double angle );
180183

181184
double mAngle;

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
8282
QPointF offsetPt = mLayer->offset();
8383
spinOffsetX->setValue( offsetPt.x() );
8484
spinOffsetY->setValue( offsetPt.y() );
85+
mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
86+
mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
8587
blockComboSignals( false );
8688
}
8789

@@ -202,6 +204,26 @@ void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
202204
mSymbolWidthUnitComboBox->blockSignals( block );
203205
mOutlineWidthUnitComboBox->blockSignals( block );
204206
mSymbolHeightUnitComboBox->blockSignals( block );
207+
mHorizontalAnchorComboBox->blockSignals( block );
208+
mVerticalAnchorComboBox->blockSignals( block );
209+
}
210+
211+
void QgsEllipseSymbolLayerV2Widget::on_mHorizontalAnchorComboBox_currentIndexChanged( int index )
212+
{
213+
if ( mLayer )
214+
{
215+
mLayer->setHorizontalAnchorPoint(( QgsMarkerSymbolLayerV2::HorizontalAnchorPoint ) index );
216+
emit changed();
217+
}
218+
}
219+
220+
void QgsEllipseSymbolLayerV2Widget::on_mVerticalAnchorComboBox_currentIndexChanged( int index )
221+
{
222+
if ( mLayer )
223+
{
224+
mLayer->setVerticalAnchorPoint(( QgsMarkerSymbolLayerV2::VerticalAnchorPoint ) index );
225+
emit changed();
226+
}
205227
}
206228

207229
void QgsEllipseSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
@@ -228,6 +250,10 @@ void QgsEllipseSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
228250
"'circle'|'rectangle'|'cross'|'triangle'" );
229251
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "offset", tr( "Offset" ), mLayer->dataDefinedPropertyString( "offset" ),
230252
QgsDataDefinedSymbolDialog::offsetHelpText() );
253+
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "horizontal_anchor_point", tr( "Horizontal anchor point" ), mLayer->dataDefinedPropertyString( "horizontal_anchor_point" ),
254+
QgsDataDefinedSymbolDialog::horizontalAnchorHelpText() );
255+
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "vertical_anchor_point", tr( "Vertical anchor point" ), mLayer->dataDefinedPropertyString( "vertical_anchor_point" ),
256+
QgsDataDefinedSymbolDialog::verticalAnchorHelpText() );
231257
QgsDataDefinedSymbolDialog d( dataDefinedProperties, mVectorLayer );
232258
if ( d.exec() == QDialog::Accepted )
233259
{

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ class GUI_EXPORT QgsEllipseSymbolLayerV2Widget: public QgsSymbolLayerV2Widget, p
5252
void on_mOutlineWidthUnitComboBox_currentIndexChanged( int index );
5353
void on_mSymbolHeightUnitComboBox_currentIndexChanged( int index );
5454
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
55-
55+
void on_mHorizontalAnchorComboBox_currentIndexChanged( int index );
56+
void on_mVerticalAnchorComboBox_currentIndexChanged( int index );
5657
void on_mDataDefinedPropertiesButton_clicked();
58+
5759
void setOffset();
5860
};
5961

‎src/ui/symbollayer/widget_ellipse.ui

Lines changed: 110 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,40 @@
77
<x>0</x>
88
<y>0</y>
99
<width>404</width>
10-
<height>504</height>
10+
<height>436</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
16-
<layout class="QGridLayout" name="gridLayout">
17-
<property name="margin">
18-
<number>1</number>
19-
</property>
16+
<layout class="QGridLayout" name="gridLayout_2">
2017
<item row="0" column="0">
21-
<layout class="QFormLayout" name="formLayout">
22-
<property name="fieldGrowthPolicy">
23-
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
24-
</property>
25-
<property name="labelAlignment">
26-
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
27-
</property>
28-
<property name="horizontalSpacing">
29-
<number>28</number>
30-
</property>
31-
<item row="1" column="0">
18+
<layout class="QGridLayout" name="gridLayout">
19+
<item row="0" column="0">
3220
<widget class="QLabel" name="label_2">
3321
<property name="text">
3422
<string>Colors</string>
3523
</property>
3624
</widget>
3725
</item>
38-
<item row="1" column="1">
26+
<item row="3" column="1">
27+
<widget class="QDoubleSpinBox" name="mRotationSpinBox"/>
28+
</item>
29+
<item row="4" column="0">
30+
<widget class="QLabel" name="mSymbolHeightLabel">
31+
<property name="text">
32+
<string>Symbol height</string>
33+
</property>
34+
</widget>
35+
</item>
36+
<item row="3" column="0">
37+
<widget class="QLabel" name="mRotationLabel">
38+
<property name="text">
39+
<string>Rotation</string>
40+
</property>
41+
</widget>
42+
</item>
43+
<item row="0" column="1">
3944
<layout class="QHBoxLayout" name="horizontalLayout_4">
4045
<item>
4146
<widget class="QLabel" name="label_3">
@@ -116,17 +121,10 @@
116121
</item>
117122
</layout>
118123
</item>
119-
<item row="2" column="0">
120-
<widget class="QLabel" name="mSymbolWidthLabel">
121-
<property name="text">
122-
<string>Symbol width</string>
123-
</property>
124-
</widget>
125-
</item>
126-
<item row="2" column="1">
127-
<layout class="QHBoxLayout" name="horizontalLayout">
124+
<item row="4" column="1">
125+
<layout class="QHBoxLayout" name="horizontalLayout_3">
128126
<item>
129-
<widget class="QDoubleSpinBox" name="mWidthSpinBox">
127+
<widget class="QDoubleSpinBox" name="mHeightSpinBox">
130128
<property name="sizePolicy">
131129
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
132130
<horstretch>1</horstretch>
@@ -142,7 +140,13 @@
142140
</widget>
143141
</item>
144142
<item>
145-
<widget class="QComboBox" name="mSymbolWidthUnitComboBox">
143+
<widget class="QComboBox" name="mSymbolHeightUnitComboBox">
144+
<property name="sizePolicy">
145+
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
146+
<horstretch>0</horstretch>
147+
<verstretch>0</verstretch>
148+
</sizepolicy>
149+
</property>
146150
<item>
147151
<property name="text">
148152
<string>Millimeter</string>
@@ -157,17 +161,10 @@
157161
</item>
158162
</layout>
159163
</item>
160-
<item row="3" column="0">
161-
<widget class="QLabel" name="mOutlineWidthLabel">
162-
<property name="text">
163-
<string>Outline width</string>
164-
</property>
165-
</widget>
166-
</item>
167-
<item row="3" column="1">
168-
<layout class="QHBoxLayout" name="horizontalLayout_2">
164+
<item row="1" column="1">
165+
<layout class="QHBoxLayout" name="horizontalLayout">
169166
<item>
170-
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox">
167+
<widget class="QDoubleSpinBox" name="mWidthSpinBox">
171168
<property name="sizePolicy">
172169
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
173170
<horstretch>1</horstretch>
@@ -183,7 +180,7 @@
183180
</widget>
184181
</item>
185182
<item>
186-
<widget class="QComboBox" name="mOutlineWidthUnitComboBox">
183+
<widget class="QComboBox" name="mSymbolWidthUnitComboBox">
187184
<item>
188185
<property name="text">
189186
<string>Millimeter</string>
@@ -198,27 +195,59 @@
198195
</item>
199196
</layout>
200197
</item>
201-
<item row="4" column="0">
202-
<widget class="QLabel" name="mRotationLabel">
198+
<item row="1" column="0">
199+
<widget class="QLabel" name="mSymbolWidthLabel">
203200
<property name="text">
204-
<string>Rotation</string>
201+
<string>Symbol width</string>
205202
</property>
206203
</widget>
207204
</item>
208-
<item row="4" column="1">
209-
<widget class="QDoubleSpinBox" name="mRotationSpinBox"/>
210-
</item>
211-
<item row="5" column="0">
212-
<widget class="QLabel" name="mSymbolHeightLabel">
213-
<property name="text">
214-
<string>Symbol height</string>
215-
</property>
216-
</widget>
205+
<item row="6" column="1">
206+
<layout class="QHBoxLayout" name="horizontalLayout_6">
207+
<item>
208+
<widget class="QComboBox" name="mHorizontalAnchorComboBox">
209+
<item>
210+
<property name="text">
211+
<string>Left</string>
212+
</property>
213+
</item>
214+
<item>
215+
<property name="text">
216+
<string>HCenter</string>
217+
</property>
218+
</item>
219+
<item>
220+
<property name="text">
221+
<string>Right</string>
222+
</property>
223+
</item>
224+
</widget>
225+
</item>
226+
<item>
227+
<widget class="QComboBox" name="mVerticalAnchorComboBox">
228+
<item>
229+
<property name="text">
230+
<string>Top</string>
231+
</property>
232+
</item>
233+
<item>
234+
<property name="text">
235+
<string>VCenter</string>
236+
</property>
237+
</item>
238+
<item>
239+
<property name="text">
240+
<string>Bottom</string>
241+
</property>
242+
</item>
243+
</widget>
244+
</item>
245+
</layout>
217246
</item>
218-
<item row="5" column="1">
219-
<layout class="QHBoxLayout" name="horizontalLayout_3">
247+
<item row="2" column="1">
248+
<layout class="QHBoxLayout" name="horizontalLayout_2">
220249
<item>
221-
<widget class="QDoubleSpinBox" name="mHeightSpinBox">
250+
<widget class="QDoubleSpinBox" name="mOutlineWidthSpinBox">
222251
<property name="sizePolicy">
223252
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
224253
<horstretch>1</horstretch>
@@ -234,13 +263,7 @@
234263
</widget>
235264
</item>
236265
<item>
237-
<widget class="QComboBox" name="mSymbolHeightUnitComboBox">
238-
<property name="sizePolicy">
239-
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
240-
<horstretch>0</horstretch>
241-
<verstretch>0</verstretch>
242-
</sizepolicy>
243-
</property>
266+
<widget class="QComboBox" name="mOutlineWidthUnitComboBox">
244267
<item>
245268
<property name="text">
246269
<string>Millimeter</string>
@@ -255,20 +278,28 @@
255278
</item>
256279
</layout>
257280
</item>
258-
<item row="7" column="0" colspan="2">
259-
<widget class="QPushButton" name="mDataDefinedPropertiesButton">
260-
<property name="sizePolicy">
261-
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
262-
<horstretch>0</horstretch>
263-
<verstretch>0</verstretch>
264-
</sizepolicy>
281+
<item row="2" column="0">
282+
<widget class="QLabel" name="mOutlineWidthLabel">
283+
<property name="text">
284+
<string>Outline width</string>
265285
</property>
286+
</widget>
287+
</item>
288+
<item row="6" column="0">
289+
<widget class="QLabel" name="mAnchorPointLabel">
266290
<property name="text">
267-
<string>Data defined properties...</string>
291+
<string>Anchor point</string>
268292
</property>
269293
</widget>
270294
</item>
271-
<item row="6" column="1">
295+
<item row="5" column="0">
296+
<widget class="QLabel" name="label_5">
297+
<property name="text">
298+
<string>Offset X,Y</string>
299+
</property>
300+
</widget>
301+
</item>
302+
<item row="5" column="1">
272303
<layout class="QHBoxLayout" name="horizontalLayout_5">
273304
<item>
274305
<widget class="QDoubleSpinBox" name="spinOffsetX">
@@ -318,10 +349,16 @@
318349
</item>
319350
</layout>
320351
</item>
321-
<item row="6" column="0">
322-
<widget class="QLabel" name="label_5">
352+
<item row="7" column="0" colspan="2">
353+
<widget class="QPushButton" name="mDataDefinedPropertiesButton">
354+
<property name="sizePolicy">
355+
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
356+
<horstretch>0</horstretch>
357+
<verstretch>0</verstretch>
358+
</sizepolicy>
359+
</property>
323360
<property name="text">
324-
<string>Offset X,Y</string>
361+
<string>Data defined properties...</string>
325362
</property>
326363
</widget>
327364
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.