Skip to content
Permalink
Browse files

Apply anchor point in svg marker symbollayer and widget

  • Loading branch information
mhugent committed Sep 17, 2013
1 parent a84b4a8 commit b525cfd71d37d9997dc5cc20bacd119292accc05
@@ -780,6 +780,15 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create( const QgsStringMap& props )
if ( props.contains( "outline_width_unit" ) )
m->setOutlineWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["outline_width_unit"] ) );

if ( props.contains( "horizontal_anchor_point" ) )
{
m->setHorizontalAnchorPoint( QgsMarkerSymbolLayerV2::HorizontalAnchorPoint( props[ "horizontal_anchor_point" ].toInt() ) );
}
if ( props.contains( "vertical_anchor_point" ) )
{
m->setVerticalAnchorPoint( QgsMarkerSymbolLayerV2::VerticalAnchorPoint( props[ "vertical_anchor_point" ].toInt() ) );
}

//data defined properties
if ( props.contains( "size_expression" ) )
{
@@ -887,15 +896,10 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re

p->save();

QPointF offset = mOffset;
QgsExpression* offsetExpression = expression( "offset" );
if ( offsetExpression )
{
QString offsetString = offsetExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString();
offset = QgsSymbolLayerV2Utils::decodePoint( offsetString );
}
double offsetX = offset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
double offsetY = offset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
//offset
double offsetX = 0;
double offsetY = 0;
markerOffset( context, offsetX, offsetY );
QPointF outputOffset( offsetX, offsetY );

double angle = mAngle;
@@ -1016,6 +1020,9 @@ QgsStringMap QgsSvgMarkerSymbolLayerV2::properties() const
map["outline"] = mOutlineColor.name();
map["outline-width"] = QString::number( mOutlineWidth );
map["outline_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOutlineWidthUnit );
map["horizontal_anchor_point"] = QString::number( mHorizontalAnchorPoint );
map["vertical_anchor_point"] = QString::number( mVerticalAnchorPoint );

saveDataDefinedProperties( map );
return map;
}
@@ -1030,6 +1037,8 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::clone() const
m->setOffset( mOffset );
m->setOffsetUnit( mOffsetUnit );
m->setSizeUnit( mSizeUnit );
m->setHorizontalAnchorPoint( mHorizontalAnchorPoint );
m->setVerticalAnchorPoint( mVerticalAnchorPoint );
copyDataDefinedProperties( m );
return m;
}
@@ -1012,6 +1012,15 @@ void QgsSvgMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
mOffsetUnitComboBox->blockSignals( true );
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
mOffsetUnitComboBox->blockSignals( false );

//anchor points
mHorizontalAnchorComboBox->blockSignals( true );
mVerticalAnchorComboBox->blockSignals( true );
mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
mHorizontalAnchorComboBox->blockSignals( false );
mVerticalAnchorComboBox->blockSignals( false );

setGuiForSvg( mLayer );
}

@@ -1195,6 +1204,24 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
}
}

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

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

/////////////

#include <QFileDialog>
@@ -222,6 +222,9 @@ class GUI_EXPORT QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget
void on_mBorderWidthUnitComboBox_currentIndexChanged( int index );
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
void on_mDataDefinedPropertiesButton_clicked();
void on_mHorizontalAnchorComboBox_currentIndexChanged( int index );
void on_mVerticalAnchorComboBox_currentIndexChanged( int index );


protected:

0 comments on commit b525cfd

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