QGIS API Documentation  3.0.2-Girona (307d082)
qgsmemoryprovider.h
Go to the documentation of this file.
1 /***************************************************************************
2  memoryprovider.h - provider with storage in memory
3  ------------------
4  begin : June 2008
5  copyright : (C) 2008 by Martin Dobias
6  email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #define SIP_NO_FILE
17 
18 #include "qgsvectordataprovider.h"
20 #include "qgsfields.h"
21 
23 typedef QMap<QgsFeatureId, QgsFeature> QgsFeatureMap;
24 
25 class QgsSpatialIndex;
26 
27 class QgsMemoryFeatureIterator;
28 
29 class QgsMemoryProvider : public QgsVectorDataProvider
30 {
31  Q_OBJECT
32 
33  public:
34  explicit QgsMemoryProvider( const QString &uri = QString() );
35 
36  ~QgsMemoryProvider() override;
37 
39  static QString providerKey();
41  static QString providerDescription();
42 
43  static QgsMemoryProvider *createProvider( const QString &uri );
44 
45  /* Implementation of functions from QgsVectorDataProvider */
46 
47  QgsAbstractFeatureSource *featureSource() const override;
48 
49  QString dataSourceUri( bool expandAuthConfig = true ) const override;
50  QString storageType() const override;
51  QgsFeatureIterator getFeatures( const QgsFeatureRequest &request ) const override;
52  QgsWkbTypes::Type wkbType() const override;
53  long featureCount() const override;
54  QgsFields fields() const override;
55  bool addFeatures( QgsFeatureList &flist, QgsFeatureSink::Flags flags = nullptr ) override;
56  bool deleteFeatures( const QgsFeatureIds &id ) override;
57  bool addAttributes( const QList<QgsField> &attributes ) override;
58  bool renameAttributes( const QgsFieldNameMap &renamedAttributes ) override;
59  bool deleteAttributes( const QgsAttributeIds &attributes ) override;
60  bool changeAttributeValues( const QgsChangedAttributesMap &attr_map ) override;
61  bool changeGeometryValues( const QgsGeometryMap &geometry_map ) override;
62  QString subsetString() const override;
63  bool setSubsetString( const QString &theSQL, bool updateFeatureCount = true ) override;
64  bool supportsSubsetString() const override { return true; }
65  bool createSpatialIndex() override;
66  QgsVectorDataProvider::Capabilities capabilities() const override;
67 
68  /* Implementation of functions from QgsDataProvider */
69 
70  QString name() const override;
71  QString description() const override;
72  QgsRectangle extent() const override;
73  void updateExtents() override;
74  bool isValid() const override;
75  QgsCoordinateReferenceSystem crs() const override;
76 
77  private:
78  // Coordinate reference system
80 
81  // fields
82  QgsFields mFields;
83  QgsWkbTypes::Type mWkbType;
84  mutable QgsRectangle mExtent;
85 
86  // features
87  QgsFeatureMap mFeatures;
88  QgsFeatureId mNextFeatureId;
89 
90  // indexing
91  QgsSpatialIndex *mSpatialIndex = nullptr;
92 
93  QString mSubsetString;
94 
95  friend class QgsMemoryFeatureSource;
96 };
97 
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:537
virtual bool setSubsetString(const QString &subset, bool updateFeatureCount=true)
Set the subset string used to create a subset of features in the layer.
A rectangle specified with double values.
Definition: qgsrectangle.h:39
virtual QString subsetString() const
Returns the subset definition string (typically sql) currently in use by the layer and used by the pr...
virtual QgsVectorDataProvider::Capabilities capabilities() const
Returns flags containing the supported capabilities.
QgsWkbTypes::Type wkbType() const override=0
Returns the geometry type which is returned by this layer.
virtual void updateExtents()
Update the extents of the layer.
virtual bool addAttributes(const QList< QgsField > &attributes)
Adds new attributes to the provider.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:544
bool addFeatures(QgsFeatureList &flist, QgsFeatureSink::Flags flags=nullptr) override
Adds a list of features to the sink.
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:549
virtual bool deleteFeatures(const QgsFeatureIds &id)
Deletes one or more features from the provider.
virtual bool renameAttributes(const QgsFieldNameMap &renamedAttributes)
Renames existing attributes.
Container of fields for a vector layer.
Definition: qgsfields.h:42
virtual QString name() const =0
Return a provider name.
virtual QgsAbstractFeatureSource * featureSource() const =0
Return feature source object that can be used for querying provider&#39;s data.
QSet< int > QgsAttributeIds
virtual bool createSpatialIndex()
Creates a spatial index on the datasource (if supported by the provider type).
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:67
virtual bool isValid() const =0
Returns true if this is a valid layer.
virtual QgsCoordinateReferenceSystem crs() const =0
Returns the coordinate system for the data source.
QgsFields fields() const override=0
Returns the fields associated with this data provider.
virtual bool changeAttributeValues(const QgsChangedAttributesMap &attr_map)
Changes attribute values of existing features.
virtual QString dataSourceUri(bool expandAuthConfig=false) const
Get the data source specification.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
virtual bool supportsSubsetString() const
Returns true if the provider supports setting of subset strings.
virtual bool changeGeometryValues(const QgsGeometryMap &geometry_map)
Changes geometries of existing features.
Base class that can be used for any class that is capable of returning features.
QMap< int, QString > QgsFieldNameMap
Definition: qgsattributes.h:45
QMap< QgsFeatureId, QgsFeature > QgsFeatureMap
A spatial index for QgsFeature objects.
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:528
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest()) const override=0
Query the provider for features specified in request.
long featureCount() const override=0
Number of features in the layer.
This class represents a coordinate reference system (CRS).
virtual QString description() const =0
Return description.
virtual bool deleteAttributes(const QgsAttributeIds &attributes)
Deletes existing attributes from the provider.
qint64 QgsFeatureId
Definition: qgsfeature.h:37
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
virtual QString storageType() const
Returns the permanent storage type for this layer as a friendly name.
This is the base class for vector data providers.