Skip to content
Permalink
Browse files

Recognise that a cache can be filled using a FilterNone request

On behalf of Faunalia, sponsored by ENEL

(cherry-picked from afd5d1e)
  • Loading branch information
nyalldawson committed Nov 23, 2016
1 parent 0d6c2f0 commit e82f8a482beb07d5c790b549c9e3a4cfc8b2306b
@@ -65,9 +65,18 @@ class QgsVectorLayerCache : QObject
* be used for slow data sources, be aware, that the call to this method might take a long time.
*
* @param fullCache True: enable full caching, False: disable full caching
* @see hasFullCache()
*/
void setFullCache( bool fullCache );

/** Returns true if the cache is complete, ie it contains all features. This may happen as
* a result of a call to setFullCache() or by through a feature request which resulted in
* all available features being cached.
* @see setFullCache()
* @note added in QGIS 3.0
*/
bool hasFullCache() const;

/**
* @brief
* Adds a {@link QgsAbstractCacheIndex} to this cache. Cache indices know about features present
@@ -180,6 +180,10 @@ void QgsVectorLayerCache::requestCompleted( const QgsFeatureRequest& featureRequ
{
idx->requestCompleted( featureRequest, fids );
}
if ( featureRequest.filterType() == QgsFeatureRequest::FilterNone )
{
mFullCache = true;
}
}
}

@@ -131,9 +131,18 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
* be used for slow data sources, be aware, that the call to this method might take a long time.
*
* @param fullCache True: enable full caching, False: disable full caching
* @see hasFullCache()
*/
void setFullCache( bool fullCache );

/** Returns true if the cache is complete, ie it contains all features. This may happen as
* a result of a call to setFullCache() or by through a feature request which resulted in
* all available features being cached.
* @see setFullCache()
* @note added in QGIS 3.0
*/
bool hasFullCache() const { return mFullCache; }

/**
* @brief
* Adds a {@link QgsAbstractCacheIndex} to this cache. Cache indices know about features present
@@ -51,6 +51,8 @@ class TestVectorLayerCache : public QObject
void testCacheAttrActions(); // Test attribute add/ attribute delete
void testFeatureActions(); // Test adding/removing features works
void testSubsetRequest();
void testFullCache();
void testFullCacheThroughRequest();

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

@@ -218,6 +220,52 @@ void TestVectorLayerCache::testSubsetRequest()
QVERIFY( a == f.attribute( 3 ) );
}

void TestVectorLayerCache::testFullCache()
{
// cache is too small to fit all features
QgsVectorLayerCache cache( mPointsLayer, 2 );
QVERIFY( !cache.hasFullCache() );
QVERIFY( cache.cacheSize() < mPointsLayer->featureCount() );
// but we set it to full cache
cache.setFullCache( true );
// so now it should have sufficient size for all features
QVERIFY( cache.cacheSize() >= mPointsLayer->featureCount() );
QVERIFY( cache.hasFullCache() );

// double check that everything is indeed in the cache
QgsFeatureIterator it = mPointsLayer->getFeatures();
QgsFeature f;
while ( it.nextFeature( f ) )
{
QVERIFY( cache.isFidCached( f.id() ) );
}
}

void TestVectorLayerCache::testFullCacheThroughRequest()
{
// make sure cache is sufficient size for all features
QgsVectorLayerCache cache( mPointsLayer, mPointsLayer->featureCount() * 2 );
QVERIFY( !cache.hasFullCache() );

// now request all features from cache
QgsFeatureIterator it = cache.getFeatures( QgsFeatureRequest() );
QgsFeature f;
while ( it.nextFeature( f ) )
{
// suck in all features
}

// cache should now contain all features
it = mPointsLayer->getFeatures();
while ( it.nextFeature( f ) )
{
QVERIFY( cache.isFidCached( f.id() ) );
}

// so it should be a full cache!
QVERIFY( cache.hasFullCache() );
}

void TestVectorLayerCache::onCommittedFeaturesAdded( const QString& layerId, const QgsFeatureList& features )
{
Q_UNUSED( layerId )

0 comments on commit e82f8a4

Please sign in to comment.
You can’t perform that action at this time.