Skip to content

Commit e1d80b5

Browse files
committed
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.
1 parent 1d504ea commit e1d80b5

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

src/core/qgsvectorlayercache.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ void QgsVectorLayerCache::attributeAdded( int field )
237237
{
238238
Q_UNUSED( field )
239239
mCachedAttributes.append( field );
240-
mCache.clear();
240+
invalidate();
241241
}
242242

243243
void QgsVectorLayerCache::attributeDeleted( int field )
@@ -273,6 +273,7 @@ void QgsVectorLayerCache::layerDeleted()
273273
void QgsVectorLayerCache::invalidate()
274274
{
275275
mCache.clear();
276+
mFullCache = false;
276277
emit invalidated();
277278
}
278279

src/core/qgsvectorlayercache.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
141141
* be used for slow data sources, be aware, that the call to this method might take a long time.
142142
*
143143
* @param fullCache True: enable full caching, False: disable full caching
144+
* @note when a cache is invalidated() (e.g. by adding an attribute to a layer) this setting
145+
* is reset. A full cache rebuild must be performed by calling setFullCache( true ) again.
144146
* @see hasFullCache()
145147
*/
146148
void setFullCache( bool fullCache );
@@ -319,7 +321,9 @@ class CORE_EXPORT QgsVectorLayerCache : public QObject
319321
void featureAdded( QgsFeatureId fid );
320322

321323
/**
322-
* The cache has been invalidated and cleared.
324+
* The cache has been invalidated and cleared. Note that when a cache is invalidated
325+
* the fullCache() setting will be cleared, and a full cache rebuild via setFullCache( true )
326+
* will need to be performed.
323327
*/
324328
void invalidated();
325329

src/gui/attributetable/qgsdualview.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,8 @@ void QgsDualView::initLayerCache( bool cacheGeometry )
273273
mLayerCache->setCacheGeometry( cacheGeometry );
274274
if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayer->dataProvider()->capabilities() ) )
275275
{
276-
connect( mLayerCache, &QgsVectorLayerCache::progress, this, &QgsDualView::progress );
277-
connect( mLayerCache, &QgsVectorLayerCache::finished, this, &QgsDualView::finished );
278-
279-
mLayerCache->setFullCache( true );
276+
connect( mLayerCache, &QgsVectorLayerCache::invalidated, this, &QgsDualView::rebuildFullLayerCache );
277+
rebuildFullLayerCache();
280278
}
281279
}
282280

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

680+
void QgsDualView::rebuildFullLayerCache()
681+
{
682+
connect( mLayerCache, &QgsVectorLayerCache::progress, this, &QgsDualView::progress, Qt::UniqueConnection );
683+
connect( mLayerCache, &QgsVectorLayerCache::finished, this, &QgsDualView::finished, Qt::UniqueConnection );
684+
685+
mLayerCache->setFullCache( true );
686+
}
687+
682688
void QgsDualView::previewExpressionChanged( const QString &expression )
683689
{
684690
mLayer->setDisplayExpression( expression );

src/gui/attributetable/qgsdualview.h

+2
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ class GUI_EXPORT QgsDualView : public QStackedWidget, private Ui::QgsDualViewBas
327327
//! Pans to the active feature
328328
void panToCurrentFeature();
329329

330+
void rebuildFullLayerCache();
331+
330332
private:
331333
void initLayerCache( bool cacheGeometry );
332334
void initModels( QgsMapCanvas *mapCanvas, const QgsFeatureRequest &request );

tests/src/core/testqgsvectorlayercache.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,13 @@ void TestVectorLayerCache::testCacheGeom()
384384
{
385385
QVERIFY( f.hasGeometry() );
386386
}
387+
388+
// another test...
389+
cache.setCacheGeometry( false );
390+
cache.setFullCache( true );
391+
QVERIFY( cache.hasFullCache() );
392+
cache.setCacheGeometry( true );
393+
QVERIFY( !cache.hasFullCache() );
387394
}
388395

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

0 commit comments

Comments
 (0)