@@ -224,7 +224,9 @@ bool QgsGeometryEditUtils::deletePart( QgsAbstractGeometry* geom, int partNum )
224
224
return c->removeGeometry ( partNum );
225
225
}
226
226
227
- QgsAbstractGeometry* QgsGeometryEditUtils::avoidIntersections ( const QgsAbstractGeometry& geom, QHash<QgsVectorLayer *, QSet<QgsFeatureId> > ignoreFeatures )
227
+ QgsAbstractGeometry* QgsGeometryEditUtils::avoidIntersections ( const QgsAbstractGeometry& geom,
228
+ const QList<QgsVectorLayer*>& avoidIntersectionsLayers,
229
+ QHash<QgsVectorLayer *, QSet<QgsFeatureId> > ignoreFeatures )
228
230
{
229
231
QScopedPointer<QgsGeometryEngine> geomEngine ( QgsGeometry::createGeometryEngine ( &geom ) );
230
232
if ( geomEngine.isNull () )
@@ -240,39 +242,32 @@ QgsAbstractGeometry* QgsGeometryEditUtils::avoidIntersections( const QgsAbstract
240
242
return nullptr ;
241
243
}
242
244
243
- QStringList avoidIntersectionsList = QgsProject::instance ()->avoidIntersectionsList ();
244
- if ( avoidIntersectionsList.isEmpty () )
245
+ if ( avoidIntersectionsLayers.isEmpty () )
245
246
return nullptr ; // no intersections stored in project does not mean error
246
247
247
248
QList< QgsAbstractGeometry* > nearGeometries;
248
249
249
250
// go through list, convert each layer to vector layer and call QgsVectorLayer::removePolygonIntersections for each
250
- QgsVectorLayer* currentLayer = nullptr ;
251
- QStringList::const_iterator aIt = avoidIntersectionsList.constBegin ();
252
- for ( ; aIt != avoidIntersectionsList.constEnd (); ++aIt )
251
+ Q_FOREACH ( QgsVectorLayer* currentLayer, avoidIntersectionsLayers )
253
252
{
254
- currentLayer = dynamic_cast <QgsVectorLayer*>( QgsProject::instance ()->mapLayer ( *aIt ) );
255
- if ( currentLayer )
253
+ QgsFeatureIds ignoreIds;
254
+ QHash<QgsVectorLayer*, QSet<qint64> >::const_iterator ignoreIt = ignoreFeatures.find ( currentLayer );
255
+ if ( ignoreIt != ignoreFeatures.constEnd () )
256
+ ignoreIds = ignoreIt.value ();
257
+
258
+ QgsFeatureIterator fi = currentLayer->getFeatures ( QgsFeatureRequest ( geom.boundingBox () )
259
+ .setFlags ( QgsFeatureRequest::ExactIntersect )
260
+ .setSubsetOfAttributes ( QgsAttributeList () ) );
261
+ QgsFeature f;
262
+ while ( fi.nextFeature ( f ) )
256
263
{
257
- QgsFeatureIds ignoreIds;
258
- QHash<QgsVectorLayer*, QSet<qint64> >::const_iterator ignoreIt = ignoreFeatures.find ( currentLayer );
259
- if ( ignoreIt != ignoreFeatures.constEnd () )
260
- ignoreIds = ignoreIt.value ();
261
-
262
- QgsFeatureIterator fi = currentLayer->getFeatures ( QgsFeatureRequest ( geom.boundingBox () )
263
- .setFlags ( QgsFeatureRequest::ExactIntersect )
264
- .setSubsetOfAttributes ( QgsAttributeList () ) );
265
- QgsFeature f;
266
- while ( fi.nextFeature ( f ) )
267
- {
268
- if ( ignoreIds.contains ( f.id () ) )
269
- continue ;
264
+ if ( ignoreIds.contains ( f.id () ) )
265
+ continue ;
270
266
271
- if ( !f.hasGeometry () )
272
- continue ;
267
+ if ( !f.hasGeometry () )
268
+ continue ;
273
269
274
- nearGeometries << f.geometry ().geometry ()->clone ();
275
- }
270
+ nearGeometries << f.geometry ().geometry ()->clone ();
276
271
}
277
272
}
278
273
0 commit comments