Skip to content

Commit 03cfba7

Browse files
committedSep 19, 2013
Anchor points for font marker
1 parent b525cfd commit 03cfba7

File tree

4 files changed

+99
-29
lines changed

4 files changed

+99
-29
lines changed
 

‎src/core/symbology-ng/qgsmarkersymbollayerv2.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,14 @@ QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::create( const QgsStringMap& props
11671167
m->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit" ] ) );
11681168
if ( props.contains( "size_unit" ) )
11691169
m->setSizeUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["size_unit"] ) );
1170+
if ( props.contains( "horizontal_anchor_point" ) )
1171+
{
1172+
m->setHorizontalAnchorPoint( QgsMarkerSymbolLayerV2::HorizontalAnchorPoint( props[ "horizontal_anchor_point" ].toInt() ) );
1173+
}
1174+
if ( props.contains( "vertical_anchor_point" ) )
1175+
{
1176+
m->setVerticalAnchorPoint( QgsMarkerSymbolLayerV2::VerticalAnchorPoint( props[ "vertical_anchor_point" ].toInt() ) );
1177+
}
11701178
return m;
11711179
}
11721180

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

12041212
p->save();
1205-
double offsetX = mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
1206-
double offsetY = mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
1213+
//offset
1214+
double offsetX = 0;
1215+
double offsetY = 0;
1216+
markerOffset( context, offsetX, offsetY );
12071217
QPointF outputOffset( offsetX, offsetY );
12081218
if ( mAngle )
12091219
outputOffset = _rotatedOffset( outputOffset, mAngle );
@@ -1233,6 +1243,8 @@ QgsStringMap QgsFontMarkerSymbolLayerV2::properties() const
12331243
props["angle"] = QString::number( mAngle );
12341244
props["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
12351245
props["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
1246+
props["horizontal_anchor_point"] = QString::number( mHorizontalAnchorPoint );
1247+
props["vertical_anchor_point"] = QString::number( mVerticalAnchorPoint );
12361248
return props;
12371249
}
12381250

@@ -1242,6 +1254,8 @@ QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::clone() const
12421254
m->setOffset( mOffset );
12431255
m->setOffsetUnit( mOffsetUnit );
12441256
m->setSizeUnit( mSizeUnit );
1257+
m->setHorizontalAnchorPoint( mHorizontalAnchorPoint );
1258+
m->setVerticalAnchorPoint( mVerticalAnchorPoint );
12451259
return m;
12461260
}
12471261

‎src/gui/symbology-ng/qgssymbollayerv2widget.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,14 @@ void QgsFontMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
18351835
mOffsetUnitComboBox->blockSignals( true );
18361836
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
18371837
mOffsetUnitComboBox->blockSignals( false );
1838+
1839+
//anchor points
1840+
mHorizontalAnchorComboBox->blockSignals( true );
1841+
mVerticalAnchorComboBox->blockSignals( true );
1842+
mHorizontalAnchorComboBox->setCurrentIndex( mLayer->horizontalAnchorPoint() );
1843+
mVerticalAnchorComboBox->setCurrentIndex( mLayer->verticalAnchorPoint() );
1844+
mHorizontalAnchorComboBox->blockSignals( false );
1845+
mVerticalAnchorComboBox->blockSignals( false );
18381846
}
18391847

18401848
QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2Widget::symbolLayer()
@@ -1898,6 +1906,24 @@ void QgsFontMarkerSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChange
18981906
emit changed();
18991907
}
19001908

1909+
void QgsFontMarkerSymbolLayerV2Widget::on_mHorizontalAnchorComboBox_currentIndexChanged( int index )
1910+
{
1911+
if ( mLayer )
1912+
{
1913+
mLayer->setHorizontalAnchorPoint( QgsMarkerSymbolLayerV2::HorizontalAnchorPoint( index ) );
1914+
emit changed();
1915+
}
1916+
}
1917+
1918+
void QgsFontMarkerSymbolLayerV2Widget::on_mVerticalAnchorComboBox_currentIndexChanged( int index )
1919+
{
1920+
if ( mLayer )
1921+
{
1922+
mLayer->setVerticalAnchorPoint( QgsMarkerSymbolLayerV2::VerticalAnchorPoint( index ) );
1923+
emit changed();
1924+
}
1925+
}
1926+
19011927

