Skip to content

Commit

Permalink
Manually merge PR #1290 (fixes #9861)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed May 7, 2014
2 parents 0a82f37 + ddecf7e commit 0c6056b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
24 changes: 16 additions & 8 deletions src/core/symbology-ng/qgslinesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
else
{
double scaledOffset = offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale );
p->drawPolyline( ::offsetLine( points, scaledOffset ) );
QList<QPolygonF> mline = ::offsetLine( points, scaledOffset );
for ( int part = 0; part < mline.count(); ++part )
p->drawPolyline( mline[ part ] );
}
}

Expand Down Expand Up @@ -777,13 +779,19 @@ void QgsMarkerLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
}
else
{
QPolygonF points2 = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale ) );
if ( placement == Interval )
renderPolylineInterval( points2, context );
else if ( placement == CentralPoint )
renderPolylineCentral( points2, context );
else
renderPolylineVertex( points2, context, placement );
QList<QPolygonF> mline = ::offsetLine( points, offset * QgsSymbolLayerV2Utils::lineWidthScaleFactor( context.renderContext(), mOffsetUnit, mOffsetMapUnitScale ) );

for ( int part = 0; part < mline.count(); ++part )
{
const QPolygonF &points2 = mline[ part ];

if ( placement == Interval )
renderPolylineInterval( points2, context );
else if ( placement == CentralPoint )
renderPolylineCentral( points2, context );
else
renderPolylineVertex( points2, context, placement );
}
}
}

Expand Down
55 changes: 44 additions & 11 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,10 +662,15 @@ static QPointF linesIntersection( QPointF p1, double t1, QPointF p2, double t2 )
#endif


QPolygonF offsetLine( QPolygonF polyline, double dist )
QList<QPolygonF> offsetLine( QPolygonF polyline, double dist )
{
QList<QPolygonF> resultLine;

if ( polyline.count() < 2 )
return polyline;
{
resultLine.append( polyline );
return resultLine;
}

QPolygonF newLine;

Expand All @@ -688,22 +693,48 @@ QPolygonF offsetLine( QPolygonF polyline, double dist )
if ( offsetGeom )
{
tempGeometry->fromGeos( offsetGeom );
tempPolyline = tempGeometry->asPolyline();

pointCount = tempPolyline.count();
newLine.resize( pointCount );
if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBLineString )
{
tempPolyline = tempGeometry->asPolyline();

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

delete tempGeometry;
return newLine;
QgsPoint* tempPtr2 = tempPolyline.data();
for ( i = 0; i < pointCount; ++i, tempPtr2++ ) newLine[i] = QPointF( tempPtr2->x(), tempPtr2->y() );
resultLine.append( newLine );

delete tempGeometry;
return resultLine;
}
else if ( QGis::flatType( tempGeometry->wkbType() ) == QGis::WKBMultiLineString )
{
QgsMultiPolyline tempMPolyline = tempGeometry->asMultiPolyline();

for ( int part = 0; part < tempMPolyline.count(); ++part )
{
tempPolyline = tempMPolyline[ part ];

pointCount = tempPolyline.count();
newLine.resize( pointCount );

QgsPoint* tempPtr2 = tempPolyline.data();
for ( i = 0; i < pointCount; ++i, tempPtr2++ ) newLine[i] = QPointF( tempPtr2->x(), tempPtr2->y() );
resultLine.append( newLine );

newLine = QPolygonF();
}
delete tempGeometry;
return resultLine;
}
}
delete tempGeometry;
}

// returns original polyline when 'GEOSOffsetCurve' fails!
return polyline;
resultLine.append( polyline );
return resultLine;

#else

Expand Down Expand Up @@ -741,7 +772,9 @@ QPolygonF offsetLine( QPolygonF polyline, double dist )
// last line segment:
pt_new = offsetPoint( p2, angle + M_PI / 2, dist );
newLine.append( pt_new );
return newLine;

resultLine.append( newLine );
return resultLine;

#endif
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgssymbollayerv2utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
class QPolygonF;

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


#endif
Expand Down

0 comments on commit 0c6056b

Please sign in to comment.