Skip to content
Permalink
Browse files

More data defined anchor points

  • Loading branch information
mhugent committed Sep 20, 2013
1 parent 03cfba7 commit dec8953b1897d16c8058959786475f75f36149f9
@@ -123,6 +123,14 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::create( const QgsStringMap& prop
{
m->setDataDefinedProperty( "offset", props["offset_expression"] );
}
if ( props.contains( "horizontal_anchor_point_expression" ) )
{
m->setDataDefinedProperty( "horizontal_anchor_point", props[ "horizontal_anchor_point_expression" ] );
}
if ( props.contains( "vertical_anchor_point_expression" ) )
{
m->setDataDefinedProperty( "vertical_anchor_point", props[ "vertical_anchor_point_expression" ] );
}
return m;
}

@@ -818,6 +826,14 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create( const QgsStringMap& props )
{
m->setDataDefinedProperty( "outline", props["outline_expression"] );
}
if ( props.contains( "horizontal_anchor_point_expression" ) )
{
m->setDataDefinedProperty( "horizontal_anchor_point", props[ "horizontal_anchor_point_expression" ] );
}
if ( props.contains( "vertical_anchor_point_expression" ) )
{
m->setDataDefinedProperty( "vertical_anchor_point", props[ "vertical_anchor_point_expression" ] );
}
return m;
}

@@ -192,28 +192,41 @@ void QgsMarkerSymbolLayerV2::markerOffset( QgsSymbolV2RenderContext& context, do
offsetX *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
offsetY *= QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );

HorizontalAnchorPoint horizontalAnchorPoint = mHorizontalAnchorPoint;
VerticalAnchorPoint verticalAnchorPoint = mVerticalAnchorPoint;
QgsExpression* horizontalAnchorExpression = expression( "horizontal_anchor_point" );
if ( horizontalAnchorExpression )
{
horizontalAnchorPoint = decodeHorizontalAnchorPoint( horizontalAnchorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
}
QgsExpression* verticalAnchorExpression = expression( "vertical_anchor_point" );
if ( verticalAnchorExpression )
{
verticalAnchorPoint = decodeVerticalAnchorPoint( verticalAnchorExpression->evaluate( const_cast<QgsFeature*>( context.feature() ) ).toString() );
}

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

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

//correct vertical position according to anchor point
if ( mVerticalAnchorPoint == Top )
if ( verticalAnchorPoint == Top )
{
offsetY += anchorPointCorrection;
}
else if ( mVerticalAnchorPoint == Bottom )
else if ( verticalAnchorPoint == Bottom )
{
offsetY -= anchorPointCorrection;
}
@@ -226,6 +239,38 @@ QPointF QgsMarkerSymbolLayerV2::_rotatedOffset( const QPointF& offset, double an
return QPointF( offset.x() * c - offset.y() * s, offset.x() * s + offset.y() * c );
}

QgsMarkerSymbolLayerV2::HorizontalAnchorPoint QgsMarkerSymbolLayerV2::decodeHorizontalAnchorPoint( const QString& str )
{
if ( str.compare( "left", Qt::CaseInsensitive ) == 0 )
{
return QgsMarkerSymbolLayerV2::Left;
}
else if ( str.compare( "right", Qt::CaseInsensitive ) == 0 )
{
return QgsMarkerSymbolLayerV2::Right;
}
else
{
return QgsMarkerSymbolLayerV2::HCenter;
}
}

QgsMarkerSymbolLayerV2::VerticalAnchorPoint QgsMarkerSymbolLayerV2::decodeVerticalAnchorPoint( const QString& str )
{
if ( str.compare( "top", Qt::CaseInsensitive ) == 0 )
{
return QgsMarkerSymbolLayerV2::Top;
}
else if ( str.compare( "bottom", Qt::CaseInsensitive ) == 0 )
{
return QgsMarkerSymbolLayerV2::Bottom;
}
else
{
return QgsMarkerSymbolLayerV2::VCenter;
}
}

QgsSymbolV2::OutputUnit QgsMarkerSymbolLayerV2::outputUnit() const
{
QgsSymbolV2::OutputUnit unit = mSizeUnit;
@@ -186,6 +186,10 @@ class CORE_EXPORT QgsMarkerSymbolLayerV2 : public QgsSymbolLayerV2
QgsSymbolV2::ScaleMethod mScaleMethod;
HorizontalAnchorPoint mHorizontalAnchorPoint;
VerticalAnchorPoint mVerticalAnchorPoint;

private:
static QgsMarkerSymbolLayerV2::HorizontalAnchorPoint decodeHorizontalAnchorPoint( const QString& str );
static QgsMarkerSymbolLayerV2::VerticalAnchorPoint decodeVerticalAnchorPoint( const QString& str );
};

class CORE_EXPORT QgsLineSymbolLayerV2 : public QgsSymbolLayerV2
@@ -182,3 +182,13 @@ QString QgsDataDefinedSymbolDialog::fileNameHelpText()
{
return tr( "'<filename>'" );
}

QString QgsDataDefinedSymbolDialog::horizontalAnchorHelpText()
{
return tr( "'left'|'hcenter'|'right'" );
}

QString QgsDataDefinedSymbolDialog::verticalAnchorHelpText()
{
return tr( "'top'|'vcenter'|'bottom'" );
}
@@ -33,6 +33,8 @@ class GUI_EXPORT QgsDataDefinedSymbolDialog: public QDialog, private Ui::QgsData
static QString colorHelpText();
static QString offsetHelpText();
static QString fileNameHelpText();
static QString horizontalAnchorHelpText();
static QString verticalAnchorHelpText();

private slots:
void expressionButtonClicked();
@@ -429,6 +429,10 @@ void QgsSimpleMarkerSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked
QgsDataDefinedSymbolDialog::doubleHelpText() );
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 )
{
@@ -588,6 +592,10 @@ void QgsSimpleFillSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
QgsDataDefinedSymbolDialog::colorHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "width_border", tr( "Border width" ), mLayer->dataDefinedPropertyString( "width_border" ),
QgsDataDefinedSymbolDialog::doubleHelpText() );
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 )
{
@@ -1185,6 +1193,10 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mDataDefinedPropertiesButton_clicked()
QgsDataDefinedSymbolDialog::colorHelpText() );
dataDefinedProperties << QgsDataDefinedSymbolDialog::DataDefinedSymbolEntry( "outline", tr( "Border color" ), mLayer->dataDefinedPropertyString( "outline" ),
QgsDataDefinedSymbolDialog::colorHelpText() );
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 )
{

0 comments on commit dec8953

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