19 #ifndef QgsVectorLayerCache_H
20 #define QgsVectorLayerCache_H
22 #include "qgis_core.h"
27 #include <unordered_set>
57 class CORE_EXPORT QgsCachedFeature
70 , mAllAttributesFetched( allAttributesFetched )
79 mCache->featureRemoved( mFeature->id() );
83 inline const QgsFeature *feature() {
return mFeature; }
85 bool allAttributesFetched()
const;
90 bool mAllAttributesFetched =
true;
308 sipRes = sipCpp->featureCount();
312 int __bool__()
const;
406 void onAttributeValueChanged(
QgsFeatureId fid,
int field,
const QVariant &value );
407 void onJoinAttributeValueChanged(
QgsFeatureId fid,
int field,
const QVariant &value );
410 void attributeAdded(
int field );
411 void attributeDeleted(
int field );
418 void connectJoinedLayers()
const;
420 inline void cacheFeature(
QgsFeature &feat,
bool allAttributesFetched )
423 mCache.insert( feat.
id(), cachedFeature );
424 if ( mCacheUnorderedKeys.find( feat.
id() ) == mCacheUnorderedKeys.end() )
426 mCacheUnorderedKeys.insert( feat.
id() );
427 mCacheOrderedKeys.emplace_back( feat.
id() );
432 QCache< QgsFeatureId, QgsCachedFeature > mCache;
437 std::unordered_set< QgsFeatureId > mCacheUnorderedKeys;
438 std::deque< QgsFeatureId > mCacheOrderedKeys;
440 bool mCacheGeometry =
true;
441 bool mFullCache =
false;
442 QList<QgsAbstractCacheIndex *> mCacheIndices;
448 friend class QgsCachedFeature;
460 friend class TestVectorLayerCache;
WkbType
The WKB type describes the number of dimensions a geometry has.
Abstract base class for cache indices.
Delivers features from the cache.
Uses another iterator as backend and writes features to the cache.
This class represents a coordinate reference system (CRS).
Wrapper for iterator of features from vector data provider or vector layer.
bool nextFeature(QgsFeature &f)
Fetch next feature and stores in f, returns true on success.
This class wraps a request for features to a vector layer (or directly its vector data provider).
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
A rectangle specified with double values.
This class caches features of a given QgsVectorLayer.
bool isFidCached(QgsFeatureId fid) const
Check if a certain feature id is cached.
void setFullCache(bool fullCache)
This enables or disables full caching.
bool hasFullCache() const
Returns true if the cache is complete, ie it contains all features.
QgsFeatureIterator getFeatures(const QString &expression)
Query the layer for features matching a given expression.
void finished()
When filling the cache, this signal gets emitted once the cache is fully initialized.
void featureRemoved(QgsFeatureId fid)
Gets called, whenever a feature has been removed.
void setCacheAddedAttributes(bool cacheAddedAttributes)
If this is enabled, the subset of cached attributes will automatically be extended to also include ne...
friend class QgsCachedFeature
void invalidated()
The cache has been invalidated and cleared.
void setCacheSize(int cacheSize)
Sets the maximum number of features to keep in the cache.
void setCacheSubsetOfAttributes(const QgsAttributeList &attributes)
Set the list (possibly a subset) of attributes to be cached.
QgsFeatureIterator getFeatures(const QgsRectangle &rectangle)
Query the layer for the features which intersect the specified rectangle.
void featureAdded(QgsFeatureId fid)
Emitted when a new feature has been added to the layer and this cache.
QgsFields fields() const
Returns the fields associated with features in the cache.
QgsFeatureIterator getFeatures(const QgsFeatureIds &fids)
Query the layer for the features with the given ids.
QgsFeature getFeature(QgsFeatureId fid)
Query the layer for the feature with the given id.
void cachedLayerDeleted()
Is emitted when the cached layer is deleted.
void requestCompleted(const QgsFeatureRequest &featureRequest, const QgsFeatureIds &fids)
Gets called, whenever the full list of feature ids for a certain request is known.
void attributeValueChanged(QgsFeatureId fid, int field, const QVariant &value)
Emitted when an attribute is changed.
bool removeCachedFeature(QgsFeatureId fid)
Removes the feature identified by fid from the cache if present.
void progress(int i, bool &cancel)
When filling the cache, this signal gets emitted periodically to notify about the progress and to be ...
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
long long featureCount() const
Returns the number of features contained in the source, or -1 if the feature count is unknown.
QgsCoordinateReferenceSystem sourceCrs() const
Returns the coordinate reference system for features in the cache.
bool checkInformationCovered(const QgsFeatureRequest &featureRequest)
Checks if the information required to complete the request is cached.
QgsFeatureIds cachedFeatureIds() const
Returns the set of feature IDs for features which are cached.
bool featureAtIdWithAllAttributes(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id with all attributes, if the cached feature already contains ...
bool cacheGeometry() const
Returns true if the cache will fetch and cache feature geometries.
Qgis::WkbType wkbType() const
Returns the geometry type for features in the cache.
int cacheSize()
Returns the maximum number of features this cache will hold.
QgsAttributeList cacheSubsetOfAttributes() const
Returns the list (possibly a subset) of cached attributes.
void addCacheIndex(QgsAbstractCacheIndex *cacheIndex)
Adds a QgsAbstractCacheIndex to this cache.
QgsVectorLayerCache(QgsVectorLayer *layer, int cacheSize, QObject *parent=nullptr)
void setCacheGeometry(bool cacheGeometry)
Enable or disable the caching of geometries.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &featureRequest=QgsFeatureRequest())
Query this VectorLayerCache for features.
~QgsVectorLayerCache() override
bool featureAtId(QgsFeatureId featureId, QgsFeature &feature, bool skipCache=false)
Gets the feature at the given feature id.
Represents a vector layer which manages a vector based data sets.
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList