Skip to content
Permalink
Browse files
Output units for simple fill symbol layer
  • Loading branch information
mhugent committed Mar 13, 2013
1 parent ac3dbea commit 4c49cf30c99f73fc69d15061d34f35afaf0d70ac
@@ -28,11 +28,28 @@
#include <QDomElement>

QgsSimpleFillSymbolLayerV2::QgsSimpleFillSymbolLayerV2( QColor color, Qt::BrushStyle style, QColor borderColor, Qt::PenStyle borderStyle, double borderWidth )
: mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth )
: mBrushStyle( style ), mBorderColor( borderColor ), mBorderStyle( borderStyle ), mBorderWidth( borderWidth ), mBorderWidthUnit( QgsSymbolV2::MM ),
mOffsetUnit( QgsSymbolV2::MM )
{
mColor = color;
}

void QgsSimpleFillSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
{
mBorderWidthUnit = unit;
mOffsetUnit = unit;
}

QgsSymbolV2::OutputUnit QgsSimpleFillSymbolLayerV2::outputUnit() const
{
QgsSymbolV2::OutputUnit unit = mBorderWidthUnit;
if ( mOffsetUnit != unit )
{
return QgsSymbolV2::Mixed;
}
return unit;
}


QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props )
{
@@ -58,6 +75,10 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::create( const QgsStringMap& props

QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( color, style, borderColor, borderStyle, borderWidth );
sl->setOffset( offset );
if ( props.contains( "border_width_unit" ) )
sl->setBorderWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["border_width_unit"] ) );
if ( props.contains( "offset_unit" ) )
sl->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit"] ) );
return sl;
}

@@ -94,7 +115,7 @@ void QgsSimpleFillSymbolLayerV2::startRender( QgsSymbolV2RenderContext& context
mPen = QPen( borderColor );
mSelPen = QPen( selPenColor );
mPen.setStyle( mBorderStyle );
mPen.setWidthF( context.outputLineWidth( mBorderWidth ) );
mPen.setWidthF( mBorderWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mBorderWidthUnit ) );
}

void QgsSimpleFillSymbolLayerV2::stopRender( QgsSymbolV2RenderContext& context )
@@ -114,13 +135,20 @@ void QgsSimpleFillSymbolLayerV2::renderPolygon( const QPolygonF& points, QList<Q
p->setPen( mPen );
p->setPen( context.selected() ? mSelPen : mPen );

QPointF offset;
if ( !mOffset.isNull() )
p->translate( mOffset );
{
offset.setX( mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit ) );
offset.setY( mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit ) );
p->translate( offset );
}

_renderPolygon( p, points, rings );

if ( !mOffset.isNull() )
p->translate( -mOffset );
{
p->translate( -offset );
}
}

QgsStringMap QgsSimpleFillSymbolLayerV2::properties() const
@@ -131,14 +159,18 @@ QgsStringMap QgsSimpleFillSymbolLayerV2::properties() const
map["color_border"] = QgsSymbolLayerV2Utils::encodeColor( mBorderColor );
map["style_border"] = QgsSymbolLayerV2Utils::encodePenStyle( mBorderStyle );
map["width_border"] = QString::number( mBorderWidth );
map["border_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mBorderWidthUnit );
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
return map;
}

QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::clone() const
{
QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( mColor, mBrushStyle, mBorderColor, mBorderStyle, mBorderWidth );
sl->setOffset( mOffset );
sl->setOffsetUnit( mOffsetUnit );
sl->setBorderWidthUnit( mBorderWidthUnit );
return sl;
}

@@ -74,17 +74,28 @@ class CORE_EXPORT QgsSimpleFillSymbolLayerV2 : public QgsFillSymbolLayerV2
void setOffset( QPointF offset ) { mOffset = offset; }
QPointF offset() { return mOffset; }

void setBorderWidthUnit( QgsSymbolV2::OutputUnit unit ) { mBorderWidthUnit = unit; }
QgsSymbolV2::OutputUnit borderWidthUnit() const { return mBorderWidthUnit; }

void setOffsetUnit( QgsSymbolV2::OutputUnit unit ) { mOffsetUnit = unit; }
QgsSymbolV2::OutputUnit offsetUnit() const { return mOffsetUnit; }

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

