Skip to content

Commit b163d05

Browse files
committedMar 10, 2013
Full support for width/offset/dash units in simple line symbollayer
1 parent 01734bd commit b163d05

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed
 

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
#include <cmath>
2727

2828
QgsSimpleLineSymbolLayerV2::QgsSimpleLineSymbolLayerV2( QColor color, double width, Qt::PenStyle penStyle )
29-
: mPenStyle( penStyle ), mPenJoinStyle( DEFAULT_SIMPLELINE_JOINSTYLE ), mPenCapStyle( DEFAULT_SIMPLELINE_CAPSTYLE ), mOffset( 0 ), mUseCustomDashPattern( false )
29+
: mPenStyle( penStyle ), mPenJoinStyle( DEFAULT_SIMPLELINE_JOINSTYLE ), mPenCapStyle( DEFAULT_SIMPLELINE_CAPSTYLE ), mOffset( 0 ), mOffsetUnit( QgsSymbolV2::MM ),
30+
mUseCustomDashPattern( false ), mCustomDashPatternUnit( QgsSymbolV2::MM )
3031
{
3132
mColor = color;
3233
mWidth = width;
@@ -66,8 +67,12 @@ QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::create( const QgsStringMap& props
6667

6768

6869
QgsSimpleLineSymbolLayerV2* l = new QgsSimpleLineSymbolLayerV2( color, width, penStyle );
70+
if ( props.contains( "width_unit" ) )
71+
l->setWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["width_unit"] ) );
6972
if ( props.contains( "offset" ) )
7073
l->setOffset( props["offset"].toDouble() );
74+
if ( props.contains( "offset_unit" ) )
75+
l->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit"] ) );
7176
if ( props.contains( "joinstyle" ) )
7277
l->setPenJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( props["joinstyle"] ) );
7378
if ( props.contains( "capstyle" ) )
@@ -81,6 +86,10 @@ QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::create( const QgsStringMap& props
8186
{
8287
l->setCustomDashVector( QgsSymbolLayerV2Utils::decodeRealVector( props["customdash"] ) );
8388
}
89+
if ( props.contains( "customdash_unit" ) )
90+
{
91+
l->setCustomDashPatternUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["customdash_unit"] ) );
92+
}
8493
return l;
8594
}
8695

@@ -162,12 +171,15 @@ QgsStringMap QgsSimpleLineSymbolLayerV2::properties() const
162171
QgsStringMap map;
163172
map["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
164173
map["width"] = QString::number( mWidth );
174+
map["width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mWidthUnit );
165175
map["penstyle"] = QgsSymbolLayerV2Utils::encodePenStyle( mPenStyle );
166176
map["joinstyle"] = QgsSymbolLayerV2Utils::encodePenJoinStyle( mPenJoinStyle );
167177
map["capstyle"] = QgsSymbolLayerV2Utils::encodePenCapStyle( mPenCapStyle );
168178
map["offset"] = QString::number( mOffset );
179+
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
169180
map["use_custom_dash"] = ( mUseCustomDashPattern ? "1" : "0" );
170181
map["customdash"] = QgsSymbolLayerV2Utils::encodeRealVector( mCustomDashVector );
182+
map["customdash_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mCustomDashPatternUnit );
171183
return map;
172184
}
173185

‎src/core/symbology-ng/qgssymbollayerv2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class CORE_EXPORT QgsSymbolLayerV2
6969
void setLocked( bool locked ) { mLocked = locked; }
7070
bool isLocked() const { return mLocked; }
7171

72-
virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit ) {} //= 0;
72+
virtual void setOutputUnit( QgsSymbolV2::OutputUnit unit ) { Q_UNUSED( unit ); } //= 0;
7373
virtual QgsSymbolV2::OutputUnit outputUnit() const { return QgsSymbolV2::Mixed; } //= 0;
7474

7575
// used only with rending with symbol levels is turned on (0 = first pass, 1 = second, ...)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,6 @@ QgsSymbolV2* QgsSymbolLayerV2Utils::loadSymbol( QDomElement& element )
739739
return NULL;
740740
}
741741

