QGIS API Documentation  2.15.0-Master (af20121)
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
106  };
107 
109  const static int EditingCapabilities = AddFeatures | DeleteFeatures |
110  ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;
111 
116  QgsVectorDataProvider( const QString& uri = QString() );
117 
121  virtual ~QgsVectorDataProvider();
122 
139  virtual QgsAbstractFeatureSource* featureSource() const { Q_ASSERT( 0 && "All providers must support featureSource()" ); return nullptr; }
140 
144  virtual QString storageType() const;
145 
149  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
150 
155  virtual QGis::WkbType geometryType() const = 0;
156 
161  virtual long featureCount() const = 0;
162 
168  virtual const QgsFields &fields() const = 0;
169 
174  virtual QString dataComment() const;
175 
184  virtual QVariant minimumValue( int index );
185 
194  virtual QVariant maximumValue( int index );
195 
204  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
205 
216  virtual QVariant aggregate( QgsAggregateCalculator::Aggregate aggregate,
217  int index,
219  QgsExpressionContext* context,
220  bool& ok );
221 
228  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
229 
234  virtual bool addFeatures( QgsFeatureList &flist );
235 
241  virtual bool deleteFeatures( const QgsFeatureIds &id );
242 
248  virtual bool addAttributes( const QList<QgsField> &attributes );
249 
255  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
256 
262  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
263 
272  virtual bool changeFeatures( const QgsChangedAttributesMap &attr_map,
273  const QgsGeometryMap &geometry_map );
274 
278  virtual QVariant defaultValue( int fieldId );
279 
287  virtual bool changeGeometryValues( const QgsGeometryMap &geometry_map );
288 
293  virtual bool createSpatialIndex();
294 
296  virtual bool createAttributeIndex( int field );
297 
303  virtual int capabilities() const;
304 
308  QString capabilitiesString() const;
309 
313  virtual void setEncoding( const QString& e );
314 
318  QString encoding() const;
319 
323  int fieldNameIndex( const QString& fieldName ) const;
324 
328  QMap<QString, int> fieldNameMap() const;
329 
333  virtual QgsAttributeList attributeIndexes();
334 
339 
343  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
344 
348  bool supportedType( const QgsField &field ) const;
349 
350  struct NativeType
351  {
352  NativeType( const QString& typeDesc, const QString& typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 )
353  : mTypeDesc( typeDesc )
354  , mTypeName( typeName )
355  , mType( type )
356  , mMinLen( minLen )
357  , mMaxLen( maxLen )
358  , mMinPrec( minPrec )
359  , mMaxPrec( maxPrec )
360  {}
361 
364  QVariant::Type mType;
365  int mMinLen;
366  int mMaxLen;
367  int mMinPrec;
368  int mMaxPrec;
369  };
370 
374  const QList< NativeType > &nativeTypes() const;
375 
380  virtual bool doesStrictFeatureTypeCheck() const { return true;}
381 
383  static const QStringList &availableEncodings();
384 
388  bool hasErrors();
389 
393  void clearErrors();
394 
398  QStringList errors();
399 
400 
405  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
406 
407  static QVariant convertValue( QVariant::Type type, const QString& value );
408 
412  virtual QgsTransaction* transaction() const { return nullptr; }
413 
421  virtual void forceReload()
422  {
423  emit dataChanged();
424  }
425 
429  virtual QSet<QString> layerDependencies() const;
430 
431  signals:
433  void raiseError( const QString& msg );
434 
435  protected:
436  void clearMinMaxCache();
437  void fillMinMaxCache();
438 
441 
444 
447 
450 
451  void pushError( const QString& msg );
452 
455 
458  QgsGeometry* convertToProviderType( const QgsGeometry* geom ) const;
459 
460  private:
462  QMap<QString, QVariant::Type> mOldTypeList;
463 
465  QStringList mErrors;
466 
467  static QStringList smEncodings;
468 
472  virtual void setTransaction( QgsTransaction* /*transaction*/ ) {}
473 
474 };
475 
476 
477 #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:193
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 QgsAbstractFeatureSource * featureSource() const
Return feature source object that can be used for querying provider&#39;s data.
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.