mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Recognise that a cache can be filled using a FilterNone request
On behalf of Faunalia, sponsored by ENEL
This commit is contained in:
parent
38a4aac971
commit
afd5d1e934
@ -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 )
|
||||
|
Loading…
x
Reference in New Issue
Block a user