Skip to content

Commit

Permalink
[FEATURE] Font marker: possibility to set X,Y offset. Contributed by …
Browse files Browse the repository at this point in the history
…Nathan Woodrow - thanks!

git-svn-id: http://svn.osgeo.org/qgis/trunk@14894 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Dec 12, 2010
1 parent 63856ce commit fed9097
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ QgsFontMarkerSymbolLayerV2::QgsFontMarkerSymbolLayerV2( QString fontFamily, QCha
mColor = color;
mAngle = angle;
mSize = pointSize;
mOffset = QPointF( 0, 0 );
}

QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::create( const QgsStringMap& props )
Expand All @@ -663,7 +664,10 @@ QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::create( const QgsStringMap& props
if ( props.contains( "angle" ) )
angle = props["angle"].toDouble();

return new QgsFontMarkerSymbolLayerV2( fontFamily, chr, pointSize, color, angle );
QgsFontMarkerSymbolLayerV2* m = new QgsFontMarkerSymbolLayerV2( fontFamily, chr, pointSize, color, angle );
if ( props.contains( "offset" ) )
m->setOffset( QgsSymbolLayerV2Utils::decodePoint( props["offset"] ) );
return m;
}

QString QgsFontMarkerSymbolLayerV2::layerType() const
Expand Down Expand Up @@ -693,8 +697,10 @@ void QgsFontMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2R
p->setPen( penColor );
p->setFont( mFont );


p->save();
p->translate( point );
QPointF outputOffset = QPointF( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
p->translate( point + outputOffset );

if ( context.renderHints() & QgsSymbolV2::DataDefinedSizeScale )
{
Expand All @@ -717,10 +723,13 @@ QgsStringMap QgsFontMarkerSymbolLayerV2::properties() const
props["size"] = QString::number( mSize );
props["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
props["angle"] = QString::number( mAngle );
props["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
return props;
}

QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::clone() const
{
return new QgsFontMarkerSymbolLayerV2( mFontFamily, mChr, mSize, mColor, mAngle );
QgsFontMarkerSymbolLayerV2* m = new QgsFontMarkerSymbolLayerV2( mFontFamily, mChr, mSize, mColor, mAngle );
m->setOffset( mOffset );
return m;
}
18 changes: 18 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -769,9 +769,12 @@ QgsFontMarkerSymbolLayerV2Widget::QgsFontMarkerSymbolLayerV2Widget( QWidget* par
connect( spinSize, SIGNAL( valueChanged( double ) ), this, SLOT( setSize( double ) ) );
connect( btnColor, SIGNAL( clicked() ), this, SLOT( setColor() ) );
connect( spinAngle, SIGNAL( valueChanged( double ) ), this, SLOT( setAngle( double ) ) );
connect( spinOffsetX, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
connect( spinOffsetY, SIGNAL( valueChanged( double ) ), this, SLOT( setOffset() ) );
connect( widgetChar, SIGNAL( characterSelected( const QChar & ) ), this, SLOT( setCharacter( const QChar & ) ) );
}


void QgsFontMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
{
if ( layer->layerType() != "FontMarker" )
Expand All @@ -785,6 +788,15 @@ void QgsFontMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
spinSize->setValue( mLayer->size() );
btnColor->setColor( mLayer->color() );
spinAngle->setValue( mLayer->angle() );

//block
spinOffsetX->blockSignals( true );
spinOffsetX->setValue( mLayer->offset().x() );
spinOffsetX->blockSignals( false );
spinOffsetY->blockSignals( true );
spinOffsetY->setValue( mLayer->offset().y() );
spinOffsetY->blockSignals( false );

}

QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2Widget::symbolLayer()
Expand Down Expand Up @@ -828,6 +840,12 @@ void QgsFontMarkerSymbolLayerV2Widget::setCharacter( const QChar& chr )
emit changed();
}

void QgsFontMarkerSymbolLayerV2Widget::setOffset()
{
mLayer->setOffset( QPointF( spinOffsetX->value(), spinOffsetY->value() ) );
emit changed();
}


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

Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class GUI_EXPORT QgsFontMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widge
void setSize( double size );
void setAngle( double angle );
void setCharacter( const QChar& chr );
void setOffset();

protected:
QgsFontMarkerSymbolLayerV2* mLayer;
Expand Down
43 changes: 43 additions & 0 deletions src/ui/symbollayer/widget_fontmarker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="horizontalSpacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
Expand Down Expand Up @@ -74,6 +86,37 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Offset X,Y</string>
</property>
</widget>
</item>
<item row="4" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDoubleSpinBox" name="spinOffsetX">
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="spinOffsetY">
<property name="minimum">
<double>-100000.000000000000000</double>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit fed9097

Please sign in to comment.