Skip to content

Commit f1dc709

Browse files
committed
Clear and load in getFeatures()
1 parent c603cfb commit f1dc709

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

python/analysis/auto_generated/vector/geometry_checker/qgsfeaturepool.sip.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The coordinate reference system of this layer.
7979

8080
protected:
8181

82-
void insertFeature( const QgsFeature &feature );
82+
void insertFeature( const QgsFeature &feature, bool skipLock = false );
8383
%Docstring
8484
Inserts a feature into the cache and the spatial index.
8585
To be used by implementations of ``addFeature``.

src/analysis/vector/geometry_checker/qgsfeaturepool.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,22 @@ bool QgsFeaturePool::getFeature( QgsFeatureId id, QgsFeature &feature, QgsFeedba
7070

7171
QgsFeatureIds QgsFeaturePool::getFeatures( const QgsFeatureRequest &request, QgsFeedback *feedback )
7272
{
73+
QgsReadWriteLocker( mCacheLock, QgsReadWriteLocker::Write );
74+
Q_UNUSED( feedback )
75+
Q_ASSERT( QThread::currentThread() == qApp->thread() );
76+
77+
mFeatureCache.clear();
78+
mIndex = QgsSpatialIndex();
79+
7380
QgsFeatureIds fids;
7481

75-
std::unique_ptr<QgsVectorLayerFeatureSource> source = QgsVectorLayerUtils::getFeatureSource( mLayer, feedback );
82+
mFeatureSource = qgis::make_unique<QgsVectorLayerFeatureSource>( mLayer );
7683

77-
QgsFeatureIterator it = source->getFeatures( request );
84+
QgsFeatureIterator it = mFeatureSource->getFeatures( request );
7885
QgsFeature feature;
7986
while ( it.nextFeature( feature ) )
8087
{
81-
insertFeature( feature );
88+
insertFeature( feature, true );
8289
fids << feature.id();
8390
}
8491

@@ -109,9 +116,11 @@ QPointer<QgsVectorLayer> QgsFeaturePool::layerPtr() const
109116
return mLayer;
110117
}
111118

112-
void QgsFeaturePool::insertFeature( const QgsFeature &feature )
119+
void QgsFeaturePool::insertFeature( const QgsFeature &feature, bool skipLock )
113120
{
114-
QgsReadWriteLocker locker( mCacheLock, QgsReadWriteLocker::Write );
121+
QgsReadWriteLocker locker( mCacheLock, QgsReadWriteLocker::Unlocked );
122+
if ( !skipLock )
123+
locker.changeMode( QgsReadWriteLocker::Write );
115124
mFeatureCache.insert( feature.id(), new QgsFeature( feature ) );
116125
QgsFeature indexFeature( feature );
117126
mIndex.addFeature( indexFeature );
@@ -159,6 +168,7 @@ QString QgsFeaturePool::layerName() const
159168

160169
QgsCoordinateReferenceSystem QgsFeaturePool::crs() const
161170
{
171+
QgsReadWriteLocker( mCacheLock, QgsReadWriteLocker::Read );
162172
return mFeatureSource->crs();
163173
}
164174

@@ -169,5 +179,6 @@ QgsWkbTypes::GeometryType QgsFeaturePool::geometryType() const
169179

170180
QString QgsFeaturePool::layerId() const
171181
{
182+
QgsReadWriteLocker( mCacheLock, QgsReadWriteLocker::Read );
172183
return mFeatureSource->id();
173184
}

src/analysis/vector/geometry_checker/qgsfeaturepool.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
128128
* Inserts a feature into the cache and the spatial index.
129129
* To be used by implementations of ``addFeature``.
130130
*/
131-
void insertFeature( const QgsFeature &feature );
131+
void insertFeature( const QgsFeature &feature, bool skipLock = false );
132132

133133
/**
134134
* Changes a feature in the cache and the spatial index.

0 commit comments

Comments
 (0)