Skip to content

Commit

Permalink
Output units for line decoration symbol layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Mar 11, 2013
1 parent 460a471 commit c771505
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 13 deletions.
32 changes: 27 additions & 5 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,14 @@ QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2::create( const QgsStringMap& pr
if ( props.contains( "width" ) )
width = props["width"].toDouble();

return new QgsLineDecorationSymbolLayerV2( color, width );

QgsLineDecorationSymbolLayerV2* layer = new QgsLineDecorationSymbolLayerV2( color, width );
if ( props.contains( "width_unit" ) )
{
layer->setWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["width_unit"] ) );
}
return layer;

}

QString QgsLineDecorationSymbolLayerV2::layerType() const
Expand All @@ -932,12 +939,14 @@ void QgsLineDecorationSymbolLayerV2::startRender( QgsSymbolV2RenderContext& cont
{
QColor penColor = mColor;
penColor.setAlphaF( context.alpha() );
mPen.setWidth( context.outputLineWidth( mWidth ) );

double width = mWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
mPen.setWidth( context.outputLineWidth( width ) );
mPen.setColor( penColor );
QColor selColor = context.selectionColor();
if ( ! selectionIsOpaque )
selColor.setAlphaF( context.alpha() );
mSelPen.setWidth( context.outputLineWidth( mWidth ) );
mSelPen.setWidth( context.outputLineWidth( width ) );
mSelPen.setColor( selColor );
}

Expand Down Expand Up @@ -973,7 +982,7 @@ void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, Qg
}

double angle = atan2( p2.y() - p1.y(), p2.x() - p1.x() );
double size = context.outputLineWidth( mWidth * 8 );
double size = ( mWidth * 8 ) * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mWidthUnit );
double angle1 = angle + M_PI / 6;
double angle2 = angle - M_PI / 6;

Expand All @@ -990,12 +999,15 @@ QgsStringMap QgsLineDecorationSymbolLayerV2::properties() const
QgsStringMap map;
map["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
map["width"] = QString::number( mWidth );
map["width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mWidthUnit );
return map;
}

QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2::clone() const
{
return new QgsLineDecorationSymbolLayerV2( mColor, mWidth );
QgsLineDecorationSymbolLayerV2* layer = new QgsLineDecorationSymbolLayerV2( mColor, mWidth );
layer->setWidthUnit( mWidthUnit );
return layer;
}

void QgsLineDecorationSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
Expand Down Expand Up @@ -1028,3 +1040,13 @@ void QgsLineDecorationSymbolLayerV2::toSld( QDomDocument &doc, QDomElement &elem
// use <VendorOption> to draw the decoration at end of the line
symbolizerElem.appendChild( QgsSymbolLayerV2Utils::createVendorOptionElement( doc, "placement", "lastPoint" ) );
}

void QgsLineDecorationSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
{
mWidthUnit = unit;
}

QgsSymbolV2::OutputUnit QgsLineDecorationSymbolLayerV2::outputUnit() const
{
return mWidthUnit;
}
3 changes: 3 additions & 0 deletions src/core/symbology-ng/qgslinesymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ class CORE_EXPORT QgsLineDecorationSymbolLayerV2 : public QgsLineSymbolLayerV2

void toSld( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const;

void setOutputUnit( QgsSymbolV2::OutputUnit unit );
QgsSymbolV2::OutputUnit outputUnit() const;

protected:
QPen mPen;
QPen mSelPen;
Expand Down
12 changes: 12 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,10 @@ void QgsLineDecorationSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* lay
// set values
btnChangeColor->setColor( mLayer->color() );
spinWidth->setValue( mLayer->width() );

mWidthUnitComboBox->blockSignals( true );
mWidthUnitComboBox->setCurrentIndex( mLayer->widthUnit() );
mWidthUnitComboBox->blockSignals( false );
}

QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2Widget::symbolLayer()
Expand Down Expand Up @@ -966,6 +970,14 @@ void QgsLineDecorationSymbolLayerV2Widget::penWidthChanged()
emit changed();
}

void QgsLineDecorationSymbolLayerV2Widget::on_mWidthUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setWidthUnit(( QgsSymbolV2::OutputUnit ) index );
}
}

/////////////

#include <QFileDialog>
Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ class GUI_EXPORT QgsLineDecorationSymbolLayerV2Widget : public QgsSymbolLayerV2W
public slots:
void colorChanged();
void penWidthChanged();
void on_mWidthUnitComboBox_currentIndexChanged( int index );

protected:
QgsLineDecorationSymbolLayerV2* mLayer;
Expand Down
37 changes: 29 additions & 8 deletions src/ui/symbollayer/widget_linedecoration.ui
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColor">
<property name="sizePolicy">
Expand All @@ -32,6 +39,13 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Pen width</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spinWidth">
<property name="alignment">
Expand All @@ -48,17 +62,24 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Pen width</string>
</property>
<item row="2" column="1">
<widget class="QComboBox" name="mWidthUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<item row="2" column="0">
<widget class="QLabel" name="mWidthUnitLabel">
<property name="text">
<string>Color</string>
<string>Width unit</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit c771505

Please sign in to comment.