Skip to content
Permalink
Browse files

Recognise that a cache can be filled using a FilterNone request

On behalf of Faunalia, sponsored by ENEL
  • Loading branch information
nyalldawson committed Nov 15, 2016
1 parent 38a4aac commit afd5d1e9344f41a40f882fb204810f8e650813c0
@@ -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;
}
}
}

@@ -133,9 +133,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
@@ -52,6 +52,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& );

@@ -219,6 +221,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 afd5d1e

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