Skip to content
Permalink
Browse files

Followup "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.

(cherry-picked from e1d80b5)
  • Loading branch information
nyalldawson committed Mar 7, 2017
1 parent 9bbd593 commit dbd6538d38143e458387bd72366f171c0736f106
@@ -58,9 +58,9 @@ int QgsVectorLayerCache::cacheSize()

void QgsVectorLayerCache::setCacheGeometry( bool cacheGeometry )
{
bool shouldCache = cacheGeometry && mLayer->hasGeometryType();
bool mustInvalidate = shouldCache && !mCacheGeometry; // going from no geometry -> geometry, so have to clear existing cache entries
mCacheGeometry = shouldCache;
bool shouldCacheGeometry = cacheGeometry && mLayer->hasGeometryType();
bool mustInvalidate = shouldCacheGeometry && !mCacheGeometry; // going from no geometry -> geometry, so have to clear existing cache entries
mCacheGeometry = shouldCacheGeometry;
if ( cacheGeometry )
{
connect( mLayer, SIGNAL( geometryChanged( QgsFeatureId, QgsGeometry& ) ), SLOT( geometryChanged( QgsFeatureId, QgsGeometry& ) ) );
@@ -237,8 +237,7 @@ void QgsVectorLayerCache::attributeAdded( int field )
{
Q_UNUSED( field )
mCachedAttributes.append( field );
mFullCache = false;
mCache.clear();
invalidate();
}

void QgsVectorLayerCache::attributeDeleted( int field )
@@ -138,6 +138,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 );
@@ -280,7 +282,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();

@@ -245,7 +245,7 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
switch ( mFilterModel->filterMode() )
{
case QgsAttributeTableFilterModel::ShowVisible:
disconnect( mMapCanvas, SIGNAL(extentsChanged()), this, SLOT(extentChanged()) );
disconnect( mMapCanvas, SIGNAL( extentsChanged() ), this, SLOT( extentChanged() ) );
break;

case QgsAttributeTableFilterModel::ShowAll:
@@ -254,8 +254,8 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
break;

case QgsAttributeTableFilterModel::ShowSelected:
disconnect( masterModel()->layer(), SIGNAL(selectionChanged()), this,
SLOT(updateSelectedFeatures()) );
disconnect( masterModel()->layer(), SIGNAL( selectionChanged() ), this,
SLOT( updateSelectedFeatures() ) );
break;
}

@@ -270,7 +270,7 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
switch ( filterMode )
{
case QgsAttributeTableFilterModel::ShowVisible:
connect( mMapCanvas, SIGNAL(extentsChanged()), this, SLOT(extentChanged()) );
connect( mMapCanvas, SIGNAL( extentsChanged() ), this, SLOT( extentChanged() ) );
r.setFilterFids( QgsFeatureIds() );
r.disableFilter();
if ( mMapCanvas )
@@ -288,7 +288,7 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
break;

case QgsAttributeTableFilterModel::ShowSelected:
connect( masterModel()->layer(), SIGNAL(selectionChanged()), this, SLOT(updateSelectedFeatures()) );
connect( masterModel()->layer(), SIGNAL( selectionChanged() ), this, SLOT( updateSelectedFeatures() ) );
if ( masterModel()->layer()->selectedFeatureCount() > 0 )
r.setFilterFids( masterModel()->layer()->selectedFeaturesIds() );
else
@@ -318,10 +318,8 @@ void QgsDualView::initLayerCache( bool cacheGeometry )
mLayerCache->setCacheGeometry( cacheGeometry );
if ( 0 == cacheSize || 0 == ( QgsVectorDataProvider::SelectAtId & mLayer->dataProvider()->capabilities() ) )
{
connect( mLayerCache, SIGNAL( progress( int, bool & ) ), this, SLOT( progress( int, bool & ) ) );
connect( mLayerCache, SIGNAL( finished() ), this, SLOT( finished() ) );

mLayerCache->setFullCache( true );
connect( mLayerCache, SIGNAL(invalidated()), this, SLOT(rebuildFullLayerCache()) );
rebuildFullLayerCache();
}
}

@@ -714,6 +712,14 @@ void QgsDualView::zoomToCurrentFeature()
}
}

void QgsDualView::rebuildFullLayerCache()
{
connect( mLayerCache, SIGNAL(progress(int,bool&)), this, SLOT(progress(int,bool&)), Qt::UniqueConnection );
connect( mLayerCache, SIGNAL(finished()), this, SLOT(finished()), Qt::UniqueConnection );

mLayerCache->setFullCache( true );
}

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

void rebuildFullLayerCache();

private:
void initLayerCache( bool cacheGeometry );
void initModels( QgsMapCanvas* mapCanvas, const QgsFeatureRequest& request );

0 comments on commit dbd6538

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