mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-18 00:03:05 -04:00
Clear and load in getFeatures()
This commit is contained in:
parent
9a839c97f3
commit
60512e92df
@ -83,7 +83,7 @@ The coordinate reference system of this layer.
|
||||
|
||||
protected:
|
||||
|
||||
void insertFeature( const QgsFeature &feature );
|
||||
void insertFeature( const QgsFeature &feature, bool skipLock = false );
|
||||
%Docstring
|
||||
Inserts a feature into the cache and the spatial index.
|
||||
To be used by implementations of ``addFeature``.
|
||||
|
@ -70,15 +70,22 @@ bool QgsFeaturePool::getFeature( QgsFeatureId id, QgsFeature &feature, QgsFeedba
|
||||
|
||||
QgsFeatureIds QgsFeaturePool::getFeatures( const QgsFeatureRequest &request, QgsFeedback *feedback )
|
||||
{
|
||||
QgsReadWriteLocker( mCacheLock, QgsReadWriteLocker::Write );
|
||||
Q_UNUSED( feedback )
|
||||
Q_ASSERT( QThread::currentThread() == qApp->thread() );
|
||||
|
||||
mFeatureCache.clear();
|
||||
mIndex = QgsSpatialIndex();
|
||||
|
||||
QgsFeatureIds fids;
|
||||
|
||||
std::unique_ptr<QgsVectorLayerFeatureSource> source = QgsVectorLayerUtils::getFeatureSource( mLayer, feedback );
|
||||
mFeatureSource = qgis::make_unique<QgsVectorLayerFeatureSource>( mLayer );
|
||||
|
||||
QgsFeatureIterator it = source->getFeatures( request );
|
||||
QgsFeatureIterator it = mFeatureSource->getFeatures( request );
|
||||
QgsFeature feature;
|
||||
while ( it.nextFeature( feature ) )
|
||||
{
|
||||
insertFeature( feature );
|
||||
insertFeature( feature, true );
|
||||
fids << feature.id();
|
||||
}
|
||||
|
||||
@ -109,9 +116,11 @@ QPointer<QgsVectorLayer> QgsFeaturePool::layerPtr() const
|
||||
return mLayer;
|
||||
}
|
||||
|
||||
void QgsFeaturePool::insertFeature( const QgsFeature &feature )
|
||||
void QgsFeaturePool::insertFeature( const QgsFeature &feature, bool skipLock )
|
||||
{
|
||||
QgsReadWriteLocker locker( mCacheLock, QgsReadWriteLocker::Write );
|
||||
QgsReadWriteLocker locker( mCacheLock, QgsReadWriteLocker::Unlocked );
|
||||
if ( !skipLock )
|
||||
locker.changeMode( QgsReadWriteLocker::Write );
|
||||
mFeatureCache.insert( feature.id(), new QgsFeature( feature ) );
|
||||
QgsFeature indexFeature( feature );
|
||||
mIndex.addFeature( indexFeature );
|
||||
@ -159,6 +168,7 @@ QString QgsFeaturePool::layerName() const
|
||||
|
||||
QgsCoordinateReferenceSystem QgsFeaturePool::crs() const
|
||||
{
|
||||
QgsReadWriteLocker( mCacheLock, QgsReadWriteLocker::Read );
|
||||
return mFeatureSource->crs();
|
||||
}
|
||||
|
||||
@ -169,5 +179,6 @@ QgsWkbTypes::GeometryType QgsFeaturePool::geometryType() const
|
||||
|
||||
QString QgsFeaturePool::layerId() const
|
||||
{
|
||||
QgsReadWriteLocker( mCacheLock, QgsReadWriteLocker::Read );
|
||||
return mFeatureSource->id();
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
|
||||
* Inserts a feature into the cache and the spatial index.
|
||||
* To be used by implementations of ``addFeature``.
|
||||
*/
|
||||
void insertFeature( const QgsFeature &feature );
|
||||
void insertFeature( const QgsFeature &feature, bool skipLock = false );
|
||||
|
||||
/**
|
||||
* Changes a feature in the cache and the spatial index.
|
||||
|
Loading…
x
Reference in New Issue
Block a user