Skip to content

Commit

Permalink
Output unit for svg marker
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Mar 12, 2013
1 parent d6b140a commit 6c47be6
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 52 deletions.
39 changes: 36 additions & 3 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ QgsSvgMarkerSymbolLayerV2::QgsSvgMarkerSymbolLayerV2( QString name, double size,
mAngle = angle;
mOffset = QPointF( 0, 0 );
mOutlineWidth = 1.0;
mOutlineWidthUnit = QgsSymbolV2::MM;
mFillColor = QColor( Qt::black );
mOutlineColor = QColor( Qt::black );
}
Expand Down Expand Up @@ -653,14 +654,20 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::create( const QgsStringMap& props )
}
}

if ( props.contains( "size_unit" ) )
m->setSizeUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( "size_unit" ) );
if ( props.contains( "offset" ) )
m->setOffset( QgsSymbolLayerV2Utils::decodePoint( props["offset"] ) );
if ( props.contains( "offset_unit" ) )
m->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["offset_unit"] ) );
if ( props.contains( "fill" ) )
m->setFillColor( QColor( props["fill"] ) );
if ( props.contains( "outline" ) )
m->setOutlineColor( QColor( props["outline"] ) );
if ( props.contains( "outline-width" ) )
m->setOutlineWidth( props["outline-width"].toDouble() );
if ( props.contains( "outline_width_unit" ) )
m->setOutlineWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["outline_width_unit"] ) );
return m;
}

Expand Down Expand Up @@ -710,15 +717,18 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
return;
}

double size = context.outputLineWidth( mSize );
double size = mSize * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mSizeUnit );
//don't render symbols with size below one or above 10,000 pixels
if (( int )size < 1 || 10000.0 < size )
{
return;
}

p->save();
QPointF outputOffset = QPointF( context.outputLineWidth( mOffset.x() ), context.outputLineWidth( mOffset.y() ) );
double offsetX = mOffset.x() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
double offsetY = mOffset.y() * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit );
QPointF outputOffset( offsetX, offsetY );

if ( mAngle )
outputOffset = _rotatedOffset( outputOffset, mAngle );
p->translate( point + outputOffset );
Expand Down Expand Up @@ -770,7 +780,7 @@ void QgsSvgMarkerSymbolLayerV2::renderPoint( const QPointF& point, QgsSymbolV2Re
if ( context.selected() )
{
QPen pen( context.selectionColor() );
double penWidth = context.outputLineWidth( 1.0 );
double penWidth = QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), QgsSymbolV2::MM );
if ( penWidth > size / 20 )
{
// keep the pen width from covering symbol
Expand All @@ -794,11 +804,14 @@ QgsStringMap QgsSvgMarkerSymbolLayerV2::properties() const
QgsStringMap map;
map["name"] = QgsSymbolLayerV2Utils::symbolPathToName( mPath );
map["size"] = QString::number( mSize );
map["size_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mSizeUnit );
map["angle"] = QString::number( mAngle );
map["offset"] = QgsSymbolLayerV2Utils::encodePoint( mOffset );
map["offset_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit );
map["fill"] = mFillColor.name();
map["outline"] = mOutlineColor.name();
map["outline-width"] = QString::number( mOutlineWidth );
map["outline_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mOutlineWidthUnit );
return map;
}

Expand All @@ -808,10 +821,30 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::clone() const
m->setFillColor( mFillColor );
m->setOutlineColor( mOutlineColor );
m->setOutlineWidth( mOutlineWidth );
m->setOutlineWidthUnit( mOutlineWidthUnit );
m->setOffset( mOffset );
m->setOffsetUnit( mOffsetUnit );
m->setSizeUnit( mSizeUnit );
return m;
}

void QgsSvgMarkerSymbolLayerV2::setOutputUnit( QgsSymbolV2::OutputUnit unit )
{
mSizeUnit = unit;
mOffsetUnit = unit;
mOutlineWidthUnit = unit;
}

QgsSymbolV2::OutputUnit QgsSvgMarkerSymbolLayerV2::outputUnit() const
{
QgsSymbolV2::OutputUnit unit = mSizeUnit;
if ( unit != mOffsetUnit || unit != mOutlineWidthUnit )
{
return QgsSymbolV2::Mixed;
}
return unit;
}

void QgsSvgMarkerSymbolLayerV2::writeSldMarker( QDomDocument &doc, QDomElement &element, QgsStringMap props ) const
{
// <Graphic>
Expand Down
7 changes: 7 additions & 0 deletions src/core/symbology-ng/qgsmarkersymbollayerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
double outlineWidth() const { return mOutlineWidth; }
void setOutlineWidth( double w ) { mOutlineWidth = w; }

void setOutlineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mOutlineWidthUnit = unit; }
QgsSymbolV2::OutputUnit outlineWidthUnit() const { return mOutlineWidthUnit; }

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

protected:
QString mPath;

Expand All @@ -146,6 +152,7 @@ class CORE_EXPORT QgsSvgMarkerSymbolLayerV2 : public QgsMarkerSymbolLayerV2
QColor mFillColor;
QColor mOutlineColor;
double mOutlineWidth;
QgsSymbolV2::OutputUnit mOutlineWidthUnit;
double mOrigSize;
};

Expand Down
33 changes: 33 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,15 @@ void QgsSvgMarkerSymbolLayerV2Widget::setSymbolLayer( QgsSymbolLayerV2* layer )
spinOffsetY->setValue( mLayer->offset().y() );
spinOffsetY->blockSignals( false );

mSizeUnitComboBox->blockSignals( true );
mSizeUnitComboBox->setCurrentIndex( mLayer->sizeUnit() );
mSizeUnitComboBox->blockSignals( false );
mBorderWidthUnitComboBox->blockSignals( true );
mBorderWidthUnitComboBox->setCurrentIndex( mLayer->outlineWidthUnit() );
mBorderWidthUnitComboBox->blockSignals( false );
mOffsetUnitComboBox->blockSignals( true );
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
mOffsetUnitComboBox->blockSignals( false );
setGuiForSvg( mLayer );
}

