QGIS API Documentation  3.6.0-Noosa (5873452)
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"
28 
29 class QgsVectorLayer;
30 
38 class ANALYSIS_EXPORT QgsFeaturePool : public QgsFeatureSink SIP_ABSTRACT
39 {
40 
41  public:
42 
47  virtual ~QgsFeaturePool() = default;
48 
55  bool getFeature( QgsFeatureId id, QgsFeature &feature, QgsFeedback *feedback = nullptr );
56 
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 
128  protected:
129 
134  void insertFeature( const QgsFeature &feature );
135 
140  void refreshCache( const QgsFeature &feature );
141 
146  void removeFeature( const QgsFeatureId featureId );
147 
155  void setFeatureIds( const QgsFeatureIds &ids ) SIP_SKIP;
156 
163  bool isFeatureCached( QgsFeatureId fid ) SIP_SKIP;
164 
165  private:
166 #ifdef SIP_RUN
167  QgsFeaturePool( const QgsFeaturePool &other )
168  {}
169 #endif
170 
171  static const int CACHE_SIZE = 1000;
172  QCache<QgsFeatureId, QgsFeature> mFeatureCache;
173  QPointer<QgsVectorLayer> mLayer;
174  mutable QReadWriteLock mCacheLock;
175  QgsFeatureIds mFeatureIds;
176  QgsSpatialIndex mIndex;
177  QString mLayerId;
178  QgsWkbTypes::GeometryType mGeometryType;
180 };
181 
182 #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 cancelation of something running in a worker thread...
Definition: qgsfeedback.h:44
#define SIP_ABSTRACT
Definition: qgis_sip.h:187
#define SIP_SKIP
Definition: qgis_sip.h:119
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:138
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.