QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsfeaturestore.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfeaturestore.h
3  --------------------------------------
4  Date : February 2013
5  Copyright : (C) 2013 by Radim Blazek
6  Email : [email protected]
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 #ifndef QGSFEATURESTORE_H
16 #define QGSFEATURESTORE_H
17 
18 #include "qgis_core.h"
19 #include "qgis_sip.h"
20 #include "qgsfeature.h"
21 #include "qgsfields.h"
22 #include "qgsfeaturesink.h"
24 #include <QList>
25 #include <QMetaType>
26 #include <QVariant>
27 
32 class CORE_EXPORT QgsFeatureStore : public QgsFeatureSink
33 {
34  public:
36  QgsFeatureStore() = default;
37 
40 
45  QgsFields fields() const { return mFields; }
46 
51  void setFields( const QgsFields &fields );
52 
57  QgsCoordinateReferenceSystem crs() const { return mCrs; }
58 
63  void setCrs( const QgsCoordinateReferenceSystem &crs ) { mCrs = crs; }
64 
65  bool addFeature( QgsFeature &feature, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
66  bool addFeatures( QgsFeatureList &features, QgsFeatureSink::Flags flags = QgsFeatureSink::Flags() ) override;
67 
71  int count() const { return mFeatures.size(); }
72 
73 #ifdef SIP_RUN
74 
78  int __len__() const;
79  % MethodCode
80  sipRes = sipCpp->count();
81  % End
82 
84  int __bool__() const;
85  % MethodCode
86  sipRes = true;
87  % End
88 #endif
89 
93  QgsFeatureList features() const { return mFeatures; }
94 
99  void setParams( const QMap<QString, QVariant> &parameters ) { mParams = parameters; }
100 
105  QMap<QString, QVariant> params() const { return mParams; }
106 
107  private:
108  QgsFields mFields;
109 
111 
112  QgsFeatureList mFeatures;
113 
114  // Optional parameters
115  QMap<QString, QVariant> mParams;
116 };
117 
118 #ifndef SIP_RUN
119 typedef QVector<QgsFeatureStore> QgsFeatureStoreList;
120 #else
121 typedef QVector<QgsFeatureStore> QgsFeatureStoreList;
122 
123 % MappedType QgsFeatureStoreList
124 {
125  % TypeHeaderCode
126 #include "qgsfeaturestore.h"
127  % End
128 
129  % ConvertFromTypeCode
130  // Create the list.
131  PyObject *l;
132 
133  if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
134  return NULL;
135 
136  // Set the list elements.
137  for ( int i = 0; i < sipCpp->size(); ++i )
138  {
139  QgsFeatureStore *v = new QgsFeatureStore( sipCpp->at( i ) );
140  PyObject *tobj;
141 
142  if ( ( tobj = sipConvertFromNewType( v, sipType_QgsFeatureStore, Py_None ) ) == NULL )
143  {
144  Py_DECREF( l );
145  delete v;
146 
147  return NULL;
148  }
149 
150  PyList_SET_ITEM( l, i, tobj );
151  }
152 
153  return l;
154  % End
155 
156  % ConvertToTypeCode
157  // Check the type if that is all that is required.
158  if ( sipIsErr == NULL )
159  {
160  if ( !PyList_Check( sipPy ) )
161  return 0;
162 
163  for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
164  if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QgsFeatureStore, SIP_NOT_NONE ) )
165  return 0;
166 
167  return 1;
168  }
169 
171  SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
172  qv->reserve( listSize );
173 
174  for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
175  {
176  PyObject *obj = PyList_GET_ITEM( sipPy, i );
177  int state;
178  QgsFeatureStore *t = reinterpret_cast<QgsFeatureStore *>( sipConvertToType( obj, sipType_QgsFeatureStore, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );
179 
180  if ( *sipIsErr )
181  {
182  sipReleaseType( t, sipType_QgsFeatureStore, state );
183 
184  delete qv;
185  return 0;
186  }
187 
188  qv->append( *t );
189  sipReleaseType( t, sipType_QgsFeatureStore, state );
190  }
191 
192  *sipCppPtr = qv;
193 
194  return sipGetState( sipTransferObj );
195  % End
196 };
197 #endif
198 
200 
202 
203 #endif
This class represents a coordinate reference system (CRS).
An interface for objects which accept features via addFeature(s) methods.
virtual bool addFeature(QgsFeature &feature, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())
Adds a single feature to the sink.
virtual bool addFeatures(QgsFeatureList &features, QgsFeatureSink::Flags flags=QgsFeatureSink::Flags())=0
Adds a list of features to the sink.
A container for features with the same fields and crs.
QgsFeatureList features() const
Returns the list of features contained in the store.
QMap< QString, QVariant > params() const
Returns the map of optional parameters.
QgsFields fields() const
Returns the store's field list.
void setCrs(const QgsCoordinateReferenceSystem &crs)
Sets the store's crs.
int count() const
Returns the number of features contained in the store.
QgsCoordinateReferenceSystem crs() const
Returns the store's coordinate reference system.
void setParams(const QMap< QString, QVariant > &parameters)
Sets a map of optional parameters for the store.
QgsFeatureStore()=default
Constructor.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Container of fields for a vector layer.
Definition: qgsfields.h:45
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:736
QVector< QgsFeatureStore > QgsFeatureStoreList
Q_DECLARE_METATYPE(QgsMeshTimeSettings)
const QgsCoordinateReferenceSystem & crs