31 connect( mLayer, SIGNAL( layerDeleted() ), SLOT( layerDeleted() ) );
37 connect( mLayer, SIGNAL( attributeDeleted(
int ) ), SLOT( attributeDeleted(
int ) ) );
38 connect( mLayer, SIGNAL( updatedFields() ), SLOT( invalidate() ) );
39 connect( mLayer, SIGNAL( dataChanged() ), SLOT( invalidate() ) );
45 qDeleteAll( mCacheIndices );
46 mCacheIndices.
clear();
74 mCachedAttributes = attributes;
79 mFullCache = fullCache;
88 .setSubsetOfAttributes( mCachedAttributes )
97 while ( it.nextFeature( f ) )
120 mCacheIndices.
append( cacheIndex );
125 if ( cacheAddedAttributes )
127 connect( mLayer, SIGNAL( attributeAdded(
int ) ), SLOT( attributeAdded(
int ) ) );
131 disconnect( mLayer, SIGNAL( attributeAdded(
int ) ),
this, SLOT( attributeAdded(
int ) ) );
137 bool featureFound =
false;
143 cachedFeature = mCache[ featureId ];
146 if ( cachedFeature != NULL )
148 feature =
QgsFeature( *cachedFeature->feature() );
152 .setFilterFid( featureId )
153 .setSubsetOfAttributes( mCachedAttributes )
157 cacheFeature( feature );
166 return mCache.
remove( fid );
194 void QgsVectorLayerCache::onAttributeValueChanged(
QgsFeatureId fid,
int field,
const QVariant& value )
198 if ( NULL != cachedFeat )
200 cachedFeat->mFeature->setAttribute( field, value );
206 void QgsVectorLayerCache::featureDeleted(
QgsFeatureId fid )
211 void QgsVectorLayerCache::onFeatureAdded(
QgsFeatureId fid )
226 void QgsVectorLayerCache::attributeAdded(
int field )
229 mCachedAttributes.append( field );
236 mCachedAttributes.
clear();
238 Q_FOREACH (
int attr, attrs )
241 mCachedAttributes << attr;
242 else if ( attr > field )
243 mCachedAttributes << attr - 1;
251 if ( cachedFeat != NULL )
253 cachedFeat->mFeature->setGeometry( geom );
257 void QgsVectorLayerCache::layerDeleted()
263 void QgsVectorLayerCache::invalidate()
272 bool requiresWriterIt =
true;
280 requiresWriterIt =
false;
289 requiresWriterIt =
false;
299 requiresWriterIt =
false;
341 foreach (
int attr, requestedAttributes )
343 if ( !mCachedAttributes.
contains( attr ) )
Wrapper for iterator of features from vector data provider or vector layer.
friend class QgsCachedFeatureWriterIterator
const Flags & flags() const
void invalidated()
The cache has been invalidated and cleared.
bool contains(const Key &key) const
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
A geometry is the spatial representation of a feature.
void setMaxCost(int cost)
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...
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.
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)...
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.
This class caches features of a given QgsVectorLayer.
void attributeValueChanged(const QgsFeatureId &fid, const int &field, const QVariant &value)
Is emitted when an attribute is changed.
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.
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.
QList< T > toList() const
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.
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.
QgsFeatureRequest & setFlags(Flags flags)
Set flags that affect how features will be fetched.
bool remove(const Key &key)
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...