27 mCache.setMaxCost( cacheSize );
31 connect( mLayer, SIGNAL( layerDeleted() ), SLOT( layerDeleted() ) );
37 connect( mLayer, SIGNAL( attributeDeleted(
int ) ), SLOT( attributeDeleted(
int ) ) );
38 connect( mLayer, SIGNAL( updatedFields() ), SLOT( updatedFields() ) );
44 qDeleteAll( mCacheIndices );
45 mCacheIndices.clear();
50 mCache.setMaxCost( cacheSize );
55 return mCache.maxCost();
73 mCachedAttributes = attributes;
78 mFullCache = fullCache;
87 .setSubsetOfAttributes( mCachedAttributes )
96 while ( it.nextFeature( f ) )
100 if ( t.elapsed() > 1000 )
119 mCacheIndices.append( cacheIndex );
124 if ( cacheAddedAttributes )
126 connect( mLayer, SIGNAL( attributeAdded(
int ) ), SLOT( attributeAdded(
int ) ) );
130 disconnect( mLayer, SIGNAL( attributeAdded(
int ) ),
this, SLOT( attributeAdded(
int ) ) );
136 bool featureFound =
false;
142 cachedFeature = mCache[ featureId ];
145 if ( cachedFeature != NULL )
147 feature =
QgsFeature( *cachedFeature->feature() );
151 .setFilterFid( featureId )
152 .setSubsetOfAttributes( mCachedAttributes )
156 cacheFeature( feature );
165 return mCache.remove( fid );
176 if ( fids.count() < mCache.size() )
193 void QgsVectorLayerCache::onAttributeValueChanged(
QgsFeatureId fid,
int field,
const QVariant& value )
197 if ( NULL != cachedFeat )
199 cachedFeat->mFeature->setAttribute( field, value );
205 void QgsVectorLayerCache::featureDeleted(
QgsFeatureId fid )
207 mCache.remove( fid );
210 void QgsVectorLayerCache::onFeatureAdded(
QgsFeatureId fid )
225 void QgsVectorLayerCache::attributeAdded(
int field )
228 mCachedAttributes.append( field );
232 void QgsVectorLayerCache::attributeDeleted(
int field )
236 mCache[ fid ]->mFeature->deleteAttribute( field );
244 if ( cachedFeat != NULL )
246 cachedFeat->mFeature->setGeometry( geom );
250 void QgsVectorLayerCache::layerDeleted()
256 void QgsVectorLayerCache::updatedFields()
264 bool requiresWriterIt =
true;
272 requiresWriterIt =
false;
281 requiresWriterIt =
false;
291 requiresWriterIt =
false;
305 QSet<int> attrs = featureRequest.
subsetOfAttributes().toSet() + mCachedAttributes.toSet();
316 return mCache.contains( fid );
333 foreach (
int attr, requestedAttributes )
335 if ( !mCachedAttributes.contains( attr ) )
Wrapper for iterator of features from vector data provider or vector layer.
friend class QgsCachedFeatureWriterIterator
const Flags & flags() const
QSet< QgsFeatureId > QgsFeatureIds
bool removeCachedFeature(QgsFeatureId fid)
Removes the feature identified by fid from the cache if present.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
bool isFidCached(const QgsFeatureId fid)
Check if a certain feature id is cached.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
const QgsAttributeList & subsetOfAttributes() const
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void setCacheSubsetOfAttributes(const QgsAttributeList &attributes)
Set the subset of attributes to be cached.
void featureAdded(QgsFeatureId fid)
Is emitted, when a new feature has been added to the layer and this cache.
void progress(int i, bool &cancel)
When filling the cache, this signal gets emitted periodically to notify about the progress and to be ...
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< int > QgsAttributeList
Fetch only a subset of attributes (setSubsetOfAttributes sets this flag)
void cachedLayerDeleted()
Is emitted when the cached layer is deleted.
bool checkInformationCovered(const QgsFeatureRequest &featureRequest)
Checks if the information required to complete the request is cached.
void attributeValueChanged(const QgsFeatureId &fid, const int &field, const QVariant &value)
Is emitted when an attribute is changed.
virtual bool getCacheIterator(QgsFeatureIterator &featureIterator, const QgsFeatureRequest &featureRequest)=0
Is called, when a feature request is issued on a cached layer.
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
virtual long featureCount() const
Number of features in the layer.
Abstract base class for cache indices.
QgsAttributeList pendingAllAttributesList()
returns list of attributes
void setCacheGeometry(bool cacheGeometry)
Enable or disable the caching of geometries.
void setFullCache(bool fullCache)
This enables or disables full caching.
virtual void flushFeature(const QgsFeatureId fid)=0
Is called, whenever a feature is removed from the cache.
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
void setCacheSize(int cacheSize)
Sets the maximum number of features to keep in the cache.
void requestCompleted(QgsFeatureRequest featureRequest, QgsFeatureIds fids)
Gets called, whenever the full list of feature ids for a certain request is known.
QgsVectorLayerCache(QgsVectorLayer *layer, int cacheSize, QObject *parent=NULL)
void featureRemoved(QgsFeatureId fid)
Gets called, whenever a feature has been removed.
int cacheSize()
Returns the maximum number of features this cache will hold.
QgsVectorDataProvider * dataProvider()
Returns the data provider.
friend class QgsCachedFeature
bool nextFeature(QgsFeature &f)
Geometry is not required. It may still be returned if e.g. required for a filter condition.
void addCacheIndex(QgsAbstractCacheIndex *cacheIndex)
Adds a QgsAbstractCacheIndex to this cache.
Represents a vector layer which manages a vector based data sets.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
void finished()
When filling the cache, this signal gets emitted once the cache is fully initialized.
friend class QgsCachedFeatureIterator
virtual void requestCompleted(QgsFeatureRequest featureRequest, QgsFeatureIds fids)
Implement this method to update the the indices, in case you need information contained by the reques...
void setCacheAddedAttributes(bool cacheAddedAttributes)
If this is enabled, the subset of cached attributes will automatically be extended to also include ne...