Skip to content
Permalink
Browse files
[FEATURE] Font marker: possibility to set X,Y offset. Contributed by …
…Nathan Woodrow - thanks!

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14894 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Dec 12, 2010
1 parent e1acc7b commit e99e28da94155534b0fe9c60310953e258b4406d
@@ -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 )
@@ -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
@@ -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 )
{
@@ -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;
}
@@ -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" )
@@ -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()
@@ -828,6 +840,12 @@ void QgsFontMarkerSymbolLayerV2Widget::setCharacter( const QChar& chr )
emit changed();
}

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


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

@@ -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;
@@ -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">
@@ -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>

0 comments on commit e99e28d

Please sign in to comment.