25#include <QMutexLocker>
31 : mFeatureCache( CACHE_SIZE )
33 , mGeometryType( layer->geometryType() )
35 , mLayerId( layer->id() )
36 , mLayerName( layer->name() )
37 , mCrs( layer->
crs() )
39 Q_ASSERT( QThread::currentThread() == mLayer->thread() );
53 QgsFeature *cachedFeature = mFeatureCache.object(
id );
57 feature = *cachedFeature;
63 if ( !mFeatureSource->getFeatures(
QgsFeatureRequest(
id ) ).nextFeature( feature ) )
68 mFeatureCache.insert(
id,
new QgsFeature( feature ) );
79 Q_ASSERT( QThread::currentThread() == mLayer->thread() );
81 mFeatureCache.clear();
86 mFeatureSource = std::make_unique<QgsVectorLayerFeatureSource>( mLayer );
114 Q_ASSERT( QThread::currentThread() == mLayer->thread() );
116 return mLayer.data();
129 mFeatureCache.insert( feature.
id(),
new QgsFeature( feature ) );
137 mFeatureCache.remove( feature.
id() );
155 mFeatureCache.remove( origFeature.
id() );
166 return mFeatureCache.contains( fid );
181 return mGeometryType;
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
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.
void refreshCache(const QgsFeature &feature)
Changes a feature in the cache and the spatial index.
Qgis::GeometryType geometryType() const
The geometry type of this layer.
QgsFeaturePool(QgsVectorLayer *layer)
Creates a new feature pool for layer.
QgsFeatureIds allFeatureIds() const
Returns the complete set of feature ids in this pool.
QString layerId() const
The layer id of the layer.
void insertFeature(const QgsFeature &feature, bool skipLock=false)
Inserts a feature into the cache and the spatial index.
QPointer< QgsVectorLayer > layerPtr() const
Gets a QPointer to the underlying layer.
bool isFeatureCached(QgsFeatureId fid)
Checks if the feature fid is cached.
QgsCoordinateReferenceSystem crs() const
The coordinate reference system of this layer.
QgsFeatureIds getFeatures(const QgsFeatureRequest &request, QgsFeedback *feedback=nullptr)
Gets features for the provided request.
QgsFeatureIds getIntersects(const QgsRectangle &rect) const
Gets all feature ids in the bounding box rect.
QString layerName() const
Returns the name of the layer.
void setFeatureIds(const QgsFeatureIds &ids)
Sets all the feature ids governed by this feature pool.
void removeFeature(const QgsFeatureId featureId)
Removes a feature from the cache and the spatial index.
QgsVectorLayer * layer() const
Gets a pointer to the underlying layer.
bool getFeature(QgsFeatureId id, QgsFeature &feature)
Retrieves the feature with the specified id into feature.
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...
Base class for feedback objects to be used for cancellation of something running in a worker thread.
The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteL...
void unlock()
Unlocks the lock.
void changeMode(Mode mode)
Change the mode of the lock to mode.
A rectangle specified with double values.
A spatial index for QgsFeature objects.
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags()) override
Adds a feature to the index.
bool deleteFeature(const QgsFeature &feature)
Removes a feature from the index.
Partial snapshot of vector layer's state (only the members necessary for access to features)
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
const QgsCoordinateReferenceSystem & crs