Skip to content
Permalink
Browse files

Make Anchor points usable from ellipse symbol layer too

  • Loading branch information
mhugent committed Sep 23, 2013
1 parent 97ce0c2 commit 186b6bd51a15ef08b08fd90321c84d15d3246da9
@@ -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" ) )
@@ -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() )
@@ -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();
@@ -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;
}
@@ -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();
@@ -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;
}
}

@@ -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;
@@ -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 );
}

@@ -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()
@@ -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 )
{
@@ -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();
};

0 comments on commit 186b6bd

Please sign in to comment.
You can’t perform that action at this time.