Fix QgsFeaturePool never uses cached feature, always retrieves feature from layer

This commit is contained in:
Nyall Dawson 2018-08-20 09:16:58 +10:00
parent 4a8d84bdf9
commit 26e4ea72b5

View File

@ -60,25 +60,22 @@ QgsFeaturePool::QgsFeaturePool( QgsVectorLayer *layer, double layerToMapUnits, c
bool QgsFeaturePool::get( QgsFeatureId id, QgsFeature &feature ) bool QgsFeaturePool::get( QgsFeatureId id, QgsFeature &feature )
{ {
QMutexLocker lock( &mLayerMutex ); QMutexLocker lock( &mLayerMutex );
QgsFeature *pfeature = mFeatureCache.object( id ); QgsFeature *cachedFeature = mFeatureCache.object( id );
if ( pfeature ) if ( cachedFeature )
{ {
//feature was cached //feature was cached
feature = *pfeature; feature = *cachedFeature;
} }
else
// Feature not in cache, retrieve from layer {
pfeature = new QgsFeature(); // Feature not in cache, retrieve from layer
// TODO: avoid always querying all attributes (attribute values are needed when merging by attribute) // TODO: avoid always querying all attributes (attribute values are needed when merging by attribute)
if ( !mLayer->getFeatures( QgsFeatureRequest( id ) ).nextFeature( *pfeature ) ) if ( !mLayer->getFeatures( QgsFeatureRequest( id ) ).nextFeature( feature ) )
{ {
delete pfeature;
return false; return false;
} }
//make a copy of pfeature into feature parameter mFeatureCache.insert( id, new QgsFeature( feature ) );
feature = QgsFeature( *pfeature ); }
//ownership of pfeature is transferred to cache
mFeatureCache.insert( id, pfeature );
return true; return true;
} }