Skip to content

Commit

Permalink
Distance unit for vector field symbol layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Mar 12, 2013
1 parent 588ceb9 commit ac3dbea
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 23 deletions.
29 changes: 23 additions & 6 deletions src/core/symbology-ng/qgsvectorfieldsymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "qgsvectorfieldsymbollayer.h"
#include "qgsvectorlayer.h"

QgsVectorFieldSymbolLayer::QgsVectorFieldSymbolLayer(): mXAttribute( "" ), mYAttribute( "" ), mScale( 1.0 ),
QgsVectorFieldSymbolLayer::QgsVectorFieldSymbolLayer(): mXAttribute( "" ), mYAttribute( "" ), mDistanceUnit( QgsSymbolV2::MM ), mScale( 1.0 ),
mVectorFieldType( Cartesian ), mAngleOrientation( ClockwiseFromNorth ), mAngleUnits( Degrees ), mXIndex( -1 ), mYIndex( -1 )
{
setSubSymbol( new QgsLineSymbolV2() );
Expand All @@ -28,6 +28,16 @@ QgsVectorFieldSymbolLayer::~QgsVectorFieldSymbolLayer()
{
}

void QgsVectorFieldSymbolLayer::setOutputUnit( QgsSymbolV2::OutputUnit unit )
{
mDistanceUnit = unit; //other units are not used
}

QgsSymbolV2::OutputUnit QgsVectorFieldSymbolLayer::outputUnit() const
{
return mDistanceUnit;
}

QgsSymbolLayerV2* QgsVectorFieldSymbolLayer::create( const QgsStringMap& properties )
{
QgsVectorFieldSymbolLayer* symbolLayer = new QgsVectorFieldSymbolLayer();
Expand All @@ -39,6 +49,10 @@ QgsSymbolLayerV2* QgsVectorFieldSymbolLayer::create( const QgsStringMap& propert
{
symbolLayer->setYAttribute( properties["y_attribute"] );
}
if ( properties.contains( "distance_unit" ) )
{
symbolLayer->setDistanceUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( properties["distance_unit"] ) );
}
if ( properties.contains( "scale" ) )
{
symbolLayer->setScale( properties["scale"].toDouble() );
Expand Down Expand Up @@ -75,6 +89,8 @@ void QgsVectorFieldSymbolLayer::renderPoint( const QPointF& point, QgsSymbolV2Re
return;
}

const QgsRenderContext& ctx = context.renderContext();

const QgsFeature* f = context.feature();
if ( !f )
{
Expand Down Expand Up @@ -102,17 +118,17 @@ void QgsVectorFieldSymbolLayer::renderPoint( const QPointF& point, QgsSymbolV2Re
switch ( mVectorFieldType )
{
case Cartesian:
xComponent = context.outputLineWidth( xVal );
yComponent = context.outputLineWidth( yVal );
xComponent = xVal * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
yComponent = yVal * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
break;
case Polar:
convertPolarToCartesian( xVal, yVal, xComponent, yComponent );
xComponent = context.outputLineWidth( xComponent );
yComponent = context.outputLineWidth( yComponent );
xComponent = xComponent * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
yComponent = yComponent * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
break;
case Height:
xComponent = 0;
yComponent = context.outputLineWidth( yVal );
yComponent = yVal * QgsSymbolLayerV2Utils::lineWidthScaleFactor( ctx, mDistanceUnit );
break;
default:
break;
Expand Down Expand Up @@ -170,6 +186,7 @@ QgsStringMap QgsVectorFieldSymbolLayer::properties() const
QgsStringMap properties;
properties["x_attribute"] = mXAttribute;
properties["y_attribute"] = mYAttribute;
properties["distance_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( mDistanceUnit );
properties["scale"] = QString::number( mScale );
properties["vector_field_type"] = QString::number( mVectorFieldType );
properties["angle_orientation"] = QString::number( mAngleOrientation );
Expand Down
7 changes: 7 additions & 0 deletions src/core/symbology-ng/qgsvectorfieldsymbollayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,16 @@ class CORE_EXPORT QgsVectorFieldSymbolLayer: public QgsMarkerSymbolLayerV2
void setAngleUnits( AngleUnits units ) { mAngleUnits = units; }
AngleUnits angleUnits() const { return mAngleUnits; }

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

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

private:
QString mXAttribute;
QString mYAttribute;
QgsSymbolV2::OutputUnit mDistanceUnit;
double mScale;
VectorFieldType mVectorFieldType;
AngleOrientation mAngleOrientation;
Expand Down
14 changes: 14 additions & 0 deletions src/gui/symbology-ng/qgsvectorfieldsymbollayerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ void QgsVectorFieldSymbolLayerWidget::setSymbolLayer( QgsSymbolLayerV2* layer )
{
mRadiansRadioButton->setChecked( true );
}

mDistanceUnitComboBox->blockSignals( true );
mDistanceUnitComboBox->setCurrentIndex( mLayer->distanceUnit() );
mDistanceUnitComboBox->blockSignals( false );

emit changed();
}

Expand Down Expand Up @@ -194,3 +199,12 @@ void QgsVectorFieldSymbolLayerWidget::on_mCounterclockwiseFromEastRadioButton_to
emit changed();
}
}

void QgsVectorFieldSymbolLayerWidget::on_mDistanceUnitComboBox_currentIndexChanged( int index )
{
if ( mLayer )
{
mLayer->setDistanceUnit(( QgsSymbolV2::OutputUnit ) index );
emit changed();
}
}
1 change: 1 addition & 0 deletions src/gui/symbology-ng/qgsvectorfieldsymbollayerwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class GUI_EXPORT QgsVectorFieldSymbolLayerWidget: public QgsSymbolLayerV2Widget,
void on_mRadiansRadioButton_toggled( bool checked );
void on_mClockwiseFromNorthRadioButton_toggled( bool checked );
void on_mCounterclockwiseFromEastRadioButton_toggled( bool checked );
void on_mDistanceUnitComboBox_currentIndexChanged( int index );
};

#endif // QGSVECTORFIELDSYMBOLLAYERWIDGET_H
2 changes: 1 addition & 1 deletion src/ui/symbollayer/widget_ellipse.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>336</width>
<height>336</height>
<height>357</height>
</rect>
</property>
<property name="windowTitle">
Expand Down
53 changes: 37 additions & 16 deletions src/ui/symbollayer/widget_vectorfield.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,34 @@
<property name="margin">
<number>1</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="mXAttributeLabel">
<property name="text">
<string>X attribute</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="mXAttributeComboBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="mYAttributeLabel">
<property name="text">
<string>Y attribute</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mYAttributeComboBox"/>
<item row="0" column="1">
<widget class="QComboBox" name="mXAttributeComboBox"/>
</item>
<item row="2" column="0">
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="mScaleSpinBox"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mScaleLabel">
<property name="text">
<string>Scale</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="mScaleSpinBox"/>
<item row="0" column="0">
<widget class="QLabel" name="mXAttributeLabel">
<property name="text">
<string>X attribute</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<item row="4" column="0" colspan="2">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
Expand Down Expand Up @@ -141,6 +138,30 @@
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="mYAttributeComboBox"/>
</item>
<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="2" column="0">
<widget class="QLabel" name="mDistanceUnitLabel">
<property name="text">
<string>Distance unit</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down

0 comments on commit ac3dbea

Please sign in to comment.