QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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
This class represents a coordinate reference system (CRS).
A feature pool is based on a vector layer and caches features.
virtual ~QgsFeaturePool()=default
This class 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:56
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
A rectangle specified with double values.
Definition: qgsrectangle.h:42
A spatial index for QgsFeature objects.
Represents a vector layer which manages a vector based data sets.
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:42
GeometryType
The geometry types are used to group QgsWkbTypes::Type in a coarse way.
Definition: qgswkbtypes.h:141
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_ABSTRACT
Definition: qgis_sip.h:199
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeatureid.h:37
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
Definition: qgsfeatureid.h:28
const QgsCoordinateReferenceSystem & crs