Skip to content

Commit 0c6056b

Browse files
committedMay 7, 2014
Manually merge PR #1290 (fixes #9861)
2 parents 0a82f37 + ddecf7e commit 0c6056b

File tree

3 files changed

+61
-20
lines changed

3 files changed

+61
-20
lines changed
 

‎src/core/symbology-ng/qgslinesymbollayerv2.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,9 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
275275
else
276276
{
277277
double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale );
278-
p->drawPolyline( ::offsetLine( points, scaledOffset ) );
278+
QList<QPolygonF> mline = ::offsetLine( points, scaledOffset );
279+
for ( int part = 0; part < mline.count(); ++part )
280+
p->drawPolyline( mline[ part ] );
279281
}
280282
}
281283

@@ -777,13 +779,19 @@ void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
777779
}
778780
else
779781
{
780-
QPolygonF points2 = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale ) );
781-
if ( placement == Interval )
782-
renderPolylineInterval( points2, context );
783-
else if ( placement == CentralPoint )
784-
renderPolylineCentral( points2, context );
785-
else
786-
renderPolylineVertex( points2, context, placement );
782+
QList<QPolygonF> mline = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale ) );
783+
784+
for ( int part = 0; part < mline.count(); ++part )
785+
{
786+
const QPolygonF &points2 = mline[ part ];
787+
788+
if ( placement == Interval )
789+
renderPolylineInterval( points2, context );
790+
else if ( placement == CentralPoint )
791+
renderPolylineCentral( points2, context );
792+
else
793+
renderPolylineVertex( points2, context, placement );
794+
}
787795
}
788796
}
789797

‎src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -662,10 +662,15 @@ static QPointF linesIntersection( QPointF p1, double t1, QPointF p2, double t2 )
662662
#endif
663663

664664

665-
QPolygonF offsetLine( QPolygonF polyline, double dist )
665+
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
666666
{
667+
QList<QPolygonF> resultLine;
668+
667669
if ( polyline.count() < 2 )
668-
return polyline;
670+
{
671+
resultLine.append( polyline );
672+
return resultLine;
673+
}
669674

670675
QPolygonF newLine;
671676

@@ -688,22 +693,48 @@ QPolygonF offsetLine( QPolygonF polyline, double dist )
688693
if ( offsetGeom )
689694
{
690695
tempGeometry->fromGeos( offsetGeom );
691-
tempPolyline = tempGeometry->asPolyline();
692696

693-
pointCount = tempPolyline.count();
694-
newLine.resize( pointCount );
697+
if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBLineString )
698+
{
699+
tempPolyline = tempGeometry->asPolyline();
695700

696-
QgsPoint* tempPtr2 = tempPolyline.data();
697-
for ( i = 0; i < pointCount; ++i, tempPtr2++ ) newLine[i] = QPointF( tempPtr2->x(), tempPtr2->y() );
701+
pointCount = tempPolyline.count();
702+
newLine.resize( pointCount );
698703

699-
delete tempGeometry;
700-
return newLine;
704+
QgsPoint* tempPtr2 = tempPolyline.data();
705+
for ( i = 0; i < pointCount; ++i, tempPtr2++ ) newLine[i] = QPointF( tempPtr2->x(), tempPtr2->y() );
706+
resultLine.append( newLine );
707+
708+
delete tempGeometry;
709+
return resultLine;
710+
}
711+
else if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBMultiLineString )
712+
{
713+
QgsMultiPolyline tempMPolyline = tempGeometry->asMultiPolyline();
714+
715+
for ( int part = 0; part < tempMPolyline.count(); ++part )
716+
{
717+
tempPolyline = tempMPolyline[ part ];
718+
719+
pointCount = tempPolyline.count();
720+
newLine.resize( pointCount );
721+
722+
QgsPoint* tempPtr2 = tempPolyline.data();
723+
for ( i = 0; i < pointCount; ++i, tempPtr2++ ) newLine[i] = QPointF( tempPtr2->x(), tempPtr2->y() );
724+
resultLine.append( newLine );
725+
726+
newLine = QPolygonF();
727+
}
728+
delete tempGeometry;
729+
return resultLine;
730+
}
701731
}
702732
delete tempGeometry;
703733
}
704734

705735
// returns original polyline when 'GEOSOffsetCurve' fails!
706-
return polyline;
736+
resultLine.append( polyline );
737+
return resultLine;
707738

708739
#else
709740

@@ -741,7 +772,9 @@ QPolygonF offsetLine( QPolygonF polyline, double dist )
741772
// last line segment:
742773
pt_new = offsetPoint( p2, angle + M_PI / 2, dist );
743774
newLine.append( pt_new );
744-
return newLine;
775+
776+
resultLine.append( newLine );
777+
return resultLine;
745778

746779
#endif
747780
}

‎src/core/symbology-ng/qgssymbollayerv2utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
291291
class QPolygonF;
292292

293293
//! calculate line shifted by a specified distance
294-
QPolygonF offsetLine( QPolygonF polyline, double dist );
294+
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist );
295295

296296

297297
#endif

0 commit comments

Comments
 (0)
Please sign in to comment.