Skip to content

Commit 186b6bd

Browse files
committed
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

+19-1
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

+13-5
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

+3
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

+26
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

+3-1
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

0 commit comments

Comments
 (0)