Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make Anchor points usable from ellipse symbol layer too
  • Loading branch information
mhugent committed Sep 23, 2013
1 parent 97ce0c2 commit 186b6bd
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 80 deletions.
20 changes: 19 additions & 1 deletion src/core/symbology-ng/qgsellipsesymbollayerv2.cpp
Expand Up @@ -92,6 +92,14 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
{
layer->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["offset_unit"] ) );
}
if ( properties.contains( "horizontal_anchor_point" ) )
{
layer->setHorizontalAnchorPoint( QgsMarkerSymbolLayerV2::HorizontalAnchorPoint( properties[ "horizontal_anchor_point" ].toInt() ) );
}
if ( properties.contains( "vertical_anchor_point" ) )
{
layer->setVerticalAnchorPoint( QgsMarkerSymbolLayerV2::VerticalAnchorPoint( properties[ "vertical_anchor_point" ].toInt() ) );
}

//data defined properties
if ( properties.contains( "width_expression" ) )
Expand Down Expand Up @@ -126,6 +134,14 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::create( const QgsStringMap& propertie
{
layer->setDataDefinedProperty( "offset", properties["offset_expression"] );
}
if ( properties.contains( "horizontal_anchor_point_expression" ) )
{
layer->setDataDefinedProperty( "horizontal_anchor_point", properties[ "horizontal_anchor_point_expression" ] );
}
if ( properties.contains( "vertical_anchor_point_expression" ) )
{
layer->setDataDefinedProperty( "vertical_anchor_point", properties[ "vertical_anchor_point_expression" ] );
}

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

QPainter* p = context.renderContext().painter();
Expand Down Expand Up @@ -385,6 +401,8 @@ QgsStringMap QgsEllipseSymbolLayerV2::properties() const
map["outline_color"] = QgsSymbolLayerV2Utils::encodeColor( mOutlineColor );
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
map["horizontal_anchor_point"] = QString::number( mHorizontalAnchorPoint );
map["vertical_anchor_point"] = QString::number( mVerticalAnchorPoint );
saveDataDefinedProperties( map );
return map;
}
Expand Down
18 changes: 13 additions & 5 deletions src/core/symbology-ng/qgssymbollayerv2.cpp
Expand Up @@ -177,6 +177,13 @@ void QgsMarkerSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
}

void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY )
{
markerOffset( context, mSize, mSize, mSizeUnit, mSizeUnit, offsetX, offsetY );
}

void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, double width, double height,
QgsSymbolV2::OutputUnit widthUnit, QgsSymbolV2::OutputUnit heightUnit,
double& offsetX, double& offsetY )
{
offsetX = mOffset.x();
offsetY = mOffset.y();
Expand Down Expand Up @@ -211,24 +218,25 @@ void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, do
return;
}

double anchorPointCorrection = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit ) / 2.0;
double anchorPointCorrectionX = width * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), widthUnit ) / 2.0;
double anchorPointCorrectionY = height * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), heightUnit ) / 2.0;
if ( horizontalAnchorPoint == Left )
{
offsetX += anchorPointCorrection;
offsetX += anchorPointCorrectionX;
}
else if ( horizontalAnchorPoint == Right )
{
offsetX -= anchorPointCorrection;
offsetX -= anchorPointCorrectionX;
}

//correct vertical position according to anchor point
if ( verticalAnchorPoint == Top )
{
offsetY += anchorPointCorrection;
offsetY += anchorPointCorrectionY;
}
else if ( verticalAnchorPoint == Bottom )
{
offsetY -= anchorPointCorrection;
offsetY -= anchorPointCorrectionY;
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2.h
Expand Up @@ -176,6 +176,9 @@ class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
QgsMarkerSymbolLayerV2( bool locked = false );
//handles marker offset and anchor point shift together
void markerOffset( QgsSymbolV2RenderContext& context, double& offsetX, double& offsetY );
void markerOffset( QgsSymbolV2RenderContext& context, double width, double height,
QgsSymbolV2::OutputUnit widthUnit, QgsSymbolV2::OutputUnit heightUnit,
double& offsetX, double& offsetY );
static QPointF _rotatedOffset( const QPointF& offset, double angle );

double mAngle;
Expand Down
26 changes: 26 additions & 0 deletions src/gui/symbology-ng/qgsellipsesymbollayerv2widget.cpp
Expand Up @@ -82,6 +82,8 @@ void QgsEllipseSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
QPointF offsetPt = mLayer->offset();
spinOffsetX->setValue( offsetPt.x() );
spinOffsetY->setValue( offsetPt.y() );
mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
blockComboSignals( false );
}

Expand Down Expand Up @@ -202,6 +204,26 @@ void QgsEllipseSymbolLayerV2Widget::blockComboSignals( bool block )
mSymbolWidthUnitComboBox->blockSignals( block );
mOutlineWidthUnitComboBox->blockSignals( block );
mSymbolHeightUnitComboBox->blockSignals( block );
mHorizontalAnchorComboBox->blockSignals( block );
mVerticalAnchorComboBox->blockSignals( block );
}

void QgsEllipseSymbolLayerV2Widget::on_mHorizontalAnchorComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setHorizontalAnchorPoint(( QgsMarkerSymbolLayerV2::HorizontalAnchorPoint ) index );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mVerticalAnchorComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setVerticalAnchorPoint(( QgsMarkerSymbolLayerV2::VerticalAnchorPoint ) index );
emit changed();
}
}

void QgsEllipseSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
Expand All @@ -228,6 +250,10 @@ void QgsEllipseSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
"'circle'|'rectangle'|'cross'|'triangle'" );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "offset", tr( "Offset" ), mLayer->dataDefinedPropertyString( "offset" ),
QgsDataDefinedSymbolDialog::offsetHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "horizontal_anchor_point", tr( "Horizontal anchor point" ), mLayer->dataDefinedPropertyString( "horizontal_anchor_point" ),
QgsDataDefinedSymbolDialog::horizontalAnchorHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "vertical_anchor_point", tr( "Vertical anchor point" ), mLayer->dataDefinedPropertyString( "vertical_anchor_point" ),
QgsDataDefinedSymbolDialog::verticalAnchorHelpText() );
QgsDataDefinedSymbolDialog d( dataDefinedProperties, mVectorLayer );
if ( d.exec() == QDialog::Accepted )
{
Expand Down
4 changes: 3 additions & 1 deletion src/gui/symbology-ng/qgsellipsesymbollayerv2widget.h
Expand Up @@ -52,8 +52,10 @@ class GUI_EXPORT QgsEllipseSymbolLayerV2Widget: public QgsSymbolLayerV2Widget, p
void on_mOutlineWidthUnitComboBox_currentIndexChanged( int index );
void on_mSymbolHeightUnitComboBox_currentIndexChanged( int index );
void on_mOffsetUnitComboBox_currentIndexChanged( int index );

void on_mHorizontalAnchorComboBox_currentIndexChanged( int index );
void on_mVerticalAnchorComboBox_currentIndexChanged( int index );
void on_mDataDefinedPropertiesButton_clicked();

void setOffset();
};

Expand Down

0 comments on commit 186b6bd

Please sign in to comment.