Skip to content

Commit

Permalink
Output units for line pattern fill symbollayer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Mar 13, 2013
1 parent 52611c1 commit 47ee439
Show file tree
Hide file tree
Showing 6 changed files with 318 additions and 73 deletions.
49 changes: 44 additions & 5 deletions src/core/symbology-ng/qgsfillsymbollayerv2.cpp
Expand Up @@ -740,14 +740,32 @@ void QgsSVGFillSymbolLayer::setDefaultSvgParams()
}
}

QgsLinePatternFillSymbolLayer::QgsLinePatternFillSymbolLayer(): QgsImageFillSymbolLayer()
QgsLinePatternFillSymbolLayer::QgsLinePatternFillSymbolLayer(): QgsImageFillSymbolLayer(), mDistanceUnit( QgsSymbolV2::MM ), mLineWidthUnit( QgsSymbolV2::MM ),
mOffsetUnit( QgsSymbolV2::MM )
{
}

QgsLinePatternFillSymbolLayer::~QgsLinePatternFillSymbolLayer()
{
}

void QgsLinePatternFillSymbolLayer::setOutputUnit( QgsSymbolV2::OutputUnit unit )
{
mDistanceUnit = unit;
mLineWidthUnit = unit;
mOffsetUnit = unit;
}

QgsSymbolV2::OutputUnit QgsLinePatternFillSymbolLayer::outputUnit() const
{
QgsSymbolV2::OutputUnit unit = mDistanceUnit;
if ( mLineWidthUnit != unit || mOffsetUnit != unit )
{
return QgsSymbolV2::Mixed;
}
return unit;
}

QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::create( const QgsStringMap& properties )
{
QgsLinePatternFillSymbolLayer* patternLayer = new QgsLinePatternFillSymbolLayer();
Expand Down Expand Up @@ -788,6 +806,20 @@ QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::create( const QgsStringMap& pro
offset = properties["offset"].toDouble();
}
patternLayer->setOffset( offset );


if ( properties.contains( "distance_unit" ) )
{
patternLayer->setDistanceUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["distance_unit"] ) );
}
if ( properties.contains( "line_width_unit" ) )
{
patternLayer->setLineWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["line_width_unit"] ) );
}
if ( properties.contains( "offset_unit" ) )
{
patternLayer->setOffsetUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["offset_unit"] ) );
}
return patternLayer;
}

Expand All @@ -798,9 +830,10 @@ QString QgsLinePatternFillSymbolLayer::layerType() const

void QgsLinePatternFillSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
{
double outlinePixelWidth = context.outputPixelSize( mLineWidth );
double outputPixelDist = context.outputPixelSize( mDistance );
double outputPixelOffset = context.outputPixelSize( mOffset );
const QgsRenderContext& ctx = context.renderContext();
double outlinePixelWidth = mLineWidth * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mLineWidthUnit );
double outputPixelDist = mDistance * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
double outputPixelOffset = mOffset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mOffsetUnit );

//create image
int height, width;
Expand Down Expand Up @@ -936,16 +969,22 @@ QgsStringMap QgsLinePatternFillSymbolLayer::properties() const
map.insert( "linewidth", QString::number( mLineWidth ) );
map.insert( "color", QgsSymbolLayerV2Utils::encodeColor( mColor ) );
map.insert( "offset", QString::number( mOffset ) );
map.insert( "distance_unit", QgsSymbolLayerV2Utils::encodeOutputUnit( mDistanceUnit ) );
map.insert( "line_width_unit", QgsSymbolLayerV2Utils::encodeOutputUnit( mLineWidthUnit ) );
map.insert( "offset_unit", QgsSymbolLayerV2Utils::encodeOutputUnit( mOffsetUnit ) );
return map;
}

QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::clone() const
{
QgsSymbolLayerV2* clonedLayer = QgsLinePatternFillSymbolLayer::create( properties() );
QgsLinePatternFillSymbolLayer* clonedLayer = static_cast<QgsLinePatternFillSymbolLayer*>( QgsLinePatternFillSymbolLayer::create( properties() ) );
if ( mOutline )
{
clonedLayer->setSubSymbol( mOutline->clone() );
}
clonedLayer->setDistanceUnit( mDistanceUnit );
clonedLayer->setLineWidthUnit( mLineWidthUnit );
clonedLayer->setOffsetUnit( mOffsetUnit );
return clonedLayer;
}

Expand Down
15 changes: 15 additions & 0 deletions src/core/symbology-ng/qgsfillsymbollayerv2.h
Expand Up @@ -233,16 +233,31 @@ class CORE_EXPORT QgsLinePatternFillSymbolLayer: public QgsImageFillSymbolLayer
void setOffset( double offset ) { mOffset = offset; }
double offset() const { return mOffset; }

void setDistanceUnit( QgsSymbolV2::OutputUnit unit ) { mDistanceUnit = unit; }
QgsSymbolV2::OutputUnit distanceUnit() const { return mDistanceUnit; }

void setLineWidthUnit( QgsSymbolV2::OutputUnit unit ) { mLineWidthUnit = unit; }
QgsSymbolV2::OutputUnit lineWidthUnit() const { return mLineWidthUnit; }

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

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

