@@ -388,7 +388,7 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs
388
388
destination = layer->id ();
389
389
390
390
// this is a factory, so we need to return a proxy
391
- std::unique_ptr< QgsProxyFeatureSink > sink ( new QgsProxyFeatureSink ( layer->dataProvider () ) );
391
+ std::unique_ptr< QgsProcessingFeatureSink > sink ( new QgsProcessingFeatureSink ( layer->dataProvider (), destination, context ) );
392
392
context.temporaryLayerStore ()->addMapLayer ( layer.release () );
393
393
394
394
return sink.release ();
@@ -415,7 +415,7 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs
415
415
throw QgsProcessingException ( QObject::tr ( " Could not create layer %1: %2" ).arg ( destination, writer->errorMessage () ) );
416
416
}
417
417
destination = finalFileName;
418
- return writer.release ();
418
+ return new QgsProcessingFeatureSink ( writer.release (), destination, context, true );
419
419
}
420
420
else
421
421
{
@@ -434,7 +434,7 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, Qgs
434
434
destination = layer->id ();
435
435
436
436
context.temporaryLayerStore ()->addMapLayer ( layer.release () );
437
- return exporter.release ();
437
+ return new QgsProcessingFeatureSink ( exporter.release (), destination, context, true );
438
438
}
439
439
}
440
440
return nullptr ;
@@ -750,3 +750,44 @@ QgsExpressionContextScope *QgsProcessingFeatureSource::createExpressionContextSc
750
750
}
751
751
return expressionContextScope;
752
752
}
753
+
754
+
755
+ //
756
+ // QgsProcessingFeatureSink
757
+ //
758
+ QgsProcessingFeatureSink::QgsProcessingFeatureSink ( QgsFeatureSink *originalSink, const QString &sinkName, QgsProcessingContext &context, bool ownsOriginalSink )
759
+ : QgsProxyFeatureSink( originalSink )
760
+ , mContext( context )
761
+ , mSinkName( sinkName )
762
+ , mOwnsSink( ownsOriginalSink )
763
+ {}
764
+
765
+ QgsProcessingFeatureSink::~QgsProcessingFeatureSink ()
766
+ {
767
+ if ( mOwnsSink )
768
+ delete destinationSink ();
769
+ }
770
+
771
+ bool QgsProcessingFeatureSink::addFeature ( QgsFeature &feature, QgsFeatureSink::Flags flags )
772
+ {
773
+ bool result = QgsProxyFeatureSink::addFeature ( feature, flags );
774
+ if ( !result )
775
+ mContext .feedback ()->reportError ( QObject::tr ( " Feature could not be written to %1" ).arg ( mSinkName ) );
776
+ return result;
777
+ }
778
+
779
+ bool QgsProcessingFeatureSink::addFeatures ( QgsFeatureList &features, QgsFeatureSink::Flags flags )
780
+ {
781
+ bool result = QgsProxyFeatureSink::addFeatures ( features, flags );
782
+ if ( !result )
783
+ mContext .feedback ()->reportError ( QObject::tr ( " %1 feature(s) could not be written to %2" ).arg ( features.count () ).arg ( mSinkName ) );
784
+ return result;
785
+ }
786
+
787
+ bool QgsProcessingFeatureSink::addFeatures ( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags )
788
+ {
789
+ bool result = !QgsProxyFeatureSink::addFeatures ( iterator, flags );
790
+ if ( !result )
791
+ mContext .feedback ()->reportError ( QObject::tr ( " Features could not be written to %2" ).arg ( mSinkName ) );
792
+ return result;
793
+ }
0 commit comments