19#ifndef QgsVectorLayerCache_H
20#define QgsVectorLayerCache_H
23#include <unordered_set>
57 class CORE_EXPORT QgsCachedFeature
70 , mAllAttributesFetched( allAttributesFetched )
71 , mGeometryFetched( geometryFetched )
80 mCache->featureRemoved( mFeature.id() );
86 inline QgsFeature feature()
const {
return mFeature; }
88 bool allAttributesFetched()
const;
90 bool geometryFetched()
const;
95 bool mAllAttributesFetched =
true;
96 bool mGeometryFetched =
false;
99 Q_DISABLE_COPY( QgsCachedFeature )
160 void setCacheAddedAttributes(
bool cacheAddedAttributes );
175 void setFullCache(
bool fullCache );
321 sipRes = sipCpp->featureCount();
325 int __bool__()
const;
336 long long featureCount()
const;
469 void onAttributeValueChanged(
QgsFeatureId fid,
int field,
const QVariant &value );
470 void onJoinAttributeValueChanged(
QgsFeatureId fid,
int field,
const QVariant &value );
473 void attributeAdded(
int field );
474 void attributeDeleted(
int field );
480 void connectJoinedLayers()
const;
482 inline void cacheFeature(
QgsFeature &feat,
bool allAttributesFetched,
bool geometryFetched =
false )
484 QgsCachedFeature *cachedFeature =
new QgsCachedFeature( feat,
this, allAttributesFetched, geometryFetched || mCacheGeometry );
485 mCache.insert( feat.
id(), cachedFeature );
486 if ( mCacheUnorderedKeys.find( feat.
id() ) == mCacheUnorderedKeys.end() )
488 mCacheUnorderedKeys.insert( feat.
id() );
489 mCacheOrderedKeys.emplace_back( feat.
id() );
493 QgsVectorLayer *mLayer =
nullptr;
494 QCache< QgsFeatureId, QgsCachedFeature > mCache;
499 std::unordered_set< QgsFeatureId > mCacheUnorderedKeys;
500 std::deque< QgsFeatureId > mCacheOrderedKeys;
502 bool mCacheGeometry =
true;
503 bool mFullCache =
false;
504 QList<QgsAbstractCacheIndex *> mCacheIndices;
505 bool mCacheAddedAttributes =
false;
511 friend class QgsCachedFeature;
WkbType
The WKB type describes the number of dimensions a geometry has.
Abstract base class for cache indices.
Delivers features from the cache.
Represents a coordinate reference system (CRS).
Wrapper for iterator of features from vector data provider or vector layer.
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.
void featureAboutToBeAdded(QgsFeatureId fid)
Emitted when a new feature is about to be added to the cache (as a result of feature addition to the ...
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 invalidated()
The cache has been invalidated and cleared.
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.
void featureDeleted(QgsFeatureId fid)
Emitted when a feature has been deleted from the layer and this cache.
void setCacheSize(long long cacheSize)
Sets the maximum number of features to keep 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.
friend class QgsCachedFeatureWriterIterator
void attributeValueChanged(QgsFeatureId fid, int field, const QVariant &value)
Emitted when an attribute is changed.
void progress(int i, bool &cancel)
When filling the cache, this signal gets emitted periodically to notify about the progress and to be ...
friend class TestVectorLayerCache
QgsVectorLayer * layer()
Returns the layer to which this cache belongs.
bool cacheGeometry() const
Returns true if the cache will fetch and cache feature geometries.
void featureAboutToBeDeleted(QgsFeatureId fid)
Emitted when a feature is about to be deleted from this cache (as a result of a feature deletion from...
friend class QgsCachedFeatureIterator
long long cacheSize() const
Returns the maximum number of features this cache will hold.
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.
Represents a vector layer which manages a vector based dataset.
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
QList< int > QgsAttributeList