Skip to content

Commit

Permalink
Anchor points for font marker
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Sep 19, 2013
1 parent b525cfd commit 03cfba7
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 29 deletions.
18 changes: 16 additions & 2 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1167,6 +1167,14 @@ QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::create( const QgsStringMap& props
m->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit" ] ) ); m->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit" ] ) );
if ( props.contains( "size_unit" ) ) if ( props.contains( "size_unit" ) )
m->setSizeUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["size_unit"] ) ); m->setSizeUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["size_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() ) );
}
return m; return m;
} }


Expand Down Expand Up @@ -1202,8 +1210,10 @@ void QgsFontMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2R
p->setFont( mFont ); p->setFont( mFont );


p->save(); p->save();
double offsetX = mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit ); //offset
double offsetY = mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit ); double offsetX = 0;
double offsetY = 0;
markerOffset( context, offsetX, offsetY );
QPointF outputOffset( offsetX, offsetY ); QPointF outputOffset( offsetX, offsetY );
if ( mAngle ) if ( mAngle )
outputOffset = _rotatedOffset( outputOffset, mAngle ); outputOffset = _rotatedOffset( outputOffset, mAngle );
Expand Down Expand Up @@ -1233,6 +1243,8 @@ QgsStringMap QgsFontMarkerSymbolLayerV2::properties() const
props["angle"] = QString::number( mAngle ); props["angle"] = QString::number( mAngle );
props["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset ); props["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
props["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit ); props["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
props["horizontal_anchor_point"] = QString::number( mHorizontalAnchorPoint );
props["vertical_anchor_point"] = QString::number( mVerticalAnchorPoint );
return props; return props;
} }


Expand All @@ -1242,6 +1254,8 @@ QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::clone() const
m->setOffset( mOffset ); m->setOffset( mOffset );
m->setOffsetUnit( mOffsetUnit ); m->setOffsetUnit( mOffsetUnit );
m->setSizeUnit( mSizeUnit ); m->setSizeUnit( mSizeUnit );
m->setHorizontalAnchorPoint( mHorizontalAnchorPoint );
m->setVerticalAnchorPoint( mVerticalAnchorPoint );
return m; return m;
} }


Expand Down
26 changes: 26 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1835,6 +1835,14 @@ void QgsFontMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
mOffsetUnitComboBox->blockSignals( true ); mOffsetUnitComboBox->blockSignals( true );
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() ); mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
mOffsetUnitComboBox->blockSignals( false ); 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 );
} }


QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2Widget::symbolLayer() QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2Widget::symbolLayer()
Expand Down Expand Up @@ -1898,6 +1906,24 @@ void QgsFontMarkerSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChange
emit changed(); emit changed();
} }


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

void QgsFontMarkerSymbolLayerV2Widget::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
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ class GUI_EXPORT QgsFontMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widge
void setOffset(); void setOffset();
void on_mSizeUnitComboBox_currentIndexChanged( int index ); void on_mSizeUnitComboBox_currentIndexChanged( int index );
void on_mOffsetUnitComboBox_currentIndexChanged( int index ); void on_mOffsetUnitComboBox_currentIndexChanged( int index );
void on_mHorizontalAnchorComboBox_currentIndexChanged( int index );
void on_mVerticalAnchorComboBox_currentIndexChanged( int index );


protected: protected:
QgsFontMarkerSymbolLayerV2* mLayer; QgsFontMarkerSymbolLayerV2* mLayer;
Expand Down
82 changes: 55 additions & 27 deletions src/ui/symbollayer/widget_fontmarker.ui
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,37 +6,16 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>541</width> <width>406</width>
<height>559</height> <height>354</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string>Form</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QGridLayout" name="gridLayout_2">
<property name="margin"> <item row="0" column="0">
<number>1</number> <layout class="QGridLayout" name="gridLayout">
</property>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="horizontalSpacing">
<number>28</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
Expand Down Expand Up @@ -200,9 +179,58 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="5" column="0">
<widget class="QLabel" name="mAnchorPointLabel">
<property name="text">
<string>Anchor point</string>
</property>
</widget>
</item>
<item row="5" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="mHorizontalAnchorComboBox">
<item>
<property name="text">
<string>Left</string>
</property>
</item>
<item>
<property name="text">
<string>HCenter</string>
</property>
</item>
<item>
<property name="text">
<string>Right</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="mVerticalAnchorComboBox">
<item>
<property name="text">
<string>Top</string>
</property>
</item>
<item>
<property name="text">
<string>VCenter</string>
</property>
</item>
<item>
<property name="text">
<string>Bottom</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
<item> <item row="1" column="0">
<widget class="QScrollArea" name="scrollArea"> <widget class="QScrollArea" name="scrollArea">
<widget class="QWidget" name="scrollAreaWidgetContents"> <widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry"> <property name="geometry">
Expand Down

0 comments on commit 03cfba7

Please sign in to comment.