QGIS API Documentation  2.17.0-Master (f49f7ce)
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;
55 
56  public:
57 
58  // If you add to this, please also add to capabilitiesString()
63  {
65  NoCapabilities = 0,
67  AddFeatures = 1,
69  DeleteFeatures = 1 << 1,
71  ChangeAttributeValues = 1 << 2,
73  AddAttributes = 1 << 3,
75  DeleteAttributes = 1 << 4,
77  SaveAsShapefile = 1 << 5,
79  CreateSpatialIndex = 1 << 6,
81  SelectAtId = 1 << 7,
83  ChangeGeometries = 1 << 8,
85  SelectGeometryAtId = 1 << 9,
87  RandomSelectGeometryAtId = 1 << 10,
89  SequentialSelectGeometryAtId = 1 << 11,
91  CreateAttributeIndex = 1 << 12,
93  SelectEncoding = 1 << 13,
95  SimplifyGeometries = 1 << 14,
97  SimplifyGeometriesWithTopologicalValidation = 1 << 15,
99  TransactionSupport = 1 << 16,
101  CircularGeometries = 1 << 17,
105  ChangeFeatures = 1 << 18,
107  RenameAttributes = 1 << 19,
108  };
109 
111  const static int EditingCapabilities = AddFeatures | DeleteFeatures |
112  ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes |
113  RenameAttributes;
114 
119  QgsVectorDataProvider( const QString& uri = QString() );
120 
124  virtual ~QgsVectorDataProvider();
125 
142  virtual QgsAbstractFeatureSource *featureSource() const = 0;
143 
147  virtual QString storageType() const;
148 
152  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
153 
158  virtual QGis::WkbType geometryType() const = 0;
159 
164  virtual long featureCount() const = 0;
165 
171  // TODO QGIS 3: return by value
172  virtual const QgsFields &fields() const = 0;
173 
178  virtual QString dataComment() const;
179 
188  virtual QVariant minimumValue( int index );
189 
198  virtual QVariant maximumValue( int index );
199 
208  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
209 
220  virtual QVariant aggregate( QgsAggregateCalculator::Aggregate aggregate,
221  int index,
223  QgsExpressionContext* context,
224  bool& ok );
225 
232  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
233 
238  virtual bool addFeatures( QgsFeatureList &flist );
239 
245  virtual bool deleteFeatures( const QgsFeatureIds &id );
246 
252  virtual bool addAttributes( const QList<QgsField> &attributes );
253 
259  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
260 
267  virtual bool renameAttributes( const QgsFieldNameMap& renamedAttributes );
268 
274  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
275 
284  virtual bool changeFeatures( const QgsChangedAttributesMap &attr_map,
285  const QgsGeometryMap &geometry_map );
286 
290  virtual QVariant defaultValue( int fieldId );
291 
299  virtual bool changeGeometryValues( const QgsGeometryMap &geometry_map );
300 
305  virtual bool createSpatialIndex();
306 
308  virtual bool createAttributeIndex( int field );
309 
315  virtual int capabilities() const;
316 
320  QString capabilitiesString() const;
321 
325  virtual void setEncoding( const QString& e );
326 
330  QString encoding() const;
331 
335  int fieldNameIndex( const QString& fieldName ) const;
336 
340  QMap<QString, int> fieldNameMap() const;
341 
345  virtual QgsAttributeList attributeIndexes();
346 
351 
355  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
356 
360  bool supportedType( const QgsField &field ) const;
361 
362  struct NativeType
363  {
364  NativeType( const QString& typeDesc, const QString& typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 )
365  : mTypeDesc( typeDesc )
366  , mTypeName( typeName )
367  , mType( type )
368  , mMinLen( minLen )
369  , mMaxLen( maxLen )
370  , mMinPrec( minPrec )
371  , mMaxPrec( maxPrec )
372  {}
373 
376  QVariant::Type mType;
377  int mMinLen;
378  int mMaxLen;
379  int mMinPrec;
380  int mMaxPrec;
381  };
382 
386  const QList< NativeType > &nativeTypes() const;
387 
392  virtual bool doesStrictFeatureTypeCheck() const { return true;}
393 
395  static const QStringList &availableEncodings();
396 
400  bool hasErrors();
401 
405  void clearErrors();
406 
410  QStringList errors();
411 
412 
417  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
418 
419  static QVariant convertValue( QVariant::Type type, const QString& value );
420 
424  virtual QgsTransaction* transaction() const { return nullptr; }
425 
433  virtual void forceReload()
434  {
435  emit dataChanged();
436  }
437 
441  virtual QSet<QString> layerDependencies() const;
442 
443  signals:
445  void raiseError( const QString& msg );
446 
447  protected:
448  void clearMinMaxCache();
449  void fillMinMaxCache();
450 
453 
456 
459 
462 
463  void pushError( const QString& msg );
464 
467 
470  QgsGeometry* convertToProviderType( const QgsGeometry* geom ) const;
471 
472  private:
474  QMap<QString, QVariant::Type> mOldTypeList;
475 
477  QStringList mErrors;
478 
479  static QStringList smEncodings;
480 
484  virtual void setTransaction( QgsTransaction* /*transaction*/ ) {}
485 
486 };
487 
488 
489 #endif
void clear()
Wrapper for iterator of features from vector data provider or vector layer.
static unsigned index
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.
virtual QgsTransaction * transaction() const
Returns the transaction this data provider is included in, if any.
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.
QSet< int > QgsAttributeIds
QTextCodec * mEncoding
Encoding.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const
Return list of indexes to names for QgsPalLabeling fix.
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.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:44
Base class that can be used for any class that is capable of returning features.
virtual bool doesStrictFeatureTypeCheck() const
Returns true if the provider is strict about the type of inserted features (e.g.
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.
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.