Skip to content

Commit

Permalink
Avoid some QgsGeometry pointer use in QgsGeometry API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 8, 2016
1 parent 1a4f8f5 commit f9bb230
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions python/core/geometry/qgsgeometry.sip
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class QgsGeometry
@note available in python bindings as addPartGeometry (added in 2.2)
*/
// TODO QGIS 3.0 returns an enum instead of a magic constant
int addPart( const QgsGeometry *newPart /Transfer/ ) /PyName=addPartGeometry/;
int addPart( const QgsGeometry& newPart ) /PyName=addPartGeometry/;

/** Translate this geometry by dx, dy
@return 0 in case of success*/
Expand Down Expand Up @@ -388,7 +388,7 @@ class QgsGeometry
@return 0 in case of success, 1 if geometry has not been split, error else*/
// TODO QGIS 3.0 returns an enum instead of a magic constant
int splitGeometry( const QList<QgsPoint>& splitLine,
QList<QgsGeometry*>&newGeometries /Out/,
QList<QgsGeometry>& newGeometries /Out/,
bool topological,
QList<QgsPoint> &topologyTestPoints /Out/);

Expand Down
19 changes: 9 additions & 10 deletions src/core/geometry/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ QgsGeometry QgsGeometry::collectGeometry( const QList< QgsGeometry >& geometries
}
else
{
QgsGeometry part = QgsGeometry( *git );
collected.addPart( &part );
collected.addPart( *git );
}
}
return collected;
Expand Down Expand Up @@ -731,14 +730,14 @@ int QgsGeometry::addPart( QgsAbstractGeometry* part, QgsWkbTypes::GeometryType g
return QgsGeometryEditUtils::addPart( d->geometry, part );
}

int QgsGeometry::addPart( const QgsGeometry *newPart )
int QgsGeometry::addPart( const QgsGeometry& newPart )
{
if ( !d->geometry || !newPart || !newPart->d || !newPart->d->geometry )
if ( !d->geometry || !newPart.d || !newPart.d->geometry )
{
return 1;
}

return addPart( newPart->d->geometry->clone() );
return addPart( newPart.d->geometry->clone() );
}

int QgsGeometry::addPart( GEOSGeometry *newPart )
Expand Down Expand Up @@ -786,7 +785,7 @@ int QgsGeometry::rotate( double rotation, const QgsPoint& center )
return 0;
}

int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeometry*>& newGeometries, bool topological, QList<QgsPoint> &topologyTestPoints )
int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeometry>& newGeometries, bool topological, QList<QgsPoint> &topologyTestPoints )
{
if ( !d->geometry )
{
Expand All @@ -811,7 +810,7 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome
newGeometries.clear();
for ( int i = 1; i < newGeoms.size(); ++i )
{
newGeometries.push_back( new QgsGeometry( newGeoms.at( i ) ) );
newGeometries.push_back( QgsGeometry( newGeoms.at( i ) ) );
}
}

Expand Down Expand Up @@ -1401,7 +1400,7 @@ QgsGeometry QgsGeometry::offsetCurve( double distance, int segments, JoinStyle j
QgsGeometry first = results.takeAt( 0 );
Q_FOREACH ( const QgsGeometry& result, results )
{
first.addPart( & result );
first.addPart( result );
}
return first;
}
Expand Down Expand Up @@ -1440,7 +1439,7 @@ QgsGeometry QgsGeometry::singleSidedBuffer( double distance, int segments, Buffe
QgsGeometry first = results.takeAt( 0 );
Q_FOREACH ( const QgsGeometry& result, results )
{
first.addPart( & result );
first.addPart( result );
}
return first;
}
Expand Down Expand Up @@ -1480,7 +1479,7 @@ QgsGeometry QgsGeometry::extendLine( double startDistance, double endDistance )
QgsGeometry first = results.takeAt( 0 );
Q_FOREACH ( const QgsGeometry& result, results )
{
first.addPart( & result );
first.addPart( result );
}
return first;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/geometry/qgsgeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class CORE_EXPORT QgsGeometry
@note available in python bindings as addPartGeometry (added in 2.2)
*/
// TODO QGIS 3.0 returns an enum instead of a magic constant
int addPart( const QgsGeometry *newPart );
int addPart( const QgsGeometry& newPart );

/** Translate this geometry by dx, dy
@return 0 in case of success*/
Expand Down Expand Up @@ -432,7 +432,7 @@ class CORE_EXPORT QgsGeometry
@return 0 in case of success, 1 if geometry has not been split, error else*/
// TODO QGIS 3.0 returns an enum instead of a magic constant
int splitGeometry( const QList<QgsPoint>& splitLine,
QList<QgsGeometry*>&newGeometries,
QList<QgsGeometry>& newGeometries,
bool topological,
QList<QgsPoint> &topologyTestPoints );

Expand Down
10 changes: 3 additions & 7 deletions src/core/qgsvectorlayereditutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,8 @@ int QgsVectorLayerEditUtils::splitFeatures( const QList<QgsPoint>& splitLine, bo
{
continue;
}
QList<QgsGeometry*> newGeometries;
QList<QgsGeometry> newGeometries;
QList<QgsPoint> topologyTestPoints;
QgsGeometry* newGeometry = nullptr;
QgsGeometry featureGeom = feat.geometry();
splitFunctionReturn = featureGeom.splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
if ( splitFunctionReturn == 0 )
Expand All @@ -372,9 +371,8 @@ int QgsVectorLayerEditUtils::splitFeatures( const QList<QgsPoint>& splitLine, bo
//insert new features
for ( int i = 0; i < newGeometries.size(); ++i )
{
newGeometry = newGeometries.at( i );
QgsFeature newFeature;
newFeature.setGeometry( *newGeometry );
newFeature.setGeometry( newGeometries.at( i ) );

//use default value where possible for primary key (e.g. autoincrement),
//and use the value from the original (split) feature if not primary key
Expand Down Expand Up @@ -492,7 +490,7 @@ int QgsVectorLayerEditUtils::splitParts( const QList<QgsPoint>& splitLine, bool
QgsFeature feat;
while ( fit.nextFeature( feat ) )
{
QList<QgsGeometry*> newGeometries;
QList<QgsGeometry> newGeometries;
QList<QgsPoint> topologyTestPoints;
QgsGeometry featureGeom = feat.geometry();
splitFunctionReturn = featureGeom.splitGeometry( splitLine, newGeometries, topologicalEditing, topologyTestPoints );
Expand Down Expand Up @@ -550,8 +548,6 @@ int QgsVectorLayerEditUtils::splitParts( const QList<QgsPoint>& splitLine, bool
{
returnCode = splitFunctionReturn;
}

qDeleteAll( newGeometries );
}

if ( numberOfSplittedParts == 0 && L->selectedFeatureCount() > 0 && returnCode == 0 )
Expand Down

0 comments on commit f9bb230

Please sign in to comment.