742-
symbol->setOutputUnit( decodeOutputUnit( element.attribute( "outputUnit" ) ) );
743742
symbol->setAlpha( element.attribute( "alpha", "1.0" ).toDouble() );
744743

745744
return symbol;

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ void QgsSimpleLineSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
7676
mOffsetUnitComboBox->blockSignals( true );
7777
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
7878
mOffsetUnitComboBox->blockSignals( false );
79+
mDashPatternUnitComboBox->blockSignals( true );
80+
mDashPatternUnitComboBox->setCurrentIndex( mLayer->customDashPatternUnit() );
81+
mDashPatternUnitComboBox->blockSignals( false );
7982

8083
// set values
8184
spinWidth->setValue( mLayer->width() );
@@ -185,6 +188,14 @@ void QgsSimpleLineSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChange
185188
}
186189
}
187190

191+
void QgsSimpleLineSymbolLayerV2Widget::on_mDashPatternUnitComboBox_currentIndexChanged( int index )
192+
{
193+
if ( mLayer )
194+
{
195+
mLayer->setCustomDashPatternUnit(( QgsSymbolV2::OutputUnit )index );
196+
}
197+
}
198+
188199
void QgsSimpleLineSymbolLayerV2Widget::updatePatternIcon()
189200
{
190201
if ( !mLayer )

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class GUI_EXPORT QgsSimpleLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widge
6969
void on_mChangePatternButton_clicked();
7070
void on_mPenWidthUnitComboBox_currentIndexChanged( int index );
7171
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
72+
void on_mDashPatternUnitComboBox_currentIndexChanged( int index );
7273

7374

7475
protected:

‎src/ui/symbollayer/widget_simpleline.ui

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>278</width>
10-
<height>195</height>
9+
<width>331</width>
10+
<height>235</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -143,21 +143,24 @@
143143
</property>
144144
</widget>
145145
</item>
146-
<item row="4" column="1" rowspan="2" colspan="2">
146+
<item row="4" column="1" colspan="2">
147147
<widget class="QgsPenJoinStyleComboBox" name="cboJoinStyle"/>
148148
</item>
149-
<item row="5" column="0" rowspan="2">
149+
<item row="5" column="0">
150150
<widget class="QLabel" name="label_6">
151151
<property name="text">
152152
<string>Cap style</string>
153153
</property>
154154
</widget>
155155
</item>
156-
<item row="6" column="1" colspan="2">
156+
<item row="5" column="1" colspan="2">
157157
<widget class="QgsPenCapStyleComboBox" name="cboCapStyle"/>
158158
</item>
159-
<item row="7" column="0" colspan="3">
159+
<item row="6" column="0" colspan="3">
160160
<layout class="QHBoxLayout" name="horizontalLayout">
161+
<property name="sizeConstraint">
162+
<enum>QLayout::SetFixedSize</enum>
163+
</property>
161164
<item>
162165
<widget class="QCheckBox" name="mCustomCheckBox">
163166
<property name="text">
@@ -174,6 +177,27 @@
174177
</item>
175178
</layout>
176179
</item>
180+
<item row="7" column="0">
181+
<widget class="QLabel" name="mDashPatternUnitLabel">
182+
<property name="text">
183+
<string>Dash pattern unit</string>
184+
</property>
185+
</widget>
186+
</item>
187+
<item row="7" column="1" colspan="2">
188+
<widget class="QComboBox" name="mDashPatternUnitComboBox">
189+
<item>
190+
<property name="text">
191+
<string>Millimeter</string>
192+
</property>
193+
</item>
194+
<item>
195+
<property name="text">
196+
<string>Map unit</string>
197+
</property>
198+
</item>
199+
</widget>
200+
</item>
177201
</layout>
178202
</widget>
179203
<customwidgets>

0 commit comments

Comments
 (0)
Please sign in to comment.