QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsvectordataprovider.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectordataprovider.h - DataProvider Interface for vector layers
3  --------------------------------------
4  Date : 23-Sep-2004
5  Copyright : (C) 2004 by Marco Hugentobler
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 QGSVECTORDATAPROVIDER_H
16 #define QGSVECTORDATAPROVIDER_H
17 
18 class QTextCodec;
19 
20 #include <QList>
21 #include <QSet>
22 #include <QMap>
23 #include <QHash>
24 
25 //QGIS Includes
26 #include "qgis.h"
27 #include "qgsdataprovider.h"
28 #include "qgsfeature.h"
29 #include "qgsfield.h"
30 #include "qgsrectangle.h"
31 #include "qgsaggregatecalculator.h"
32 
36 
37 class QgsFeatureIterator;
38 class QgsTransaction;
39 
40 #include "qgsfeaturerequest.h"
41 
50 class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
51 {
52  Q_OBJECT
53 
54  friend class QgsTransaction;
56 
57  public:
58 
59  // If you add to this, please also add to capabilitiesString()
64  {
66  NoCapabilities = 0,
68  AddFeatures = 1,
70  DeleteFeatures = 1 << 1,
72  ChangeAttributeValues = 1 << 2,
74  AddAttributes = 1 << 3,
76  DeleteAttributes = 1 << 4,
78  SaveAsShapefile = 1 << 5,
80  CreateSpatialIndex = 1 << 6,
82  SelectAtId = 1 << 7,
84  ChangeGeometries = 1 << 8,
86  SelectGeometryAtId = 1 << 9,
88  RandomSelectGeometryAtId = 1 << 10,
90  SequentialSelectGeometryAtId = 1 << 11,
92  CreateAttributeIndex = 1 << 12,
94  SelectEncoding = 1 << 13,
96  SimplifyGeometries = 1 << 14,
98  SimplifyGeometriesWithTopologicalValidation = 1 << 15,
100  TransactionSupport = 1 << 16,
102  CircularGeometries = 1 << 17,
106  ChangeFeatures = 1 << 18,
108  RenameAttributes = 1 << 19,
109  };
110 
112  const static int EditingCapabilities = AddFeatures | DeleteFeatures |
113  ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes |
114  RenameAttributes;
115 
120  QgsVectorDataProvider( const QString& uri = QString() );
121 
125  virtual ~QgsVectorDataProvider();
126 
143  virtual QgsAbstractFeatureSource *featureSource() const = 0;
144 
148  virtual QString storageType() const;
149 
153  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
154 
159  virtual QGis::WkbType geometryType() const = 0;
160 
165  virtual long featureCount() const = 0;
166 
172  // TODO QGIS 3: return by value
173  virtual const QgsFields &fields() const = 0;
174 
179  virtual QString dataComment() const;
180 
189  virtual QVariant minimumValue( int index );
190 
199  virtual QVariant maximumValue( int index );
200 
209  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
210 
221  virtual QVariant aggregate( QgsAggregateCalculator::Aggregate aggregate,
222  int index,
224  QgsExpressionContext* context,
225  bool& ok );
226 
233  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
234 
239  virtual bool addFeatures( QgsFeatureList &flist );
240 
246  virtual bool deleteFeatures( const QgsFeatureIds &id );
247 
253  virtual bool addAttributes( const QList<QgsField> &attributes );
254 
260  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
261 
268  virtual bool renameAttributes( const QgsFieldNameMap& renamedAttributes );
269 
275  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
276 
285  virtual bool changeFeatures( const QgsChangedAttributesMap &attr_map,
286  const QgsGeometryMap &geometry_map );
287 
293  virtual QVariant defaultValue( int fieldId, bool forceLazyEval = false );
294 
302  virtual bool changeGeometryValues( const QgsGeometryMap &geometry_map );
303 
308  virtual bool createSpatialIndex();
309 
311  virtual bool createAttributeIndex( int field );
312 
318  virtual int capabilities() const;
319 
323  QString capabilitiesString() const;
324 
328  virtual void setEncoding( const QString& e );
329 
333  QString encoding() const;
334 
338  int fieldNameIndex( const QString& fieldName ) const;
339 
343  QMap<QString, int> fieldNameMap() const;
344 
348  virtual QgsAttributeList attributeIndexes();
349 
354 
358  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
359 
363  bool supportedType( const QgsField &field ) const;
364 
365  struct NativeType
366  {
367  NativeType( const QString& typeDesc, const QString& typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 )
368  : mTypeDesc( typeDesc )
369  , mTypeName( typeName )
370  , mType( type )
371  , mMinLen( minLen )
372  , mMaxLen( maxLen )
373  , mMinPrec( minPrec )
374  , mMaxPrec( maxPrec )
375  {}
376 
379  QVariant::Type mType;
380  int mMinLen;
381  int mMaxLen;
382  int mMinPrec;
383  int mMaxPrec;
384  };
385 
389  const QList< NativeType > &nativeTypes() const;
390 
395  virtual bool doesStrictFeatureTypeCheck() const { return true;}
396 
398  static const QStringList &availableEncodings();
399 
403  bool hasErrors();
404 
408  void clearErrors();
409 
413  QStringList errors();
414 
415 
420  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
421 
422  static QVariant convertValue( QVariant::Type type, const QString& value );
423 
427  virtual QgsTransaction* transaction() const { return nullptr; }
428 
436  virtual void forceReload()
437  {
438  emit dataChanged();
439  }
440 
444  virtual QSet<QString> layerDependencies() const;
445 
446  signals:
448  void raiseError( const QString& msg );
449 
450  protected:
451  void clearMinMaxCache();
452  void fillMinMaxCache();
453 
456 
459 
462 
465 
466  void pushError( const QString& msg );
467 
470 
483  QgsGeometry* convertToProviderType( const QgsGeometry* geom ) const;
484 
485  private:
487  QMap<QString, QVariant::Type> mOldTypeList;
488 
490  QStringList mErrors;
491 
492  static QStringList smEncodings;
493 
497  virtual void setTransaction( QgsTransaction* /*transaction*/ ) {}
498 
499 };
500 
501 
502 #endif
void clear()
Wrapper for iterator of features from vector data provider or vector layer.
static unsigned index
virtual bool addFeatures(QgsFeatureList &features)
Insert a copy of the given features into the layer (but does not commit it)
QgsAttributeList mAttributesToFetch
List of attribute indices to fetch with nextFeature calls.
virtual void enumValues(int index, QStringList &enumList)
Returns the possible enum values of an attribute.
Container of fields for a vector layer.
Definition: qgsfield.h:252
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
WkbType
Used for symbology operations.
Definition: qgis.h:61
Abstract base class for spatial data provider implementations.
QList< int > QgsAttributeList
virtual QgsAttributeList pkAttributeIndexes()
Return list of indexes of fields that make up the primary key.
virtual bool doesStrictFeatureTypeCheck() const
Returns true if the provider is strict about the type of inserted features (e.g.
QSet< int > QgsAttributeIds
QTextCodec * mEncoding
Encoding.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Capability
enumeration with capabilities that providers might implement
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< NativeType > mNativeTypes
The names of the providers native types.
virtual bool deleteFeatures(const QgsFeatureIds &fid)
Deletes a set of features from the layer (but does not commit it)
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
virtual bool changeAttributeValues(QgsFeatureId fid, const QgsAttributeMap &newValues, const QgsAttributeMap &oldValues)
Changes values of attributes (but does not commit it).
Base class that can be used for any class that is capable of returning features.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
QgsAttrPalIndexNameHash mAttrPalIndexName
Old-style mapping of index to name for QgsPalLabeling fix.
NativeType(const QString &typeDesc, const QString &typeName, QVariant::Type type, int minLen=0, int maxLen=0, int minPrec=0, int maxPrec=0)
virtual void forceReload()
Forces a reload of the underlying datasource if the provider implements this method.
This is the base class for vector data providers.
virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const
Return list of indexes to names for QgsPalLabeling fix.
QHash< int, QString > QgsAttrPalIndexNameHash
Aggregate
Available aggregates to calculate.
QMap< int, QVariant > mCacheMinValues
virtual bool isSaveAndLoadStyleToDBSupported()
It returns false by default.
A bundle of parameters controlling aggregate calculation.