Skip to content

Commit

Permalink
Clear and load in getFeatures()
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Mar 12, 2019
1 parent 9a839c9 commit 60512e9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down
21 changes: 16 additions & 5 deletions src/analysis/vector/geometry_checker/qgsfeaturepool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -159,6 +168,7 @@ QString QgsFeaturePool::layerName() const

QgsCoordinateReferenceSystem QgsFeaturePool::crs() const
{
QgsReadWriteLocker( mCacheLock, QgsReadWriteLocker::Read );
return mFeatureSource->crs();
}

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

QString QgsFeaturePool::layerId() const
{
QgsReadWriteLocker( mCacheLock, QgsReadWriteLocker::Read );
return mFeatureSource->id();
}
2 changes: 1 addition & 1 deletion src/analysis/vector/geometry_checker/qgsfeaturepool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 60512e9

Please sign in to comment.