@@ -28,6 +28,7 @@ QgsArrowSymbolLayer::QgsArrowSymbolLayer()
28
28
, mHeadType( HeadSingle )
29
29
, mArrowType( ArrowPlain )
30
30
, mIsCurved( true )
31
+ , mIsRepeated( true )
31
32
, mScaledArrowWidth( 1.0 )
32
33
, mScaledArrowStartWidth( 1.0 )
33
34
, mScaledHeadWidth( 1.5 )
@@ -78,6 +79,9 @@ QgsSymbolLayerV2* QgsArrowSymbolLayer::create( const QgsStringMap& props )
78
79
if ( props.contains ( " is_curved" ) )
79
80
l->setIsCurved ( props[" is_curved" ].toInt () == 1 );
80
81
82
+ if ( props.contains ( " is_repeated" ) )
83
+ l->setIsRepeated ( props[" is_repeated" ].toInt () == 1 );
84
+
81
85
if ( props.contains ( " head_width" ) )
82
86
l->setHeadWidth ( props[" head_width" ].toDouble () );
83
87
@@ -145,6 +149,7 @@ QgsStringMap QgsArrowSymbolLayer::properties() const
145
149
map[" arrow_start_width_unit_scale" ] = QgsSymbolLayerV2Utils::encodeMapUnitScale ( arrowStartWidthUnitScale () );
146
150
147
151
map[" is_curved" ] = QString::number ( isCurved () ? 1 : 0 );
152
+ map[" is_repeated" ] = QString::number ( isRepeated () ? 1 : 0 );
148
153
149
154
map[" head_width" ] = QString::number ( headWidth () );
150
155
map[" head_width_unit" ] = QgsSymbolLayerV2Utils::encodeOutputUnit ( headWidthUnit () );
@@ -689,52 +694,98 @@ void QgsArrowSymbolLayer::renderPolyline( const QPolygonF& points, QgsSymbolV2Re
689
694
mExpressionScope ->setVariable ( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, 1 );
690
695
if ( isCurved () )
691
696
{
692
- for ( int pIdx = 0 ; pIdx < points.size () - 1 ; pIdx += 2 )
693
- {
694
- mExpressionScope ->setVariable ( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, pIdx + 1 );
695
- _resolveDataDefined ( context );
697
+ _resolveDataDefined ( context );
696
698
697
- if ( points.size () - pIdx >= 3 )
699
+ if ( ! isRepeated () )
700
+ {
701
+ if ( points.size () >= 3 )
698
702
{
699
703
// origin point
700
- QPointF po ( points.at ( pIdx ) );
704
+ QPointF po ( points.at ( 0 ) );
701
705
// middle point
702
- QPointF pm ( points.at ( pIdx + 1 ) );
706
+ QPointF pm ( points.at ( points. size () / 2 ) );
703
707
// destination point
704
- QPointF pd ( points.at ( pIdx + 2 ) );
708
+ QPointF pd ( points.back ( ) );
705
709
706
710
QPolygonF poly = curvedArrow ( po, pm, pd, mScaledArrowStartWidth , mScaledArrowWidth , mScaledHeadWidth , mScaledHeadHeight , mComputedHeadType , mComputedArrowType , mScaledOffset );
707
711
mSymbol ->renderPolygon ( poly, /* rings */ nullptr , context.feature (), context.renderContext () );
708
712
}
709
713
// straight arrow
710
- else if ( points.size () - pIdx == 2 )
714
+ else if ( points.size () == 2 )
711
715
{
712
716
// origin point
713
- QPointF po ( points.at ( pIdx ) );
717
+ QPointF po ( points.at ( 0 ) );
714
718
// destination point
715
- QPointF pd ( points.at ( pIdx + 1 ) );
719
+ QPointF pd ( points.at ( 1 ) );
716
720
717
721
QPolygonF poly = straightArrow ( po, pd, mScaledArrowStartWidth , mScaledArrowWidth , mScaledHeadWidth , mScaledHeadHeight , mComputedHeadType , mComputedArrowType , mScaledOffset );
718
722
mSymbol ->renderPolygon ( poly, /* rings */ nullptr , context.feature (), context.renderContext () );
719
723
}
720
724
}
725
+ else
726
+ {
727
+ for ( int pIdx = 0 ; pIdx < points.size () - 1 ; pIdx += 2 )
728
+ {
729
+ mExpressionScope ->setVariable ( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, pIdx + 1 );
730
+ _resolveDataDefined ( context );
731
+
732
+ if ( points.size () - pIdx >= 3 )
733
+ {
734
+ // origin point
735
+ QPointF po ( points.at ( pIdx ) );
736
+ // middle point
737
+ QPointF pm ( points.at ( pIdx + 1 ) );
738
+ // destination point
739
+ QPointF pd ( points.at ( pIdx + 2 ) );
740
+
741
+ QPolygonF poly = curvedArrow ( po, pm, pd, mScaledArrowStartWidth , mScaledArrowWidth , mScaledHeadWidth , mScaledHeadHeight , mComputedHeadType , mComputedArrowType , mScaledOffset );
742
+ mSymbol ->renderPolygon ( poly, /* rings */ nullptr , context.feature (), context.renderContext () );
743
+ }
744
+ // straight arrow
745
+ else if ( points.size () - pIdx == 2 )
746
+ {
747
+ // origin point
748
+ QPointF po ( points.at ( pIdx ) );
749
+ // destination point
750
+ QPointF pd ( points.at ( pIdx + 1 ) );
751
+
752
+ QPolygonF poly = straightArrow ( po, pd, mScaledArrowStartWidth , mScaledArrowWidth , mScaledHeadWidth , mScaledHeadHeight , mComputedHeadType , mComputedArrowType , mScaledOffset );
753
+ mSymbol ->renderPolygon ( poly, /* rings */ nullptr , context.feature (), context.renderContext () );
754
+ }
755
+ }
756
+ }
721
757
}
722
758
else
723
759
{
724
- // only straight arrows
725
- for ( int pIdx = 0 ; pIdx < points.size () - 1 ; pIdx++ )
760
+ if ( !isRepeated () )
726
761
{
727
- mExpressionScope ->setVariable ( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, pIdx + 1 );
728
762
_resolveDataDefined ( context );
729
763
730
764
// origin point
731
- QPointF po ( points.at ( pIdx ) );
765
+ QPointF po ( points.at ( 0 ) );
732
766
// destination point
733
- QPointF pd ( points.at ( pIdx + 1 ) );
767
+ QPointF pd ( points.back ( ) );
734
768
735
769
QPolygonF poly = straightArrow ( po, pd, mScaledArrowStartWidth , mScaledArrowWidth , mScaledHeadWidth , mScaledHeadHeight , mComputedHeadType , mComputedArrowType , mScaledOffset );
736
770
mSymbol ->renderPolygon ( poly, /* rings */ nullptr , context.feature (), context.renderContext () );
737
771
}
772
+ else
773
+ {
774
+ // only straight arrows
775
+ for ( int pIdx = 0 ; pIdx < points.size () - 1 ; pIdx++ )
776
+ {
777
+ mExpressionScope ->setVariable ( QgsExpressionContext::EXPR_GEOMETRY_POINT_NUM, pIdx + 1 );
778
+ _resolveDataDefined ( context );
779
+
780
+ // origin point
781
+ QPointF po ( points.at ( pIdx ) );
782
+ // destination point
783
+ QPointF pd ( points.at ( pIdx + 1 ) );
784
+
785
+ QPolygonF poly = straightArrow ( po, pd, mScaledArrowStartWidth , mScaledArrowWidth , mScaledHeadWidth , mScaledHeadHeight , mComputedHeadType , mComputedArrowType , mScaledOffset );
786
+ mSymbol ->renderPolygon ( poly, /* rings */ nullptr , context.feature (), context.renderContext () );
787
+ }
788
+ }
738
789
}
739
790
context.renderContext ().expressionContext ().popScope ();
740
791
}
0 commit comments