QgsFeaturePool class
A feature pool is based on a vector layer and caches features.
Contents
Base classes
- class QgsFeatureSink
- An interface for objects which accept features via addFeature(s) methods.
Derived classes
- class QgsVectorDataProviderFeaturePool
- A feature pool based on a vector data provider.
- class QgsVectorLayerFeaturePool
- A feature pool based on a vector layer.
Constructors, destructors, conversion operators
- QgsFeaturePool(QgsVectorLayer* layer)
- Creates a new feature pool for layer.
Public functions
- auto allFeatureIds() const -> QgsFeatureIds
- Returns the complete set of feature ids in this pool.
- auto crs() const -> QgsCoordinateReferenceSystem
- The coordinate reference system of this layer.
- void deleteFeature(QgsFeatureId fid) pure virtual
- Removes a feature from this pool.
-
auto geometryType() const -> QgsWkbTypes::
GeometryType - The geometry type of this layer.
- auto getFeature(QgsFeatureId id, QgsFeature& feature, QgsFeedback* feedback = nullptr) -> bool
- Retrieves the feature with the specified id into feature.
- auto getFeatures(const QgsFeatureRequest& request, QgsFeedback* feedback = nullptr) -> QgsFeatureIds
- Gets features for the provided request.
- auto getIntersects(const QgsRectangle& rect) const -> QgsFeatureIds
- Gets all feature ids in the bounding box rect.
- auto layer() const -> QgsVectorLayer*
- Gets a pointer to the underlying layer.
- auto layerId() const -> QString
- The layer id of the layer.
- auto layerPtr() const -> QPointer<QgsVectorLayer>
- Gets a QPointer to the underlying layer.
- void updateFeature(QgsFeature& feature) pure virtual
- Updates a feature in this pool.
Protected functions
- void insertFeature(const QgsFeature& feature)
- Inserts a feature into the cache and the spatial index.
- auto isFeatureCached(QgsFeatureId fid) -> bool
- Checks if the feature fid is cached.
- void refreshCache(const QgsFeature& feature)
- Changes a feature in the cache and the spatial index.
- void removeFeature(const QgsFeatureId featureId)
- Removes a feature from the cache and the spatial index.
- void setFeatureIds(const QgsFeatureIds& ids)
- Sets all the feature ids governed by this feature pool.
Function documentation
QgsFeatureIds QgsFeaturePool:: allFeatureIds() const
Returns the complete set of feature ids in this pool.
Note that this concerns the features governed by this pool, which are not necessarily all cached.
void QgsFeaturePool:: deleteFeature(QgsFeatureId fid) pure virtual
Removes a feature from this pool.
Implementations will remove the feature from the layer or from the data provider.
bool QgsFeaturePool:: getFeature(QgsFeatureId id,
QgsFeature& feature,
QgsFeedback* feedback = nullptr)
Retrieves the feature with the specified id into feature.
It will be retrieved from the cache or from the underlying layer if unavailable. If the feature is neither available from the cache nor from the layer it will return false. If feedback is specified, the call may return if the feedback is canceled.
QgsFeatureIds QgsFeaturePool:: getFeatures(const QgsFeatureRequest& request,
QgsFeedback* feedback = nullptr)
Gets features for the provided request.
No features will be fetched from the cache and the request is sent directly to the underlying feature source. Results of the request are cached in the pool and the ids of all the features are returned. This can be used to warm the cache for a particular area of interest (bounding box) or other set of features. If feedback is specified, the call may return if the feedback is canceled.
QgsFeatureIds QgsFeaturePool:: getIntersects(const QgsRectangle& rect) const
Gets all feature ids in the bounding box rect.
It will use a spatial index to determine the ids.
QgsVectorLayer* QgsFeaturePool:: layer() const
Gets a pointer to the underlying layer.
May return a nullptr if the layer has been deleted. This must only be called from the main thread.
QPointer<QgsVectorLayer> QgsFeaturePool:: layerPtr() const
Gets a QPointer to the underlying layer.
Note that access to any methods of the object will need to be done on the main thread and the pointer will need to be checked for validity before usage.
void QgsFeaturePool:: updateFeature(QgsFeature& feature) pure virtual
Updates a feature in this pool.
Implementations will update the feature on the layer or on the data provider.
void QgsFeaturePool:: insertFeature(const QgsFeature& feature) protected
Inserts a feature into the cache and the spatial index.
To be used by implementations of addFeature.
bool QgsFeaturePool:: isFeatureCached(QgsFeatureId fid) protected
Checks if the feature fid is cached.
void QgsFeaturePool:: refreshCache(const QgsFeature& feature) protected
Changes a feature in the cache and the spatial index.
To be used by implementations of updateFeature.
void QgsFeaturePool:: removeFeature(const QgsFeatureId featureId) protected
Removes a feature from the cache and the spatial index.
To be used by implementations of deleteFeature.
void QgsFeaturePool:: setFeatureIds(const QgsFeatureIds& ids) protected
Sets all the feature ids governed by this feature pool.
Should be called by subclasses constructor and whenever they insert a new feature.