mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-03 00:02:25 -05:00
Fix QgsFeaturePool never uses cached feature, always retrieves feature from layer
This commit is contained in:
parent
4a8d84bdf9
commit
26e4ea72b5
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user