Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Full support for width/offset/dash units in simple line symbollayer
  • Loading branch information
mhugent committed Mar 10, 2013
1 parent 01734bd commit b163d05
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 9 deletions.
14 changes: 13 additions & 1 deletion src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -26,7 +26,8 @@
#include <cmath>

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


QgsSimpleLineSymbolLayerV2* l = new QgsSimpleLineSymbolLayerV2( color, width, penStyle );
if ( props.contains( "width_unit" ) )
l->setWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["width_unit"] ) );
if ( props.contains( "offset" ) )
l->setOffset( props["offset"].toDouble() );
if ( props.contains( "offset_unit" ) )
l->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit"] ) );
if ( props.contains( "joinstyle" ) )
l->setPenJoinStyle( QgsSymbolLayerV2Utils::decodePenJoinStyle( props["joinstyle"] ) );
if ( props.contains( "capstyle" ) )
Expand All @@ -81,6 +86,10 @@ QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::create( const QgsStringMap& props
{
l->setCustomDashVector( QgsSymbolLayerV2Utils::decodeRealVector( props["customdash"] ) );
}
if ( props.contains( "customdash_unit" ) )
{
l->setCustomDashPatternUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["customdash_unit"] ) );
}
return l;
}

Expand Down Expand Up @@ -162,12 +171,15 @@ QgsStringMap QgsSimpleLineSymbolLayerV2::properties() const
QgsStringMap map;
map["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
map["width"] = QString::number( mWidth );
map["width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mWidthUnit );
map["penstyle"] = QgsSymbolLayerV2Utils::encodePenStyle( mPenStyle );
map["joinstyle"] = QgsSymbolLayerV2Utils::encodePenJoinStyle( mPenJoinStyle );
map["capstyle"] = QgsSymbolLayerV2Utils::encodePenCapStyle( mPenCapStyle );
map["offset"] = QString::number( mOffset );
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
map["use_custom_dash"] = ( mUseCustomDashPattern ? "1" : "0" );
map["customdash"] = QgsSymbolLayerV2Utils::encodeRealVector( mCustomDashVector );
map["customdash_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mCustomDashPatternUnit );
return map;
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbollayerv2.h
Expand Up @@ -69,7 +69,7 @@ class CORE_EXPORT QgsSymbolLayerV2
void setLocked( bool locked ) { mLocked = locked; }
bool isLocked() const { return mLocked; }

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

// used only with rending with symbol levels is turned on (0 = first pass, 1 = second, ...)
Expand Down
1 change: 0 additions & 1 deletion src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -739,7 +739,6 @@ QgsSymbolV2* QgsSymbolLayerV2Utils::loadSymbol( QDomElement& element )
return NULL;
}

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

return symbol;
Expand Down
11 changes: 11 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -76,6 +76,9 @@ void QgsSimpleLineSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
mOffsetUnitComboBox->blockSignals( true );
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
mOffsetUnitComboBox->blockSignals( false );
mDashPatternUnitComboBox->blockSignals( true );
mDashPatternUnitComboBox->setCurrentIndex( mLayer->customDashPatternUnit() );
mDashPatternUnitComboBox->blockSignals( false );

// set values
spinWidth->setValue( mLayer->width() );
Expand Down Expand Up @@ -185,6 +188,14 @@ void QgsSimpleLineSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChange
}
}

void QgsSimpleLineSymbolLayerV2Widget::on_mDashPatternUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setCustomDashPatternUnit(( QgsSymbolV2::OutputUnit )index );
}
}

void QgsSimpleLineSymbolLayerV2Widget::updatePatternIcon()
{
if ( !mLayer )
Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -69,6 +69,7 @@ class GUI_EXPORT QgsSimpleLineSymbolLayerV2Widget : public QgsSymbolLayerV2Widge
void on_mChangePatternButton_clicked();
void on_mPenWidthUnitComboBox_currentIndexChanged( int index );
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
void on_mDashPatternUnitComboBox_currentIndexChanged( int index );


protected:
Expand Down
36 changes: 30 additions & 6 deletions src/ui/symbollayer/widget_simpleline.ui
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>278</width>
<height>195</height>
<width>331</width>
<height>235</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -143,21 +143,24 @@
</property>
</widget>
</item>
<item row="4" column="1" rowspan="2" colspan="2">
<item row="4" column="1" colspan="2">
<widget class="QgsPenJoinStyleComboBox" name="cboJoinStyle"/>
</item>
<item row="5" column="0" rowspan="2">
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Cap style</string>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<item row="5" column="1" colspan="2">
<widget class="QgsPenCapStyleComboBox" name="cboCapStyle"/>
</item>
<item row="7" column="0" colspan="3">
<item row="6" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<widget class="QCheckBox" name="mCustomCheckBox">
<property name="text">
Expand All @@ -174,6 +177,27 @@
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mDashPatternUnitLabel">
<property name="text">
<string>Dash pattern unit</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="2">
<widget class="QComboBox" name="mDashPatternUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down

0 comments on commit b163d05

Please sign in to comment.