@@ -55,6 +55,7 @@ class TestVectorLayerCache : public QObject
55
55
void testFullCache ();
56
56
void testFullCacheThroughRequest ();
57
57
void testCanUseCacheForRequest ();
58
+ void testCacheGeom ();
58
59
59
60
void onCommittedFeaturesAdded ( const QString &, const QgsFeatureList & );
60
61
@@ -331,6 +332,51 @@ void TestVectorLayerCache::testCanUseCacheForRequest()
331
332
QVERIFY ( cache.canUseCacheForRequest ( QgsFeatureRequest ().setFilterExpression ( " $x<5" ), it ) );
332
333
}
333
334
335
+ void TestVectorLayerCache::testCacheGeom ()
336
+ {
337
+ QgsVectorLayerCache cache ( mPointsLayer , 2 );
338
+ // cache geometry
339
+ cache.setCacheGeometry ( true );
340
+
341
+ // first get some feature ids from layer
342
+ QgsFeature f;
343
+ QgsFeatureIterator it = mPointsLayer ->getFeatures ();
344
+ it.nextFeature ( f );
345
+ QgsFeatureId id1 = f.id ();
346
+ it.nextFeature ( f );
347
+ QgsFeatureId id2 = f.id ();
348
+
349
+ QgsFeatureRequest req;
350
+ req.setFlags ( QgsFeatureRequest::NoGeometry ); // should be ignored by cache
351
+ req.setFilterFids ( QgsFeatureIds () << id1 << id2 );
352
+
353
+ it = cache.getFeatures ( req );
354
+ while ( it.nextFeature ( f ) )
355
+ {
356
+ QVERIFY ( f.hasGeometry () );
357
+ }
358
+
359
+ // disabled geometry caching
360
+ cache.setCacheGeometry ( false );
361
+ // we should still have cached features... no need to lose these!
362
+ QCOMPARE ( cache.cachedFeatureIds (), QgsFeatureIds () << id1 << id2 );
363
+ it = cache.getFeatures ( req );
364
+ while ( it.nextFeature ( f ) )
365
+ {
366
+ QVERIFY ( f.hasGeometry () );
367
+ }
368
+
369
+ // now upgrade cache from no geometry -> geometry, should be cleared since we
370
+ // cannot be confident that features existing in the cache have geometry
371
+ cache.setCacheGeometry ( true );
372
+ QVERIFY ( cache.cachedFeatureIds ().isEmpty () );
373
+ it = cache.getFeatures ( req );
374
+ while ( it.nextFeature ( f ) )
375
+ {
376
+ QVERIFY ( f.hasGeometry () );
377
+ }
378
+ }
379
+
334
380
void TestVectorLayerCache::onCommittedFeaturesAdded ( const QString &layerId, const QgsFeatureList &features )
335
381
{
336
382
Q_UNUSED ( layerId )
0 commit comments