Skip to content
Permalink
Browse files

Unvert "Ensure that full cache flag is cleared when invalid"

This is required - when the cache is invalidated it requires
a full rebuild (eg due to a new attribute being added) in order
to have complete information.

Since this could be a very lengthy process, it's not safe to
immediately rebuild the full cache. Instead, clear the full
cache flag and require users of this class to handle
responsive cache rebuilding by listening to the invalidated()
signal from the cache.
  • Loading branch information
nyalldawson committed Mar 5, 2017
1 parent 1d504ea commit e1d80b5bbb7472bc396ece50b295b02cbfd6ae26
@@ -237,7 +237,7 @@ void QgsVectorLayerCache::attributeAdded( int field )
{
Q_UNUSED( field )
mCachedAttributes.append( field );
mCache.clear();
invalidate();
}

void QgsVectorLayerCache::attributeDeleted( int field )
@@ -273,6 +273,7 @@ void QgsVectorLayerCache::layerDeleted()
void QgsVectorLayerCache::invalidate()
{
mCache.clear();
mFullCache = false;
emit invalidated();
}

@@ -141,6 +141,8 @@ 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
* @note when a cache is invalidated() (e.g. by adding an attribute to a layer) this setting
* is reset. A full cache rebuild must be performed by calling setFullCache( true ) again.
* @see hasFullCache()
*/
void setFullCache( bool fullCache );
@@ -319,7 +321,9 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
void featureAdded( QgsFeatureId fid );

/**
* The cache has been invalidated and cleared.
* The cache has been invalidated and cleared. Note that when a cache is invalidated
* the fullCache() setting will be cleared, and a full cache rebuild via setFullCache( true )
* will need to be performed.
*/
void invalidated();

@@ -273,10 +273,8 @@ void QgsDualView::initLayerCache( bool cacheGeometry )
mLayerCache->setCacheGeometry( cacheGeometry );
if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayer->dataProvider()->capabilities() ) )
{
connect( mLayerCache, &QgsVectorLayerCache::progress, this, &QgsDualView::progress );
connect( mLayerCache, &QgsVectorLayerCache::finished, this, &QgsDualView::finished );

mLayerCache->setFullCache( true );
connect( mLayerCache, &QgsVectorLayerCache::invalidated, this, &QgsDualView::rebuildFullLayerCache );
rebuildFullLayerCache();
}
}

@@ -679,6 +677,14 @@ void QgsDualView::panToCurrentFeature()
}
}

void QgsDualView::rebuildFullLayerCache()
{
connect( mLayerCache, &QgsVectorLayerCache::progress, this, &QgsDualView::progress, Qt::UniqueConnection );
connect( mLayerCache, &QgsVectorLayerCache::finished, this, &QgsDualView::finished, Qt::UniqueConnection );

mLayerCache->setFullCache( true );
}

void QgsDualView::previewExpressionChanged( const QString &expression )
{
mLayer->setDisplayExpression( expression );
@@ -327,6 +327,8 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
//! Pans to the active feature
void panToCurrentFeature();

void rebuildFullLayerCache();

private:
void initLayerCache( bool cacheGeometry );
void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request );
@@ -384,6 +384,13 @@ void TestVectorLayerCache::testCacheGeom()
{
QVERIFY( f.hasGeometry() );
}

// another test...
cache.setCacheGeometry( false );
cache.setFullCache( true );
QVERIFY( cache.hasFullCache() );
cache.setCacheGeometry( true );
QVERIFY( !cache.hasFullCache() );
}

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

0 comments on commit e1d80b5

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