Skip to content

Commit e13a4aa

Browse files
committedOct 13, 2017
Cleanup some loops
1 parent b922166 commit e13a4aa

File tree

1 file changed

+37
-44
lines changed

1 file changed

+37
-44
lines changed
 

‎src/core/geometry/qgsgeometry.cpp

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,16 @@ QgsGeometry QgsGeometry::collectGeometry( const QList< QgsGeometry > &geometries
229229
{
230230
QgsGeometry collected;
231231

232-
QList< QgsGeometry >::const_iterator git = geometries.constBegin();
233-
for ( ; git != geometries.constEnd(); ++git )
232+
for ( const QgsGeometry &g : geometries )
234233
{
235234
if ( collected.isNull() )
236235
{
237-
collected = QgsGeometry( *git );
236+
collected = g;
238237
collected.convertToMultiType();
239238
}
240239
else
241240
{
242-
collected.addPart( *git );
241+
collected.addPart( g );
243242
}
244243
}
245244
return collected;
@@ -2133,10 +2132,9 @@ QPolygonF QgsGeometry::asQPolygonF() const
21332132
return result;
21342133
}
21352134

2136-
QgsPolyline::const_iterator lineIt = polyline.constBegin();
2137-
for ( ; lineIt != polyline.constEnd(); ++lineIt )
2135+
for ( const QgsPointXY &p : qgsAsConst( polyline ) )
21382136
{
2139-
result << lineIt->toQPointF();
2137+
result << p.toQPointF();
21402138
}
21412139
return result;
21422140
}
@@ -2245,12 +2243,11 @@ QgsGeometry QgsGeometry::unaryUnion( const QList<QgsGeometry> &geometries )
22452243
QgsGeos geos( nullptr );
22462244

22472245
QList<QgsAbstractGeometry *> geomV2List;
2248-
QList<QgsGeometry>::const_iterator it = geometries.constBegin();
2249-
for ( ; it != geometries.constEnd(); ++it )
2246+
for ( const QgsGeometry &g : geometries )
22502247
{
2251-
if ( !( ( *it ).isNull() ) )
2248+
if ( !( g.isNull() ) )
22522249
{
2253-
geomV2List.append( ( *it ).geometry() );
2250+
geomV2List.append( g.geometry() );
22542251
}
22552252
}
22562253

@@ -2266,12 +2263,11 @@ QgsGeometry QgsGeometry::polygonize( const QList<QgsGeometry> &geometryList )
22662263
QgsGeos geos( nullptr );
22672264

22682265
QList<QgsAbstractGeometry *> geomV2List;
2269-
QList<QgsGeometry>::const_iterator it = geometryList.constBegin();
2270-
for ( ; it != geometryList.constEnd(); ++it )
2266+
for ( const QgsGeometry &g : geometryList )
22712267
{
2272-
if ( !( ( *it ).isNull() ) )
2268+
if ( !( g.isNull() ) )
22732269
{
2274-
geomV2List.append( ( *it ).geometry() );
2270+
geomV2List.append( g.geometry() );
22752271
}
22762272
}
22772273

@@ -2512,20 +2508,18 @@ QString QgsGeometry::lastError() const
25122508
void QgsGeometry::convertPointList( const QList<QgsPointXY> &input, QgsPointSequence &output )
25132509
{
25142510
output.clear();
2515-
QList<QgsPointXY>::const_iterator it = input.constBegin();
2516-
for ( ; it != input.constEnd(); ++it )
2511+
for ( const QgsPointXY &p : input )
25172512
{
2518-
output.append( QgsPoint( it->x(), it->y() ) );
2513+
output.append( QgsPoint( p ) );
25192514
}
25202515
}
25212516

25222517
void QgsGeometry::convertPointList( const QgsPointSequence &input, QList<QgsPointXY> &output )
25232518
{
25242519
output.clear();
2525-
QgsPointSequence::const_iterator it = input.constBegin();
2526-
for ( ; it != input.constEnd(); ++it )
2520+
for ( const QgsPoint &p : input )
25272521
{
2528-
output.append( QgsPointXY( it->x(), it->y() ) );
2522+
output.append( QgsPointXY( p.x(), p.y() ) );
25292523
}
25302524
}
25312525

