QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsfeaturepool.h
Go to the documentation of this file.
1/***************************************************************************
2 * qgsfeaturepool.h *
3 * ------------------- *
4 * copyright : (C) 2014 by Sandro Mani / Sourcepole AG *
5 * email : [email protected] *
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#ifndef QGS_FEATUREPOOL_H
18#define QGS_FEATUREPOOL_H
19
20#include "qgis_analysis.h"
21#include "qgsfeature.h"
22#include "qgsfeaturesink.h"
23#include "qgsspatialindex.h"
25
26#include <QCache>
27#include <QMutex>
28#include <QPointer>
29
37class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
38{
39 public:
46 ~QgsFeaturePool() override = default;
47
56 bool getFeature( QgsFeatureId id, QgsFeature &feature );
57
70 QgsFeatureIds getFeatures( const QgsFeatureRequest &request, QgsFeedback *feedback = nullptr ) SIP_SKIP;
71
80 virtual void updateFeature( QgsFeature &feature ) = 0;
81
90 virtual void deleteFeature( QgsFeatureId fid ) = 0;
91
102
113
120 QgsVectorLayer *layer() const;
121
132 QPointer<QgsVectorLayer> layerPtr() const SIP_SKIP;
133
137 QString layerId() const;
138
142 Qgis::GeometryType geometryType() const;
143
148
155 QString layerName() const;
156
157 protected:
165 void insertFeature( const QgsFeature &feature, bool skipLock = false );
166
178 void refreshCache( QgsFeature feature, const QgsFeature &origFeature );
179
187 void removeFeature( const QgsFeatureId featureId );
188
196 void setFeatureIds( const QgsFeatureIds &ids ) SIP_SKIP;
197
205
206 private:
207#ifdef SIP_RUN
208 QgsFeaturePool( const QgsFeaturePool &other )
209 {}
210#endif
211
212 static const int CACHE_SIZE = 1000;
213 QCache<QgsFeatureId, QgsFeature> mFeatureCache;
214 QPointer<QgsVectorLayer> mLayer;
215 mutable QReadWriteLock mCacheLock;
216 QgsFeatureIds mFeatureIds;
217 QgsSpatialIndex mIndex;
218 Qgis::GeometryType mGeometryType;
219 std::unique_ptr<QgsVectorLayerFeatureSource> mFeatureSource;
220 QString mLayerId;
221 QString mLayerName;
223
234 QHash<QgsFeatureId, QgsFeature> mUpdatedFeatures;
235
237};
238
239#endif // QGS_FEATUREPOOL_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:56
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
Definition qgis.h:358
Represents a coordinate reference system (CRS).
virtual void updateFeature(QgsFeature &feature)=0
Updates a feature in this pool.
Qgis::GeometryType geometryType() const
The geometry type of this layer.
QgsFeaturePool(QgsVectorLayer *layer)
Creates a new feature pool for layer.
void refreshCache(QgsFeature feature, const QgsFeature &origFeature)
Changes a feature in the cache and the spatial index.
QgsFeatureIds allFeatureIds() const
Returns the complete set of feature ids in this pool.
friend class TestQgsVectorLayerFeaturePool
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.
~QgsFeaturePool() override=default
QgsCoordinateReferenceSystem crs() const
The coordinate reference system of this layer.
QgsFeatureIds getFeatures(const QgsFeatureRequest &request, QgsFeedback *feedback=nullptr)
Gets features for the provided request.
virtual void deleteFeature(QgsFeatureId fid)=0
Removes a feature from this pool.
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.
Wraps a request for features to a vector layer (or directly its vector data provider).
An interface for objects which accept features via addFeature(s) methods.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
A rectangle specified with double values.
A spatial index for QgsFeature objects.
Represents a vector layer which manages a vector based dataset.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_ABSTRACT
Definition qgis_sip.h:221
QSet< QgsFeatureId > QgsFeatureIds
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features