QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 <QCache>
21 #include <QMutex>
22 #include <QPointer>
23 
24 #include "qgis_analysis.h"
25 #include "qgsfeature.h"
26 #include "qgsspatialindex.h"
27 #include "qgsfeaturesink.h"
29 
37 class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
38 {
39 
40  public:
41 
46  virtual ~QgsFeaturePool() = default;
47 
53  bool getFeature( QgsFeatureId id, QgsFeature &feature );
54 
65  QgsFeatureIds getFeatures( const QgsFeatureRequest &request, QgsFeedback *feedback = nullptr ) SIP_SKIP;
66 
71  virtual void updateFeature( QgsFeature &feature ) = 0;
72 
77  virtual void deleteFeature( QgsFeatureId fid ) = 0;
78 
85  QgsFeatureIds allFeatureIds() const SIP_SKIP;
86 
93  QgsFeatureIds getIntersects( const QgsRectangle &rect ) const SIP_SKIP;
94 
100  QgsVectorLayer *layer() const;
101 
111  QPointer<QgsVectorLayer> layerPtr() const SIP_SKIP;
112 
116  QString layerId() const;
117 
121  QgsWkbTypes::GeometryType geometryType() const;
122 
127 
134  QString layerName() const;
135 
136  protected:
137 
142  void insertFeature( const QgsFeature &feature, bool skipLock = false );
143 
148  void refreshCache( const QgsFeature &feature );
149 
154  void removeFeature( const QgsFeatureId featureId );
155 
163  void setFeatureIds( const QgsFeatureIds &ids ) SIP_SKIP;
164 
171  bool isFeatureCached( QgsFeatureId fid ) SIP_SKIP;
172 
173  private:
174 #ifdef SIP_RUN
175  QgsFeaturePool( const QgsFeaturePool &other )
176  {}
177 #endif
178 
179  static const int CACHE_SIZE = 1000;
180  QCache<QgsFeatureId, QgsFeature> mFeatureCache;
181  QPointer<QgsVectorLayer> mLayer;
182  mutable QReadWriteLock mCacheLock;
183  QgsFeatureIds mFeatureIds;
184  QgsSpatialIndex mIndex;
185  QgsWkbTypes::GeometryType mGeometryType;
186  std::unique_ptr<QgsVectorLayerFeatureSource> mFeatureSource;
187  QString mLayerName;
188 };
189 
190 #endif // QGS_FEATUREPOOL_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:34
An interface for objects which accept features via addFeature(s) methods.
qint64 QgsFeatureId
Definition: qgsfeatureid.h:25
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
const QgsCoordinateReferenceSystem & crs
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:44
#define SIP_ABSTRACT
Definition: qgis_sip.h:194
#define SIP_SKIP
Definition: qgis_sip.h:126
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.
Definition: qgswkbtypes.h:139
A spatial index for QgsFeature objects.
A feature pool is based on a vector layer and caches features.
This class represents a coordinate reference system (CRS).
Represents a vector layer which manages a vector based data sets.