Skip to content

Commit

Permalink
Implement anchor point shift and expose in simple marker dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Sep 17, 2013
1 parent bc95d0b commit a84b4a8
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 239 deletions.
13 changes: 13 additions & 0 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Expand Up @@ -85,6 +85,15 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create( const QgsStringMap& prop
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( "name_expression" ) )
{
Expand Down Expand Up @@ -546,6 +555,8 @@ QgsStringMap QgsSimpleMarkerSymbolLayerV2::properties() const
map["scale_method"] = QgsSymbolLayerV2Utils::encodeScaleMethod( mScaleMethod );
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 );

//data define properties
saveDataDefinedProperties( map );
Expand All @@ -560,6 +571,8 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::clone() const
m->setOffsetUnit( mOffsetUnit );
m->setOutlineWidth( mOutlineWidth );
m->setOutlineWidthUnit( mOutlineWidthUnit );
m->setHorizontalAnchorPoint( mHorizontalAnchorPoint );
m->setVerticalAnchorPoint( mVerticalAnchorPoint );
copyDataDefinedProperties( m );
return m;
}
Expand Down
27 changes: 23 additions & 4 deletions src/core/symbology-ng/qgssymbollayerv2.cpp
Expand Up @@ -148,7 +148,8 @@ void QgsSymbolLayerV2::copyDataDefinedProperties( QgsSymbolLayerV2* destLayer )


QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked )
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked ), mSizeUnit( QgsSymbolV2::MM ), mOffsetUnit( QgsSymbolV2::MM )
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked ), mSizeUnit( QgsSymbolV2::MM ), mOffsetUnit( QgsSymbolV2::MM ),
mHorizontalAnchorPoint( HCenter ), mVerticalAnchorPoint( VCenter )
{
}

Expand Down Expand Up @@ -191,13 +192,31 @@ void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, do
offsetX *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
offsetY *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );

//consider anchor point corrections
if( mHorizontalAnchorPoint == HCenter && mVerticalAnchorPoint == VCenter )
//correct horizontal position according to anchor point
if ( mHorizontalAnchorPoint == HCenter && mVerticalAnchorPoint == VCenter )
{
return;
return;
}

double anchorPointCorrection = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit ) / 2.0;
if ( mHorizontalAnchorPoint == Left )
{
offsetX += anchorPointCorrection;
}
else if ( mHorizontalAnchorPoint == Right )
{
offsetX -= anchorPointCorrection;
}

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

QPointF QgsMarkerSymbolLayerV2::_rotatedOffset( const QPointF& offset, double angle )
Expand Down
18 changes: 12 additions & 6 deletions src/core/symbology-ng/qgssymbollayerv2.h
Expand Up @@ -124,16 +124,16 @@ class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2

enum HorizontalAnchorPoint
{
Left,
HCenter,
Right
Left,
HCenter,
Right
};

enum VerticalAnchorPoint
{
Top,
VCenter,
Bottom
Top,
VCenter,
Bottom
};

virtual void renderPoint( const QPointF& point, QgsSymbolV2RenderContext& context ) = 0;
Expand Down Expand Up @@ -166,6 +166,12 @@ class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit );
virtual QgsSymbolV2::OutputUnit outputUnit() const;

void setHorizontalAnchorPoint( HorizontalAnchorPoint h ) { mHorizontalAnchorPoint = h; }
HorizontalAnchorPoint horizontalAnchorPoint() const { return mHorizontalAnchorPoint; }

void setVerticalAnchorPoint( VerticalAnchorPoint v ) { mVerticalAnchorPoint = v; }
VerticalAnchorPoint verticalAnchorPoint() const { return mVerticalAnchorPoint; }

protected:
QgsMarkerSymbolLayerV2( bool locked = false );
//handles marker offset and anchor point shift together
Expand Down
26 changes: 26 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -320,6 +320,14 @@ void QgsSimpleMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer
mOutlineWidthUnitComboBox->blockSignals( true );
mOutlineWidthUnitComboBox->setCurrentIndex( mLayer->outlineWidthUnit() );
mOutlineWidthUnitComboBox->blockSignals( false );

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

QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2Widget::symbolLayer()
Expand Down Expand Up @@ -440,6 +448,24 @@ void QgsSimpleMarkerSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked
}
}

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

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


///////////

Expand Down
2 changes: 2 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -110,6 +110,8 @@ class GUI_EXPORT QgsSimpleMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Wid
void on_mOutlineWidthUnitComboBox_currentIndexChanged( int index );
void on_mDataDefinedPropertiesButton_clicked();
void on_mOutlineWidthSpinBox_valueChanged( double d );
void on_mHorizontalAnchorComboBox_currentIndexChanged( int index );
void on_mVerticalAnchorComboBox_currentIndexChanged( int index );

protected:
QgsSimpleMarkerSymbolLayerV2* mLayer;
Expand Down

0 comments on commit a84b4a8

Please sign in to comment.