Skip to content

Commit ed63152

Browse files
elpasonyalldawson
authored andcommitted
Do not set full layer cache when a filter rect is passed
Fixes #19468 - Attribute table: show features visible on map is broken (and affects show all features, too) Cherry picked from master 929ab27
1 parent f54ba94 commit ed63152

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/core/qgsvectorlayercache.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ void QgsVectorLayerCache::requestCompleted( const QgsFeatureRequest &featureRequ
205205
// If a request is too large for the cache don't notify to prevent from indexing incomplete requests
206206
if ( fids.count() <= mCache.size() )
207207
{
208-
Q_FOREACH ( QgsAbstractCacheIndex *idx, mCacheIndices )
208+
for ( const auto &idx : qgis::as_const( mCacheIndices ) )
209209
{
210210
idx->requestCompleted( featureRequest, fids );
211211
}
212-
if ( featureRequest.filterType() == QgsFeatureRequest::FilterNone )
212+
if ( featureRequest.filterType() == QgsFeatureRequest::FilterNone &&
213+
( featureRequest.filterRect().isNull() || featureRequest.filterRect().contains( mLayer->extent() ) ) )
213214
{
214215
mFullCache = true;
215216
}

tests/src/core/testqgsvectorlayercache.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class TestVectorLayerCache : public QObject
5353
void testFullCacheThroughRequest();
5454
void testCanUseCacheForRequest();
5555
void testCacheGeom();
56+
void testFullCacheWithRect(); // Test that if rect is set then no full cache can exist, see #19468
5657

5758
void onCommittedFeaturesAdded( const QString &, const QgsFeatureList & );
5859

@@ -390,6 +391,33 @@ void TestVectorLayerCache::testCacheGeom()
390391
QVERIFY( !cache.hasFullCache() );
391392
}
392393

394+
void TestVectorLayerCache::testFullCacheWithRect()
395+
{
396+
QgsVectorLayerCache cache( mPointsLayer, mPointsLayer->dataProvider()->featureCount() );
397+
// cache geometry
398+
cache.setCacheGeometry( true );
399+
QVERIFY( ! cache.hasFullCache() );
400+
QgsFeatureRequest req;
401+
req.setFilterRect( mPointsLayer->dataProvider()->extent().buffered( - mPointsLayer->dataProvider()->extent().width() / 2 ) );
402+
QgsFeatureIterator it = cache.getFeatures( req );
403+
QgsFeature f;
404+
while ( it.nextFeature( f ) )
405+
{
406+
QVERIFY( f.hasGeometry() );
407+
}
408+
QVERIFY( ! cache.hasFullCache() );
409+
410+
// Filter rect contains extent
411+
req.setFilterRect( mPointsLayer->dataProvider()->extent().buffered( 1 ) );
412+
it = cache.getFeatures( req );
413+
while ( it.nextFeature( f ) )
414+
{
415+
QVERIFY( f.hasGeometry() );
416+
}
417+
QVERIFY( cache.hasFullCache() );
418+
419+
}
420+
393421
void TestVectorLayerCache::onCommittedFeaturesAdded( const QString &layerId, const QgsFeatureList &features )
394422
{
395423
Q_UNUSED( layerId )

0 commit comments

Comments
 (0)