protected:
/**Distance (in mm or map units) between lines*/
double mDistance;
QgsSymbolV2::OutputUnit mDistanceUnit;
/**Line width (in mm or map units)*/
double mLineWidth;
QgsSymbolV2::OutputUnit mLineWidthUnit;
QColor mColor;
/**Vector line angle in degrees (0 = horizontal, counterclockwise)*/
double mLineAngle;
/**Offset perpendicular to line direction*/
double mOffset;
QgsSymbolV2::OutputUnit mOffsetUnit;
};

class CORE_EXPORT QgsPointPatternFillSymbolLayer: public QgsImageFillSymbolLayer
Expand Down
38 changes: 38 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.cpp
Expand Up @@ -1322,6 +1322,17 @@ void QgsLinePatternFillSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* laye
mLineWidthSpinBox->setValue( mLayer->lineWidth() );
mOffsetSpinBox->setValue( mLayer->offset() );
mColorPushButton->setColor( mLayer->color() );

//units
mDistanceUnitComboBox->blockSignals( true );
mDistanceUnitComboBox->setCurrentIndex( mLayer->distanceUnit() );
mDistanceUnitComboBox->blockSignals( false );
mLineWidthUnitComboBox->blockSignals( true );
mLineWidthUnitComboBox->setCurrentIndex( mLayer->lineWidthUnit() );
mLineWidthUnitComboBox->blockSignals( false );
mOffsetUnitComboBox->blockSignals( true );
mOffsetUnitComboBox->setCurrentIndex( mLayer->offsetUnit() );
mOffsetUnitComboBox->blockSignals( false );
}
}

Expand Down Expand Up @@ -1380,6 +1391,33 @@ void QgsLinePatternFillSymbolLayerWidget::on_mColorPushButton_clicked()
}
}

void QgsLinePatternFillSymbolLayerWidget::on_mDistanceUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setDistanceUnit(( QgsSymbolV2::OutputUnit ) index );
emit changed();
}
}

void QgsLinePatternFillSymbolLayerWidget::on_mLineWidthUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setLineWidthUnit(( QgsSymbolV2::OutputUnit ) index );
emit changed();
}
}

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


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

Expand Down
3 changes: 3 additions & 0 deletions src/gui/symbology-ng/qgssymbollayerv2widget.h
Expand Up @@ -319,6 +319,9 @@ class GUI_EXPORT QgsLinePatternFillSymbolLayerWidget : public QgsSymbolLayerV2Wi
void on_mLineWidthSpinBox_valueChanged( double d );
void on_mOffsetSpinBox_valueChanged( double d );
void on_mColorPushButton_clicked();
void on_mDistanceUnitComboBox_currentIndexChanged( int index );
void on_mLineWidthUnitComboBox_currentIndexChanged( int index );
void on_mOffsetUnitComboBox_currentIndexChanged( int index );
};

//////////
Expand Down
130 changes: 98 additions & 32 deletions src/ui/symbollayer/widget_linepatternfill.ui
Expand Up @@ -17,31 +17,20 @@
<property name="margin">
<number>1</number>
</property>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mDistanceSpinBox">
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="mAngleSpinBox">
<property name="maximum">
<double>360.000000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1">
<item row="5" column="1">
<widget class="QDoubleSpinBox" name="mOffsetSpinBox">
<property name="decimals">
<number>5</number>
</property>
<property name="minimum">
<double>-99.000000000000000</double>
</property>
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="mLineWidthSpinBox">
<property name="decimals">
<number>5</number>
Expand All @@ -51,28 +40,98 @@
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QgsColorButtonV2" name="mColorPushButton">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mAngleLabel">
<property name="text">
<string>Angle</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="mAngleSpinBox">
<property name="maximum">
<double>360.000000000000000</double>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="mLineWidthUnitComboBox">
<item>
<property name="text">
<string>Millimeter</string>
</property>
</item>
<item>
<property name="text">
<string>Map unit</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mDistanceLabel">
<property name="text">
<string>Distance</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="mDistanceUnitLabel">
<property name="text">
<string>Distance unit</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mLineWidthLabel">
<property name="text">
<string>Line width</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mLineWidthUnitLabel">
<property name="text">
<string>Line width unit</string>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="mColorLabel">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="mAngleLabel">
<item row="2" column="1">
<widget class="QComboBox" name="mDistanceUnitComboBox">
<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="mOffsetLabel">
<property name="text">
<string>Angle</string>
<string>Offset</string>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="8" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -85,24 +144,31 @@
</property>
</spacer>
</item>
<item row="4" column="1">
<widget class="QgsColorButtonV2" name="mColorPushButton">
<property name="text">
<string>Change</string>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="mDistanceSpinBox">
<property name="maximum">
<double>999999999.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mDistanceLabel">
<property name="text">
<string>Distance</string>
</property>
<item row="6" 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="3" column="0">
<widget class="QLabel" name="mOffsetLabel">
<item row="6" column="0">
<widget class="QLabel" name="mOffsetUnitLabel">
<property name="text">
<string>Offset</string>
<string>Offset unit</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit 47ee439

Please sign in to comment.