Skip to content

Commit

Permalink
Fixed scaling of line decoration symbol layer.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14780 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Nov 28, 2010
1 parent 89e0a94 commit 5a28acc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
15 changes: 11 additions & 4 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Expand Up @@ -455,9 +455,10 @@ double QgsMarkerLineSymbolLayerV2::width() const

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

QgsLineDecorationSymbolLayerV2::QgsLineDecorationSymbolLayerV2( QColor color )
QgsLineDecorationSymbolLayerV2::QgsLineDecorationSymbolLayerV2( QColor color, double width )
{
mColor = color;
mWidth = width;
}

QgsLineDecorationSymbolLayerV2::~QgsLineDecorationSymbolLayerV2()
Expand All @@ -467,11 +468,14 @@ QgsLineDecorationSymbolLayerV2::~QgsLineDecorationSymbolLayerV2()
QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2::create( const QgsStringMap& props )
{
QColor color = DEFAULT_LINEDECORATION_COLOR;
double width = DEFAULT_LINEDECORATION_WIDTH;

if ( props.contains( "color" ) )
color = QgsSymbolLayerV2Utils::decodeColor( props["color"] );
if ( props.contains( "width" ) )
width = props["width"].toDouble();

return new QgsLineDecorationSymbolLayerV2( color );
return new QgsLineDecorationSymbolLayerV2( color, width );
}

QString QgsLineDecorationSymbolLayerV2::layerType() const
Expand All @@ -483,9 +487,11 @@ void QgsLineDecorationSymbolLayerV2::startRender( QgsSymbolV2RenderContext& cont
{
QColor penColor = mColor;
penColor.setAlphaF( context.alpha() );
mPen.setWidth( context.outputLineWidth( mWidth ) );
mPen.setColor( penColor );
QColor selColor = context.selectionColor();
if ( ! selectionIsOpaque ) selColor.setAlphaF( context.alpha() );
mSelPen.setWidth( context.outputLineWidth( mWidth ) );
mSelPen.setColor( selColor );
}

Expand Down Expand Up @@ -521,7 +527,7 @@ void QgsLineDecorationSymbolLayerV2::renderPolyline( const QPolygonF& points, Qg
QPointF p2 = points.at( cnt - 1 );
double angle = _calculateAngle( p1.x(), p1.y(), p2.x(), p2.y() );

double size = context.outputLineWidth( 2 );
double size = context.outputLineWidth( mWidth * 8 );
double angle1 = angle + M_PI / 6;
double angle2 = angle - M_PI / 6;

Expand All @@ -537,10 +543,11 @@ QgsStringMap QgsLineDecorationSymbolLayerV2::properties() const
{
QgsStringMap map;
map["color"] = QgsSymbolLayerV2Utils::encodeColor( mColor );
map["width"] = QString::number( mWidth );
return map;
}

QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2::clone() const
{
return new QgsLineDecorationSymbolLayerV2( mColor );
return new QgsLineDecorationSymbolLayerV2( mColor, mWidth );
}
4 changes: 3 additions & 1 deletion src/core/symbology-ng/qgslinesymbollayerv2.h
Expand Up @@ -146,11 +146,13 @@ class CORE_EXPORT QgsMarkerLineSymbolLayerV2 : public QgsLineSymbolLayerV2
/////////

#define DEFAULT_LINEDECORATION_COLOR QColor(0,0,0)
#define DEFAULT_LINEDECORATION_WIDTH DEFAULT_LINE_WIDTH

class CORE_EXPORT QgsLineDecorationSymbolLayerV2 : public QgsLineSymbolLayerV2
{
public:
QgsLineDecorationSymbolLayerV2( QColor color = DEFAULT_LINEDECORATION_COLOR );
QgsLineDecorationSymbolLayerV2( QColor color = DEFAULT_LINEDECORATION_COLOR,
double width = DEFAULT_LINEDECORATION_WIDTH );

~QgsLineDecorationSymbolLayerV2();

Expand Down
8 changes: 8 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -589,6 +589,7 @@ QgsLineDecorationSymbolLayerV2Widget::QgsLineDecorationSymbolLayerV2Widget( QWid
setupUi( this );

connect( btnChangeColor, SIGNAL( clicked() ), this, SLOT( colorChanged() ) );
connect( spinWidth, SIGNAL( valueChanged( double ) ), this, SLOT( penWidthChanged() ) );
}

void QgsLineDecorationSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
Expand All @@ -601,6 +602,7 @@ void QgsLineDecorationSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* lay

// set values
btnChangeColor->setColor( mLayer->color() );
spinWidth->setValue( mLayer->width() );
}

QgsSymbolLayerV2* QgsLineDecorationSymbolLayerV2Widget::symbolLayer()
Expand All @@ -618,6 +620,12 @@ void QgsLineDecorationSymbolLayerV2Widget::colorChanged()
emit changed();
}

void QgsLineDecorationSymbolLayerV2Widget::penWidthChanged()
{
mLayer->setWidth( spinWidth->value() );
emit changed();
}

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

#include <QFileDialog>
Expand Down
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -209,6 +209,7 @@ class GUI_EXPORT QgsLineDecorationSymbolLayerV2Widget : public QgsSymbolLayerV2W

public slots:
void colorChanged();
void penWidthChanged();

protected:
QgsLineDecorationSymbolLayerV2* mLayer;
Expand Down
40 changes: 32 additions & 8 deletions src/ui/symbollayer/widget_linedecoration.ui
Expand Up @@ -6,24 +6,24 @@
<rect>
<x>0</x>
<y>0</y>
<width>368</width>
<height>244</height>
<width>366</width>
<height>242</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout">
<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>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColor">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
Expand All @@ -36,7 +36,7 @@
</property>
</widget>
</item>
<item>
<item row="0" column="2" rowspan="2">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -47,11 +47,31 @@
<property name="sizeHint" stdset="0">
<size>
<width>112</width>
<height>21</height>
<height>48</height>
</size>
</property>
</spacer>
</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">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand All @@ -76,6 +96,10 @@
<header>qgscolorbutton.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>btnChangeColor</tabstop>
<tabstop>spinWidth</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

0 comments on commit 5a28acc

Please sign in to comment.