2121#include " qgsrectangle.h"
2222#include " qgslogger.h"
2323#include " qgsfeaturesource.h"
24+ #include " qgsfeedback.h"
2425
2526#include " SpatialIndex.h"
2627
@@ -92,9 +93,10 @@ class QgsFeatureIteratorDataStream : public IDataStream
9293{
9394 public:
9495 // ! constructor - needs to load all data to a vector for later access when bulk loading
95- explicit QgsFeatureIteratorDataStream ( const QgsFeatureIterator &fi )
96+ explicit QgsFeatureIteratorDataStream ( const QgsFeatureIterator &fi, QgsFeedback *feedback = nullptr )
9697 : mFi( fi )
9798 , mNextData( nullptr )
99+ , mFeedback( feedback )
98100 {
99101 readNextEntry ();
100102 }
@@ -107,6 +109,9 @@ class QgsFeatureIteratorDataStream : public IDataStream
107109 // ! returns a pointer to the next entry in the stream or 0 at the end of the stream.
108110 IData *getNext () override
109111 {
112+ if ( mFeedback && mFeedback ->isCanceled () )
113+ return nullptr ;
114+
110115 RTree::Data *ret = mNextData ;
111116 mNextData = nullptr ;
112117 readNextEntry ();
@@ -141,6 +146,7 @@ class QgsFeatureIteratorDataStream : public IDataStream
141146 private:
142147 QgsFeatureIterator mFi ;
143148 RTree::Data *mNextData = nullptr ;
149+ QgsFeedback *mFeedback = nullptr ;
144150};
145151
146152
@@ -157,9 +163,9 @@ class QgsSpatialIndexData : public QSharedData
157163 initTree ();
158164 }
159165
160- explicit QgsSpatialIndexData ( const QgsFeatureIterator &fi )
166+ explicit QgsSpatialIndexData ( const QgsFeatureIterator &fi, QgsFeedback *feedback = nullptr )
161167 {
162- QgsFeatureIteratorDataStream fids ( fi );
168+ QgsFeatureIteratorDataStream fids ( fi, feedback );
163169 initTree ( &fids );
164170 }
165171
@@ -224,14 +230,14 @@ QgsSpatialIndex::QgsSpatialIndex()
224230 d = new QgsSpatialIndexData;
225231}
226232
227- QgsSpatialIndex::QgsSpatialIndex ( const QgsFeatureIterator &fi )
233+ QgsSpatialIndex::QgsSpatialIndex ( const QgsFeatureIterator &fi, QgsFeedback *feedback )
228234{
229- d = new QgsSpatialIndexData ( fi );
235+ d = new QgsSpatialIndexData ( fi, feedback );
230236}
231237
232- QgsSpatialIndex::QgsSpatialIndex ( const QgsFeatureSource &source )
238+ QgsSpatialIndex::QgsSpatialIndex ( const QgsFeatureSource &source, QgsFeedback *feedback )
233239{
234- d = new QgsSpatialIndexData ( source.getFeatures ( QgsFeatureRequest ().setSubsetOfAttributes ( QgsAttributeList () ) ) );
240+ d = new QgsSpatialIndexData ( source.getFeatures ( QgsFeatureRequest ().setSubsetOfAttributes ( QgsAttributeList () ) ), feedback );
235241}
236242
237243QgsSpatialIndex::QgsSpatialIndex ( const QgsSpatialIndex &other ) // NOLINT
0 commit comments