protected:
QBrush mBrush;
QBrush mSelBrush;
Qt::BrushStyle mBrushStyle;
QColor mBorderColor;
Qt::PenStyle mBorderStyle;
double mBorderWidth;
QgsSymbolV2::OutputUnit mBorderWidthUnit;
QPen mPen;
QPen mSelPen;

QPointF mOffset;
QgsSymbolV2::OutputUnit mOffsetUnit;
};

/**Base class for polygon renderers generating texture images*/
@@ -673,7 +673,6 @@ void QgsFillSymbolV2::renderPolygon( const QPolygonF& points, QList<QPolygonF>*
QgsSymbolV2* QgsFillSymbolV2::clone() const
{
QgsSymbolV2* cloneSymbol = new QgsFillSymbolV2( cloneLayers() );
cloneSymbol->setOutputUnit( outputUnit() );
cloneSymbol->setAlpha( mAlpha );
return cloneSymbol;
}
@@ -408,6 +408,13 @@ void QgsSimpleFillSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
spinOffsetY->blockSignals( true );
spinOffsetY->setValue( mLayer->offset().y() );
spinOffsetY->blockSignals( false );

mBorderWidthUnitComboBox->blockSignals( true );
mBorderWidthUnitComboBox->setCurrentIndex( mLayer->borderWidthUnit() );
mBorderWidthUnitComboBox->blockSignals( false );
mOffsetUnitComboBox->blockSignals( true );
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
mOffsetUnitComboBox->blockSignals( false );
}

QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2Widget::symbolLayer()
@@ -473,6 +480,24 @@ void QgsSimpleFillSymbolLayerV2Widget::offsetChanged()
emit changed();
}

void QgsSimpleFillSymbolLayerV2Widget::on_mBorderWidthUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setBorderWidthUnit(( QgsSymbolV2::OutputUnit ) index );
emit changed();
}
}

void QgsSimpleFillSymbolLayerV2Widget::on_mOffsetUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setOffsetUnit(( QgsSymbolV2::OutputUnit ) index );
emit changed();
}
}

///////////

QgsMarkerLineSymbolLayerV2Widget::QgsMarkerLineSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent )
@@ -138,6 +138,8 @@ class GUI_EXPORT QgsSimpleFillSymbolLayerV2Widget : public QgsSymbolLayerV2Widge
void borderWidthChanged();
void borderStyleChanged();
void offsetChanged();
void on_mBorderWidthUnitComboBox_currentIndexChanged( int index );
void on_mOffsetUnitComboBox_currentIndexChanged( int index );

protected:
QgsSimpleFillSymbolLayerV2* mLayer;
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>335</width>
<height>212</height>
<height>220</height>
</rect>
</property>
<property name="windowTitle">
@@ -19,51 +19,35 @@
</property>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="1">
<widget class="QgsPenStyleComboBox" name="cboBorderStyle"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColor">
<property name="text">
<string>Border color</string>
<string>Change</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<item row="6" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Fill style</string>
<string>Offset X,Y</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QgsBrushStyleComboBox" name="cboFillStyle"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="spinBorderWidth">
<property name="decimals">
<number>5</number>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
<string>Border color</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_6">
<item row="2" column="1">
<widget class="QgsColorButtonV2" name="btnChangeBorderColor">
<property name="text">
<string>Offset X,Y</string>
<string>Change</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="6" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDoubleSpinBox" name="spinOffsetX">
@@ -93,17 +77,40 @@
</item>
</layout>
</item>
<item row="2" column="1">
<widget class="QgsColorButtonV2" name="btnChangeBorderColor">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Change</string>
<string>Color</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QgsColorButtonV2" name="btnChangeColor">
<item row="1" column="1">
<widget class="QgsBrushStyleComboBox" name="cboFillStyle"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Change</string>
<string>Border width</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QgsPenStyleComboBox" name="cboBorderStyle"/>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="spinBorderWidth">
<property name="decimals">
<number>5</number>
</property>
<property name="maximum">
<double>100000.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Fill style</string>
</property>
</widget>
</item>
@@ -114,10 +121,45 @@
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<item row="5" column="1">
<widget class="QComboBox" name="mBorderWidthUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="mBorderWidthUnitLabel">
<property name="text">
<string>Border width</string>
<string>Border width unit</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="mOffsetUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mOffsetUnitLabel">
<property name="text">
<string>Offset unit</string>
</property>
</widget>
</item>

0 comments on commit 4c49cf3

Please sign in to comment.