19021928
///////////////
19031929

‎src/gui/symbology-ng/qgssymbollayerv2widget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ class GUI_EXPORT QgsFontMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widge
370370
void setOffset();
371371
void on_mSizeUnitComboBox_currentIndexChanged( int index );
372372
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
373+
void on_mHorizontalAnchorComboBox_currentIndexChanged( int index );
374+
void on_mVerticalAnchorComboBox_currentIndexChanged( int index );
373375

374376
protected:
375377
QgsFontMarkerSymbolLayerV2* mLayer;

‎src/ui/symbollayer/widget_fontmarker.ui

Lines changed: 55 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,16 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>541</width>
10-
<height>559</height>
9+
<width>406</width>
10+
<height>354</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Form</string>
1515
</property>
16-
<layout class="QVBoxLayout" name="verticalLayout">
17-
<property name="margin">
18-
<number>1</number>
19-
</property>
20-
<item>
21-
<layout class="QFormLayout" name="formLayout">
22-
<property name="sizeConstraint">
23-
<enum>QLayout::SetDefaultConstraint</enum>
24-
</property>
25-
<property name="fieldGrowthPolicy">
26-
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
27-
</property>
28-
<property name="labelAlignment">
29-
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
30-
</property>
31-
<property name="horizontalSpacing">
32-
<number>28</number>
33-
</property>
34-
<property name="leftMargin">
35-
<number>0</number>
36-
</property>
37-
<property name="topMargin">
38-
<number>0</number>
39-
</property>
16+
<layout class="QGridLayout" name="gridLayout_2">
17+
<item row="0" column="0">
18+
<layout class="QGridLayout" name="gridLayout">
4019
<item row="0" column="0">
4120
<widget class="QLabel" name="label">
4221
<property name="text">
@@ -200,9 +179,58 @@
200179
</item>
201180
</layout>
202181
</item>
182+
<item row="5" column="0">
183+
<widget class="QLabel" name="mAnchorPointLabel">
184+
<property name="text">
185+
<string>Anchor point</string>
186+
</property>
187+
</widget>
188+
</item>
189+
<item row="5" column="1">
190+
<layout class="QHBoxLayout" name="horizontalLayout_6">
191+
<item>
192+
<widget class="QComboBox" name="mHorizontalAnchorComboBox">
193+
<item>
194+
<property name="text">
195+
<string>Left</string>
196+
</property>
197+
</item>
198+
<item>
199+
<property name="text">
200+
<string>HCenter</string>
201+
</property>
202+
</item>
203+
<item>
204+
<property name="text">
205+
<string>Right</string>
206+
</property>
207+
</item>
208+
</widget>
209+
</item>
210+
<item>
211+
<widget class="QComboBox" name="mVerticalAnchorComboBox">
212+
<item>
213+
<property name="text">
214+
<string>Top</string>
215+
</property>
216+
</item>
217+
<item>
218+
<property name="text">
219+
<string>VCenter</string>
220+
</property>
221+
</item>
222+
<item>
223+
<property name="text">
224+
<string>Bottom</string>
225+
</property>
226+
</item>
227+
</widget>
228+
</item>
229+
</layout>
230+
</item>
203231
</layout>
204232
</item>
205-
<item>
233+
<item row="1" column="0">
206234
<widget class="QScrollArea" name="scrollArea">
207235
<widget class="QWidget" name="scrollAreaWidgetContents">
208236
<property name="geometry">

0 commit comments

Comments
 (0)
Please sign in to comment.