Skip to content

Commit

Permalink
Rename arrow symbol head width/height to length/thickness
Browse files Browse the repository at this point in the history
Width/height naming is dependant on line direction, so for
clarity rename them to something which doesn't depend
on direction (fix #15002)
  • Loading branch information
nyalldawson committed Jun 14, 2016
1 parent 09b6d58 commit 6568da6
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 146 deletions.
62 changes: 34 additions & 28 deletions python/core/symbology-ng/qgsarrowsymbollayer.sip
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/** \ingroup core
* \class QgsArrowSymbolLayer
* \brief Line symbol layer used for representing lines as arrows.
* \note Added in version 2.16
*/

class QgsArrowSymbolLayer : public QgsLineSymbolLayerV2
{
%TypeHeaderCode
Expand Down Expand Up @@ -28,57 +34,57 @@ class QgsArrowSymbolLayer : public QgsLineSymbolLayerV2
/** Return a list of attributes required to render this feature */
virtual QSet<QString> usedAttributes() const;

/** Get current arrow width */
/** Get current arrow width */
double arrowWidth() const;
/** Set the arrow width */
void setArrowWidth( double w );
void setArrowWidth( double width );
/** Get the unit for the arrow width */
QgsSymbolV2::OutputUnit arrowWidthUnit() const;
/** Set the unit for the arrow width */
void setArrowWidthUnit( QgsSymbolV2::OutputUnit u );
void setArrowWidthUnit( QgsSymbolV2::OutputUnit unit );
/** Get the scale for the arrow width */
QgsMapUnitScale arrowWidthUnitScale() const;
/** Set the scale for the arrow width */
void setArrowWidthUnitScale( const QgsMapUnitScale& s );
void setArrowWidthUnitScale( const QgsMapUnitScale& scale );

/** Get current arrow start width. Only meaningfull for single headed arrows */
double arrowStartWidth() const;
/** Set the arrow start width */
void setArrowStartWidth( double w );
void setArrowStartWidth( double width );
/** Get the unit for the arrow start width */
QgsSymbolV2::OutputUnit arrowStartWidthUnit() const;
/** Set the unit for the arrow start width */
void setArrowStartWidthUnit( QgsSymbolV2::OutputUnit u );
void setArrowStartWidthUnit( QgsSymbolV2::OutputUnit unit );
/** Get the scale for the arrow start width */
QgsMapUnitScale arrowStartWidthUnitScale() const;
/** Set the scale for the arrow start width */
void setArrowStartWidthUnitScale( const QgsMapUnitScale& s );

/** Get the current arrow head width */
double headWidth() const;
/** Set the arrow head width */
void setHeadWidth( double s );
/** Get the unit for the head width */
QgsSymbolV2::OutputUnit headWidthUnit() const;
/** Set the unit for the head width */
void setHeadWidthUnit( QgsSymbolV2::OutputUnit u );
/** Get the scale for the head width */
QgsMapUnitScale headWidthUnitScale() const;
/** Set the scale for the head width */
void setHeadWidthUnitScale( const QgsMapUnitScale& s );
void setArrowStartWidthUnitScale( const QgsMapUnitScale& scale );

/** Get the current arrow head length */
double headLength() const;
/** Set the arrow head length */
void setHeadLength( double length );
/** Get the unit for the head length */
QgsSymbolV2::OutputUnit headLengthUnit() const;
/** Set the unit for the head length */
void setHeadLengthUnit( QgsSymbolV2::OutputUnit unit );
/** Get the scale for the head length */
QgsMapUnitScale headLengthUnitScale() const;
/** Set the scale for the head length */
void setHeadLengthUnitScale( const QgsMapUnitScale& scale );

/** Get the current arrow head height */
double headHeight() const;
double headThickness() const;
/** Set the arrow head height */
void setHeadHeight( double s );
void setHeadThickness( double thickness );
/** Get the unit for the head height */
QgsSymbolV2::OutputUnit headHeightUnit() const;
QgsSymbolV2::OutputUnit headThicknessUnit() const;
/** Set the unit for the head height */
void setHeadHeightUnit( QgsSymbolV2::OutputUnit u );
void setHeadThicknessUnit( QgsSymbolV2::OutputUnit unit );
/** Get the scale for the head height */
QgsMapUnitScale headHeightUnitScale() const;
QgsMapUnitScale headThicknessUnitScale() const;
/** Set the scale for the head height */
void setHeadHeightUnitScale( const QgsMapUnitScale& s );
void setHeadThicknessUnitScale( const QgsMapUnitScale& scale );

/** Return whether it is a curved arrow or a straight one */
bool isCurved() const;
Expand All @@ -101,7 +107,7 @@ class QgsArrowSymbolLayer : public QgsLineSymbolLayerV2
/** Get the current head type */
HeadType headType() const;
/** Set the head type */
void setHeadType( HeadType t );
void setHeadType( HeadType type );

/** Possible arrow types */
enum ArrowType
Expand All @@ -114,7 +120,7 @@ class QgsArrowSymbolLayer : public QgsLineSymbolLayerV2
/** Get the current arrow type */
ArrowType arrowType() const;
/** Set the arrow type */
void setArrowType( ArrowType t );
void setArrowType( ArrowType type );

/**
* Should be reimplemented by subclasses to return a string map that
Expand Down
80 changes: 40 additions & 40 deletions src/core/symbology-ng/qgsarrowsymbollayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ QgsArrowSymbolLayer::QgsArrowSymbolLayer()
, mArrowWidthUnit( QgsSymbolV2::MM )
, mArrowStartWidth( 1.0 )
, mArrowStartWidthUnit( QgsSymbolV2::MM )
, mHeadWidth( 1.5 )
, mHeadWidthUnit( QgsSymbolV2::MM )
, mHeadHeight( 1.5 )
, mHeadHeightUnit( QgsSymbolV2::MM )
, mHeadLength( 1.5 )
, mHeadLengthUnit( QgsSymbolV2::MM )
, mHeadThickness( 1.5 )
, mHeadThicknessUnit( QgsSymbolV2::MM )
, mHeadType( HeadSingle )
, mArrowType( ArrowPlain )
, mIsCurved( true )
, mIsRepeated( true )
, mScaledArrowWidth( 1.0 )
, mScaledArrowStartWidth( 1.0 )
, mScaledHeadWidth( 1.5 )
, mScaledHeadHeight( 1.5 )
, mScaledHeadLength( 1.5 )
, mScaledHeadThickness( 1.5 )
, mScaledOffset( 0.0 )
, mComputedHeadType( HeadSingle )
, mComputedArrowType( ArrowPlain )
Expand Down Expand Up @@ -83,23 +83,23 @@ QgsSymbolLayerV2* QgsArrowSymbolLayer::create( const QgsStringMap& props )
if ( props.contains( "is_repeated" ) )
l->setIsRepeated( props["is_repeated"].toInt() == 1 );

if ( props.contains( "head_width" ) )
l->setHeadWidth( props["head_width"].toDouble() );
if ( props.contains( "head_length" ) )
l->setHeadLength( props["head_length"].toDouble() );

if ( props.contains( "head_width_unit" ) )
l->setHeadWidthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["head_width_unit"] ) );
if ( props.contains( "head_length_unit" ) )
l->setHeadLengthUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["head_length_unit"] ) );

if ( props.contains( "head_width_unit_scale" ) )
l->setHeadWidthUnitScale( QgsSymbolLayerV2Utils::decodeMapUnitScale( props["head_width_unit_scale"] ) );
if ( props.contains( "head_length_unit_scale" ) )
l->setHeadLengthUnitScale( QgsSymbolLayerV2Utils::decodeMapUnitScale( props["head_length_unit_scale"] ) );

if ( props.contains( "head_height" ) )
l->setHeadHeight( props["head_height"].toDouble() );
if ( props.contains( "head_thickness" ) )
l->setHeadThickness( props["head_thickness"].toDouble() );

if ( props.contains( "head_height_unit" ) )
l->setHeadHeightUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["head_height_unit"] ) );
if ( props.contains( "head_thickness_unit" ) )
l->setHeadThicknessUnit( QgsSymbolLayerV2Utils::decodeOutputUnit( props["head_thickness_unit"] ) );

if ( props.contains( "head_height_unit_scale" ) )
l->setHeadHeightUnitScale( QgsSymbolLayerV2Utils::decodeMapUnitScale( props["head_height_unit_scale"] ) );
if ( props.contains( "head_thickness_unit_scale" ) )
l->setHeadThicknessUnitScale( QgsSymbolLayerV2Utils::decodeMapUnitScale( props["head_thickness_unit_scale"] ) );

if ( props.contains( "head_type" ) )
l->setHeadType( static_cast<HeadType>( props["head_type"].toInt() ) );
Expand Down Expand Up @@ -152,13 +152,13 @@ QgsStringMap QgsArrowSymbolLayer::properties() const
map["is_curved"] = QString::number( isCurved() ? 1 : 0 );
map["is_repeated"] = QString::number( isRepeated() ? 1 : 0 );

map["head_width"] = QString::number( headWidth() );
map["head_width_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( headWidthUnit() );
map["head_width_unit_scale"] = QgsSymbolLayerV2Utils::encodeMapUnitScale( headWidthUnitScale() );
map["head_length"] = QString::number( headLength() );
map["head_length_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( headLengthUnit() );
map["head_length_unit_scale"] = QgsSymbolLayerV2Utils::encodeMapUnitScale( headLengthUnitScale() );

map["head_height"] = QString::number( headHeight() );
map["head_height_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( headHeightUnit() );
map["head_height_unit_scale"] = QgsSymbolLayerV2Utils::encodeMapUnitScale( headHeightUnitScale() );
map["head_thickness"] = QString::number( headThickness() );
map["head_thickness_unit"] = QgsSymbolLayerV2Utils::encodeOutputUnit( headThicknessUnit() );
map["head_thickness_unit_scale"] = QgsSymbolLayerV2Utils::encodeMapUnitScale( headThicknessUnitScale() );

map["head_type"] = QString::number( headType() );
map["arrow_type"] = QString::number( arrowType() );
Expand Down Expand Up @@ -186,8 +186,8 @@ void QgsArrowSymbolLayer::startRender( QgsSymbolV2RenderContext& context )
mExpressionScope.reset( new QgsExpressionContextScope() );
mScaledArrowWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), arrowWidth(), arrowWidthUnit(), arrowWidthUnitScale() );
mScaledArrowStartWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), arrowStartWidth(), arrowStartWidthUnit(), arrowStartWidthUnitScale() );
mScaledHeadWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), headWidth(), headWidthUnit(), headWidthUnitScale() );
mScaledHeadHeight = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), headHeight(), headHeightUnit(), headHeightUnitScale() );
mScaledHeadLength = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), headLength(), headLengthUnit(), headLengthUnitScale() );
mScaledHeadThickness = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), headThickness(), headThicknessUnit(), headThicknessUnitScale() );
mScaledOffset = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), offset(), offsetUnit(), offsetMapUnitScale() );
mComputedHeadType = headType();
mComputedArrowType = arrowType();
Expand Down Expand Up @@ -632,22 +632,22 @@ void QgsArrowSymbolLayer::_resolveDataDefined( QgsSymbolV2RenderContext& context
mScaledArrowStartWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), w, arrowStartWidthUnit(), arrowStartWidthUnitScale() );
}
}
if ( hasDataDefinedProperty( "head_width" ) )
if ( hasDataDefinedProperty( "head_length" ) )
{
context.setOriginalValueVariable( headWidth() );
double w = evaluateDataDefinedProperty( "head_width", context, QVariant(), &ok ).toDouble();
context.setOriginalValueVariable( headLength() );
double w = evaluateDataDefinedProperty( "head_length", context, QVariant(), &ok ).toDouble();
if ( ok )
{
mScaledHeadWidth = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), w, headWidthUnit(), headWidthUnitScale() );
mScaledHeadLength = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), w, headLengthUnit(), headLengthUnitScale() );
}
}
if ( hasDataDefinedProperty( "head_height" ) )
if ( hasDataDefinedProperty( "head_thickness" ) )
{
context.setOriginalValueVariable( headHeight() );
double w = evaluateDataDefinedProperty( "head_height", context, QVariant(), &ok ).toDouble();
context.setOriginalValueVariable( headThickness() );
double w = evaluateDataDefinedProperty( "head_thickness", context, QVariant(), &ok ).toDouble();
if ( ok )
{
mScaledHeadHeight = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), w, headHeightUnit(), headHeightUnitScale() );
mScaledHeadThickness = QgsSymbolLayerV2Utils::convertToPainterUnits( context.renderContext(), w, headThicknessUnit(), headThicknessUnitScale() );
}
}
if ( hasDataDefinedProperty( QgsSymbolLayerV2::EXPR_OFFSET ) )
Expand Down Expand Up @@ -708,7 +708,7 @@ void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolV2Re
// destination point
QPointF pd( points.back() );

QPolygonF poly = curvedArrow( po, pm, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
QPolygonF poly = curvedArrow( po, pm, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadLength, mScaledHeadThickness, mComputedHeadType, mComputedArrowType, mScaledOffset );
mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
}
// straight arrow
Expand All @@ -719,7 +719,7 @@ void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolV2Re
// destination point
QPointF pd( points.at( 1 ) );

QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadLength, mScaledHeadThickness, mComputedHeadType, mComputedArrowType, mScaledOffset );
mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
}
}
Expand All @@ -739,7 +739,7 @@ void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolV2Re
// destination point
QPointF pd( points.at( pIdx + 2 ) );

QPolygonF poly = curvedArrow( po, pm, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
QPolygonF poly = curvedArrow( po, pm, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadLength, mScaledHeadThickness, mComputedHeadType, mComputedArrowType, mScaledOffset );
mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
}
// straight arrow
Expand All @@ -750,7 +750,7 @@ void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolV2Re
// destination point
QPointF pd( points.at( pIdx + 1 ) );

QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadLength, mScaledHeadThickness, mComputedHeadType, mComputedArrowType, mScaledOffset );
mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
}
}
Expand All @@ -769,7 +769,7 @@ void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolV2Re
// destination point
QPointF pd( points.back() );

QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadLength, mScaledHeadThickness, mComputedHeadType, mComputedArrowType, mScaledOffset );
mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
}
}
Expand All @@ -786,7 +786,7 @@ void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolV2Re
// destination point
QPointF pd( points.at( pIdx + 1 ) );

QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadWidth, mScaledHeadHeight, mComputedHeadType, mComputedArrowType, mScaledOffset );
QPolygonF poly = straightArrow( po, pd, mScaledArrowStartWidth, mScaledArrowWidth, mScaledHeadLength, mScaledHeadThickness, mComputedHeadType, mComputedArrowType, mScaledOffset );
mSymbol->renderPolygon( poly, /* rings */ nullptr, context.feature(), context.renderContext() );
}
}
Expand Down
Loading

0 comments on commit 6568da6

Please sign in to comment.