Expand Down Expand Up @@ -935,6 +944,30 @@ void QgsSvgMarkerSymbolLayerV2Widget::on_mBorderWidthSpinBox_valueChanged( doubl
}
}

void QgsSvgMarkerSymbolLayerV2Widget::on_mSizeUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setSizeUnit(( QgsSymbolV2::OutputUnit ) index );
}
}

void QgsSvgMarkerSymbolLayerV2Widget::on_mBorderWidthUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setOutlineWidthUnit(( QgsSymbolV2::OutputUnit ) index );
}
}

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

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

QgsLineDecorationSymbolLayerV2Widget::QgsLineDecorationSymbolLayerV2Widget( const QgsVectorLayer* vl, QWidget* parent )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ class GUI_EXPORT QgsSvgMarkerSymbolLayerV2Widget : public QgsSymbolLayerV2Widget
void on_mChangeColorButton_clicked();
void on_mChangeBorderColorButton_clicked();
void on_mBorderWidthSpinBox_valueChanged( double d );
void on_mSizeUnitComboBox_currentIndexChanged( int index );
void on_mBorderWidthUnitComboBox_currentIndexChanged( int index );
void on_mOffsetUnitComboBox_currentIndexChanged( int index );

protected:

Expand Down
161 changes: 112 additions & 49 deletions src/ui/symbollayer/widget_svgmarker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,109 @@
</property>
<item row="0" column="0" colspan="2">
<layout class="QGridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="spinAngle">
<property name="decimals">
<number>2</number>
</property>
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="singleStep">
<double>5.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mSizeUnitComboBox">
<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="label_4">
<property name="text">
<string>Size</string>
<string>Offset X,Y</string>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="4" column="1">
<widget class="QgsColorButtonV2" name="mChangeBorderColorButton">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mSizeUnitLabel">
<property name="text">
<string>Size unit</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mColorLabel">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="mBorderWidthLabel">
<property name="text">
<string>Offset X,Y</string>
<string>Border width</string>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="3" column="1">
<widget class="QgsColorButtonV2" name="mChangeColorButton">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="mBorderWidthSpinBox">
<property name="decimals">
<number>5</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Angle</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mBorderColorLabel">
<property name="text">
<string>Border color</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Size</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="spinSize">
<property name="sizePolicy">
Expand All @@ -72,7 +141,7 @@
</property>
</widget>
</item>
<item row="5" column="1">
<item row="7" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDoubleSpinBox" name="spinOffsetX">
Expand Down Expand Up @@ -102,51 +171,45 @@
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mBorderColorLabel">
<item row="6" column="0">
<widget class="QLabel" name="mBorderWidthUnit">
<property name="text">
<string>Border color</string>
<string>Border width unit</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mBorderWidthLabel">
<property name="text">
<string>Border width</string>
</property>
<item row="6" 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="2" column="0">
<widget class="QLabel" name="mColorLabel">
<property name="text">
<string>Color</string>
</property>
<item row="8" 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="2" column="1">
<widget class="QgsColorButtonV2" name="mChangeColorButton">
<item row="8" column="0">
<widget class="QLabel" name="mOffsetUnitLabel">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="spinAngle">
<property name="decimals">
<number>2</number>
</property>
<property name="maximum">
<double>360.000000000000000</double>
</property>
<property name="singleStep">
<double>5.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QDoubleSpinBox" name="mBorderWidthSpinBox">
<property name="decimals">
<number>5</number>
<string>Offset unit</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 6c47be6

Please sign in to comment.