QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsfeaturesink.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfeaturesink.h
3  ----------------
4  begin : April 2017
5  copyright : (C) 2017 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSFEATURESINK_H
19 #define QGSFEATURESINK_H
20 
21 #include "qgis_core.h"
22 #include "qgis.h"
23 #include "qgsfeature.h"
24 #include "qgsfeatureiterator.h"
25 
33 class CORE_EXPORT QgsFeatureSink
34 {
35  public:
36 
38  enum Flag
39  {
40 
48  FastInsert = 1 << 1,
49  };
50  Q_DECLARE_FLAGS( Flags, Flag )
51 
52  virtual ~QgsFeatureSink() = default;
53 
59  virtual bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = nullptr );
60 
66  virtual bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = nullptr ) = 0;
67 
72  virtual bool addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags = nullptr );
73 
78  virtual bool flushBuffer() { return true; }
79 };
80 
81 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFeatureSink::Flags )
82 
83 
84 
97 class CORE_EXPORT QgsProxyFeatureSink : public QgsFeatureSink
98 {
99  public:
100 
105  bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = nullptr ) override { return mSink->addFeature( feature, flags ); }
106  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = nullptr ) override { return mSink->addFeatures( features, flags ); }
107  bool addFeatures( QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags = nullptr ) override { return mSink->addFeatures( iterator, flags ); }
108 
112  QgsFeatureSink *destinationSink() { return mSink; }
113 
114  private:
115 
116  QgsFeatureSink *mSink = nullptr;
117 };
118 
120 
121 #endif // QGSFEATURESINK_H
Wrapper for iterator of features from vector data provider or vector layer.
A simple feature sink which proxies feature addition on to another feature sink.
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:549
An interface for objects which accept features via addFeature(s) methods.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
Q_DECLARE_METATYPE(QModelIndex)
bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=nullptr) override
Adds a list of features to the sink.
bool addFeatures(QgsFeatureIterator &iterator, QgsFeatureSink::Flags flags=nullptr) override
Adds all features from the specified iterator to the sink.
virtual bool flushBuffer()
Flushes any internal buffer which may exist in the sink, causing any buffered features to be added to...
Flag
Flags controlling how features are added to a sink.
bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=nullptr) override
Adds a single feature to the sink.
QgsFeatureSink * destinationSink()
Returns the destination QgsFeatureSink which the proxy will forward features to.