26 #include <QMutexLocker> 30 : mFeatureCache( CACHE_SIZE )
32 , mLayerId( layer->id() )
33 , mGeometryType( layer->geometryType() )
34 , mCrs( layer->
crs() )
42 QgsFeature *cachedFeature = mFeatureCache.object(
id );
46 feature = *cachedFeature;
54 if ( !source || !source->getFeatures(
QgsFeatureRequest(
id ) ).nextFeature( feature ) )
59 mFeatureCache.insert(
id,
new QgsFeature( feature ) );
96 Q_ASSERT( QThread::currentThread() == qApp->thread() );
109 mFeatureCache.insert( feature.
id(),
new QgsFeature( feature ) );
117 mFeatureCache.remove( feature.
id() );
135 mFeatureCache.remove( origFeature.
id() );
145 return mFeatureCache.contains( fid );
155 return mGeometryType;
bool isFeatureCached(QgsFeatureId fid)
Checks if the feature fid is cached.
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
QgsFeatureIds getIntersects(const QgsRectangle &rect) const
Gets all feature ids in the bounding box rect.
QSet< QgsFeatureId > QgsFeatureIds
bool getFeature(QgsFeatureId id, QgsFeature &feature, QgsFeedback *feedback=nullptr)
Retrieves the feature with the specified id into feature.
static std::unique_ptr< QgsVectorLayerFeatureSource > getFeatureSource(QPointer< QgsVectorLayer > layer, QgsFeedback *feedback=nullptr)
Gets the feature source from a QgsVectorLayer pointer.
QgsFeaturePool(QgsVectorLayer *layer)
Creates a new feature pool for layer.
QPointer< QgsVectorLayer > layerPtr() const
Gets a QPointer to the underlying layer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
const QgsCoordinateReferenceSystem & crs
Base class for feedback objects to be used for cancelation of something running in a worker thread...
The QgsReadWriteLocker class is a convenience class that simplifies locking and unlocking QReadWriteL...
QgsVectorLayer * layer() const
Gets a pointer to the underlying layer.
void insertFeature(const QgsFeature &feature)
Inserts a feature into the cache and the spatial index.
QgsFeatureIds getFeatures(const QgsFeatureRequest &request, QgsFeedback *feedback=nullptr)
Gets features for the provided request.
void refreshCache(const QgsFeature &feature)
Changes a feature in the cache and the spatial index.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
void unlock()
Unlocks the lock.
bool deleteFeature(const QgsFeature &feature)
Removes a feature from the index.
void setFeatureIds(const QgsFeatureIds &ids)
Sets all the feature ids governed by this feature pool.
This class represents a coordinate reference system (CRS).
void changeMode(Mode mode)
Change the mode of the lock to mode.
QgsCoordinateReferenceSystem crs() const
The coordinate reference system of this layer.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=nullptr) override
Adds a feature to the index.
bool nextFeature(QgsFeature &f)
QgsWkbTypes::GeometryType geometryType() const
The geometry type of this layer.
Represents a vector layer which manages a vector based data sets.
QgsFeatureIds allFeatureIds() const
Returns the complete set of feature ids in this pool.
QList< QgsFeatureId > intersects(const QgsRectangle &rectangle) const
Returns a list of features with a bounding box which intersects the specified rectangle.
void removeFeature(const QgsFeatureId featureId)
Removes a feature from the cache and the spatial index.
QString layerId() const
The layer id of the layer.