QGIS API Documentation 3.99.0-Master (26c88405ac0)
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:
40
47 ~QgsFeaturePool() override = default;
48
57 bool getFeature( QgsFeatureId id, QgsFeature &feature );
58
71 QgsFeatureIds getFeatures( const QgsFeatureRequest &request, QgsFeedback *feedback = nullptr ) SIP_SKIP;
72
81 virtual void updateFeature( QgsFeature &feature ) = 0;
82
91 virtual void deleteFeature( QgsFeatureId fid ) = 0;
92
103
114
121 QgsVectorLayer *layer() const;
122
133 QPointer<QgsVectorLayer> layerPtr() const SIP_SKIP;
134
138 QString layerId() const;
139
143 Qgis::GeometryType geometryType() const;
144
149
156 QString layerName() const;
157
158 protected:
159
167 void insertFeature( const QgsFeature &feature, bool skipLock = false );
168
180 void refreshCache( QgsFeature feature, const QgsFeature &origFeature );
181
189 void removeFeature( const QgsFeatureId featureId );
190
198 void setFeatureIds( const QgsFeatureIds &ids ) SIP_SKIP;
199
207
208 private:
209#ifdef SIP_RUN
210 QgsFeaturePool( const QgsFeaturePool &other )
211 {}
212#endif
213
214 static const int CACHE_SIZE = 1000;
215 QCache<QgsFeatureId, QgsFeature> mFeatureCache;
216 QPointer<QgsVectorLayer> mLayer;
217 mutable QReadWriteLock mCacheLock;
218 QgsFeatureIds mFeatureIds;
219 QgsSpatialIndex mIndex;
220 Qgis::GeometryType mGeometryType;
221 std::unique_ptr<QgsVectorLayerFeatureSource> mFeatureSource;
222 QString mLayerId;
223 QString mLayerName;
225
236 QHash<QgsFeatureId, QgsFeature> mUpdatedFeatures;
237
239};
240
241#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