25 , mCacheGeometry( true )
32 connect( mLayer, SIGNAL( layerDeleted() ), SLOT( layerDeleted() ) );
38 connect( mLayer, SIGNAL( attributeDeleted(
int ) ), SLOT( attributeDeleted(
int ) ) );
39 connect( mLayer, SIGNAL( updatedFields() ), SLOT( invalidate() ) );
40 connect( mLayer, SIGNAL( dataChanged() ), SLOT( invalidate() ) );
46 qDeleteAll( mCacheIndices );
47 mCacheIndices.
clear();
63 bool mustInvalidate = shouldCacheGeometry && !mCacheGeometry;
64 mCacheGeometry = shouldCacheGeometry;
81 mCachedAttributes = attributes;
86 mFullCache = fullCache;
95 .setSubsetOfAttributes( mCachedAttributes )
104 while ( it.nextFeature( f ) )
127 mCacheIndices.
append( cacheIndex );
132 if ( cacheAddedAttributes )
134 connect( mLayer, SIGNAL( attributeAdded(
int ) ), SLOT( attributeAdded(
int ) ) );
138 disconnect( mLayer, SIGNAL( attributeAdded(
int ) ),
this, SLOT( attributeAdded(
int ) ) );
144 bool featureFound =
false;
150 cachedFeature = mCache[ featureId ];
155 feature =
QgsFeature( *cachedFeature->feature() );
159 .setFilterFid( featureId )
160 .setSubsetOfAttributes( mCachedAttributes )
164 cacheFeature( feature );
173 return mCache.
remove( fid );
205 void QgsVectorLayerCache::onAttributeValueChanged(
QgsFeatureId fid,
int field,
const QVariant& value )
211 cachedFeat->mFeature->setAttribute( field, value );
217 void QgsVectorLayerCache::featureDeleted(
QgsFeatureId fid )
222 void QgsVectorLayerCache::onFeatureAdded(
QgsFeatureId fid )
237 void QgsVectorLayerCache::attributeAdded(
int field )
240 mCachedAttributes.
append( field );
244 void QgsVectorLayerCache::attributeDeleted(
int field )
247 mCachedAttributes.
clear();
249 Q_FOREACH (
int attr, attrs )
252 mCachedAttributes << attr;
253 else if ( attr > field )
254 mCachedAttributes << attr - 1;
264 cachedFeat->mFeature->setGeometry( geom );
268 void QgsVectorLayerCache::layerDeleted()
274 void QgsVectorLayerCache::invalidate()
306 if ( mCache.
keys().toSet().contains( featureRequest.
filterFids() ) )
332 bool requiresWriterIt =
true;
340 requiresWriterIt =
false;
345 requiresWriterIt = !canUseCacheForRequest( featureRequest, it );
352 requiresWriterIt =
false;
394 Q_FOREACH (
int attr, requestedAttributes )
396 if ( !mCachedAttributes.
contains( attr ) )
Wrapper for iterator of features from vector data provider or vector layer.
friend class QgsCachedFeatureWriterIterator
Filter using feature IDs.
QgsVectorLayerCache(QgsVectorLayer *layer, int cacheSize, QObject *parent=nullptr)
const Flags & flags() const
void invalidated()
The cache has been invalidated and cleared.
bool contains(const Key &key) const
bool cacheGeometry() const
Returns true if the cache will fetch and cache feature geometries.
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.
QgsFeatureId filterFid() const
Get the feature ID that should be fetched.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
FilterType filterType() const
Return the filter type which is currently set on this request.
const QgsFeatureIds & filterFids() const
Get feature IDs that should be fetched.
A geometry is the spatial representation of a feature.
void requestCompleted(const QgsFeatureRequest &featureRequest, const QgsFeatureIds &fids)
Gets called, whenever the full list of feature ids for a certain request is known.
void setMaxCost(int cost)
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
bool isFidCached(const QgsFeatureId fid) const
Check if a certain feature id is cached.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
void attributeValueChanged(QgsFeatureId fid, int field, const QVariant &value)
Is emitted when an attribute is changed.
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
void setCacheSubsetOfAttributes(const QgsAttributeList &attributes)
Set the subset of attributes to be cached.
virtual void requestCompleted(const QgsFeatureRequest &featureRequest, const QgsFeatureIds &fids)
Implement this method to update the the indices, in case you need information contained by the reques...
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
long featureCount(QgsSymbolV2 *symbol)
Number of features rendered with specified symbol.
void featureAdded(QgsFeatureId fid)
Is emitted, when a new feature has been added to the layer and this cache.
void append(const T &value)
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)...
Obsolete, will be ignored. If a filterRect is set it will be used anyway. Filter using a rectangle...
QgsAttributeList attributeList() const
Returns list of attribute indexes.
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
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.
QgsAttributeList subsetOfAttributes() const
Return the subset of attributes which at least need to be fetched.
bool contains(const T &value) const
virtual bool getCacheIterator(QgsFeatureIterator &featureIterator, const QgsFeatureRequest &featureRequest)=0
Is called, when a feature request is issued on a cached layer.
Abstract base class for cache indices.
QList< Key > keys() const
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.
QList< T > toList() const
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.
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
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.
bool remove(const Key &key)
void finished()
When filling the cache, this signal gets emitted once the cache is fully initialized.
friend class QgsCachedFeatureIterator
void setCacheAddedAttributes(bool cacheAddedAttributes)
If this is enabled, the subset of cached attributes will automatically be extended to also include ne...