@@ -70,15 +70,22 @@ bool QgsFeaturePool::getFeature( QgsFeatureId id, QgsFeature &feature, QgsFeedba
70
70
71
71
QgsFeatureIds QgsFeaturePool::getFeatures ( const QgsFeatureRequest &request, QgsFeedback *feedback )
72
72
{
73
+ QgsReadWriteLocker ( mCacheLock , QgsReadWriteLocker::Write );
74
+ Q_UNUSED ( feedback )
75
+ Q_ASSERT ( QThread::currentThread () == qApp->thread () );
76
+
77
+ mFeatureCache .clear ();
78
+ mIndex = QgsSpatialIndex ();
79
+
73
80
QgsFeatureIds fids;
74
81
75
- std::unique_ptr<QgsVectorLayerFeatureSource> source = QgsVectorLayerUtils::getFeatureSource ( mLayer , feedback );
82
+ mFeatureSource = qgis::make_unique<QgsVectorLayerFeatureSource> ( mLayer );
76
83
77
- QgsFeatureIterator it = source ->getFeatures ( request );
84
+ QgsFeatureIterator it = mFeatureSource ->getFeatures ( request );
78
85
QgsFeature feature;
79
86
while ( it.nextFeature ( feature ) )
80
87
{
81
- insertFeature ( feature );
88
+ insertFeature ( feature, true );
82
89
fids << feature.id ();
83
90
}
84
91
@@ -109,9 +116,11 @@ QPointer<QgsVectorLayer> QgsFeaturePool::layerPtr() const
109
116
return mLayer ;
110
117
}
111
118
112
- void QgsFeaturePool::insertFeature ( const QgsFeature &feature )
119
+ void QgsFeaturePool::insertFeature ( const QgsFeature &feature, bool skipLock )
113
120
{
114
- QgsReadWriteLocker locker ( mCacheLock , QgsReadWriteLocker::Write );
121
+ QgsReadWriteLocker locker ( mCacheLock , QgsReadWriteLocker::Unlocked );
122
+ if ( !skipLock )
123
+ locker.changeMode ( QgsReadWriteLocker::Write );
115
124
mFeatureCache .insert ( feature.id (), new QgsFeature ( feature ) );
116
125
QgsFeature indexFeature ( feature );
117
126
mIndex .addFeature ( indexFeature );
@@ -159,6 +168,7 @@ QString QgsFeaturePool::layerName() const
159
168
160
169
QgsCoordinateReferenceSystem QgsFeaturePool::crs () const
161
170
{
171
+ QgsReadWriteLocker ( mCacheLock , QgsReadWriteLocker::Read );
162
172
return mFeatureSource ->crs ();
163
173
}
164
174
@@ -169,5 +179,6 @@ QgsWkbTypes::GeometryType QgsFeaturePool::geometryType() const
169
179
170
180
QString QgsFeaturePool::layerId () const
171
181
{
182
+ QgsReadWriteLocker ( mCacheLock , QgsReadWriteLocker::Read );
172
183
return mFeatureSource ->id ();
173
184
}
0 commit comments