Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 e1d80b5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/core/qgsvectorlayercache.cpp
Expand Up @@ -237,7 +237,7 @@ void QgsVectorLayerCache::attributeAdded( int field )
{
Q_UNUSED( field )
mCachedAttributes.append( field );
mCache.clear();
invalidate();
}

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

Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsvectorlayercache.h
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();

Expand Down
14 changes: 10 additions & 4 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/attributetable/qgsdualview.h
Expand Up @@ -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 );
Expand Down
7 changes: 7 additions & 0 deletions tests/src/core/testqgsvectorlayercache.cpp
Expand Up @@ -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 )
Expand Down

0 comments on commit e1d80b5

Please sign in to comment.