Skip to content
Permalink
Browse files
Full support for width/offset/dash units in simple line symbollayer
  • Loading branch information
mhugent committed Mar 10, 2013
1 parent 01734bd commit b163d05f903cb55f68cce79cb37405c99ee039ca
@@ -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;
@@ -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" ) )
@@ -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;
}

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

@@ -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, ...)
@@ -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;
@@ -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() );
@@ -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 )
@@ -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:
@@ -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">
@@ -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">
@@ -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>

0 comments on commit b163d05

Please sign in to comment.