@@ -2595,10 +2589,9 @@ QgsPolygon QgsGeometry::createPolygonFromQPolygonF( const QPolygonF &polygon )
25952589
QgsPolyline QgsGeometry::createPolylineFromQPolygonF( const QPolygonF &polygon )
25962590
{
25972591
QgsPolyline result;
2598-
QPolygonF::const_iterator it = polygon.constBegin();
2599-
for ( ; it != polygon.constEnd(); ++it )
2592+
for ( const QPointF &p : polygon )
26002593
{
2601-
result.append( QgsPointXY( *it ) );
2594+
result.append( QgsPointXY( p ) );
26022595
}
26032596
return result;
26042597
}
@@ -2857,11 +2850,11 @@ QgsGeometry QgsGeometry::convertToPoint( bool destMultipart ) const
28572850
// input geometry is multipart
28582851
if ( isMultipart() )
28592852
{
2860-
QgsMultiPolyline multiLine = asMultiPolyline();
2853+
const QgsMultiPolyline multiLine = asMultiPolyline();
28612854
QgsMultiPoint multiPoint;
2862-
for ( QgsMultiPolyline::const_iterator multiLineIt = multiLine.constBegin(); multiLineIt != multiLine.constEnd(); ++multiLineIt )
2863-
for ( QgsPolyline::const_iterator lineIt = ( *multiLineIt ).constBegin(); lineIt != ( *multiLineIt ).constEnd(); ++lineIt )
2864-
multiPoint << *lineIt;
2855+
for ( const QgsPolyline &l : multiLine )
2856+
for ( const QgsPointXY &p : l )
2857+
multiPoint << p;
28652858
return fromMultiPoint( multiPoint );
28662859
}
28672860
// input geometry is not multipart: copy directly the line into a multipoint
@@ -2883,22 +2876,22 @@ QgsGeometry QgsGeometry::convertToPoint( bool destMultipart ) const
28832876
// input geometry is multipart: make a multipoint from multipolygon
28842877
if ( isMultipart() )
28852878
{
2886-
QgsMultiPolygon multiPolygon = asMultiPolygon();
2879+
const QgsMultiPolygon multiPolygon = asMultiPolygon();
28872880
QgsMultiPoint multiPoint;
2888-
for ( QgsMultiPolygon::const_iterator polygonIt = multiPolygon.constBegin(); polygonIt != multiPolygon.constEnd(); ++polygonIt )
2889-
for ( QgsMultiPolyline::const_iterator multiLineIt = ( *polygonIt ).constBegin(); multiLineIt != ( *polygonIt ).constEnd(); ++multiLineIt )
2890-
for ( QgsPolyline::const_iterator lineIt = ( *multiLineIt ).constBegin(); lineIt != ( *multiLineIt ).constEnd(); ++lineIt )
2891-
multiPoint << *lineIt;
2881+
for ( const QgsPolygon &poly : multiPolygon )
2882+
for ( const QgsPolyline &line : poly )
2883+
for ( const QgsPointXY &pt : line )
2884+
multiPoint << pt;
28922885
return fromMultiPoint( multiPoint );
28932886
}
28942887
// input geometry is not multipart: make a multipoint from polygon
28952888
else
28962889
{
2897-
QgsPolygon polygon = asPolygon();
2890+
const QgsPolygon polygon = asPolygon();
28982891
QgsMultiPoint multiPoint;
2899-
for ( QgsMultiPolyline::const_iterator multiLineIt = polygon.constBegin(); multiLineIt != polygon.constEnd(); ++multiLineIt )
2900-
for ( QgsPolyline::const_iterator lineIt = ( *multiLineIt ).constBegin(); lineIt != ( *multiLineIt ).constEnd(); ++lineIt )
2901-
multiPoint << *lineIt;
2892+
for ( const QgsPolyline &line : polygon )
2893+
for ( const QgsPointXY &pt : line )
2894+
multiPoint << pt;
29022895
return fromMultiPoint( multiPoint );
29032896
}
29042897
}
@@ -2959,11 +2952,11 @@ QgsGeometry QgsGeometry::convertToLine( bool destMultipart ) const
29592952
// input geometry is multipolygon
29602953
if ( isMultipart() )
29612954
{
2962-
QgsMultiPolygon multiPolygon = asMultiPolygon();
2955+
const QgsMultiPolygon multiPolygon = asMultiPolygon();
29632956
QgsMultiPolyline multiLine;
2964-
for ( QgsMultiPolygon::const_iterator polygonIt = multiPolygon.constBegin(); polygonIt != multiPolygon.constEnd(); ++polygonIt )
2965-
for ( QgsMultiPolyline::const_iterator multiLineIt = ( *polygonIt ).constBegin(); multiLineIt != ( *polygonIt ).constEnd(); ++multiLineIt )
2966-
multiLine << *multiLineIt;
2957+
for ( const QgsPolygon &poly : multiPolygon )
2958+
for ( const QgsPolyline &line : poly )
2959+
multiLine << line;
29672960

29682961
if ( destMultipart )
29692962
{
@@ -2987,10 +2980,10 @@ QgsGeometry QgsGeometry::convertToLine( bool destMultipart ) const
29872980
// TODO: would it be better to remove rings?
29882981
if ( destMultipart )
29892982
{
2990-
QgsPolygon polygon = asPolygon();
2983+
const QgsPolygon polygon = asPolygon();
29912984
QgsMultiPolyline multiLine;
2992-
for ( QgsMultiPolyline::const_iterator multiLineIt = polygon.constBegin(); multiLineIt != polygon.constEnd(); ++multiLineIt )
2993-
multiLine << *multiLineIt;
2985+
for ( const QgsPolyline &line : polygon )
2986+
multiLine << line;
29942987
return fromMultiPolyline( multiLine );
29952988
}
29962989
}

0 commit comments

Comments
 (0)
Please sign in to comment.