QGIS API Documentation
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 
35 
36 class QgsFeatureIterator;
37 class QgsTransaction;
38 
39 #include "qgsfeaturerequest.h"
40 
49 class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
50 {
51  Q_OBJECT
52 
53  friend class QgsTransaction;
54 
55  public:
56 
57  // If you add to this, please also add to capabilitiesString()
62  {
64  NoCapabilities = 0,
66  AddFeatures = 1,
68  DeleteFeatures = 1 << 1,
70  ChangeAttributeValues = 1 << 2,
72  AddAttributes = 1 << 3,
74  DeleteAttributes = 1 << 4,
76  SaveAsShapefile = 1 << 5,
78  CreateSpatialIndex = 1 << 6,
80  SelectAtId = 1 << 7,
82  ChangeGeometries = 1 << 8,
84  SelectGeometryAtId = 1 << 9,
86  RandomSelectGeometryAtId = 1 << 10,
88  SequentialSelectGeometryAtId = 1 << 11,
90  CreateAttributeIndex = 1 << 12,
92  SelectEncoding = 1 << 13,
94  SimplifyGeometries = 1 << 14,
96  SimplifyGeometriesWithTopologicalValidation = 1 << 15,
98  TransactionSupport = 1 << 16,
100  CircularGeometries = 1 << 17,
104  ChangeFeatures = 1 << 18
105  };
106 
108  const static int EditingCapabilities = AddFeatures | DeleteFeatures |
109  ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;
110 
115  QgsVectorDataProvider( const QString& uri = QString() );
116 
120  virtual ~QgsVectorDataProvider();
121 
138  virtual QgsAbstractFeatureSource* featureSource() const { Q_ASSERT( 0 && "All providers must support featureSource()" ); return nullptr; }
139 
143  virtual QString storageType() const;
144 
148  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
149 
154  virtual QGis::WkbType geometryType() const = 0;
155 
160  virtual long featureCount() const = 0;
161 
167  virtual const QgsFields &fields() const = 0;
168 
173  virtual QString dataComment() const;
174 
183  virtual QVariant minimumValue( int index );
184 
193  virtual QVariant maximumValue( int index );
194 
203  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
204 
211  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
212 
217  virtual bool addFeatures( QgsFeatureList &flist );
218 
224  virtual bool deleteFeatures( const QgsFeatureIds &id );
225 
231  virtual bool addAttributes( const QList<QgsField> &attributes );
232 
238  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
239 
245  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
246 
255  virtual bool changeFeatures( const QgsChangedAttributesMap &attr_map,
256  const QgsGeometryMap &geometry_map );
257 
261  virtual QVariant defaultValue( int fieldId );
262 
270  virtual bool changeGeometryValues( const QgsGeometryMap &geometry_map );
271 
276  virtual bool createSpatialIndex();
277 
279  virtual bool createAttributeIndex( int field );
280 
286  virtual int capabilities() const;
287 
291  QString capabilitiesString() const;
292 
296  virtual void setEncoding( const QString& e );
297 
301  QString encoding() const;
302 
306  int fieldNameIndex( const QString& fieldName ) const;
307 
311  QMap<QString, int> fieldNameMap() const;
312 
316  virtual QgsAttributeList attributeIndexes();
317 
322 
326  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
327 
331  bool supportedType( const QgsField &field ) const;
332 
333  struct NativeType
334  {
335  NativeType( const QString& typeDesc, const QString& typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 )
336  : mTypeDesc( typeDesc )
337  , mTypeName( typeName )
338  , mType( type )
339  , mMinLen( minLen )
340  , mMaxLen( maxLen )
341  , mMinPrec( minPrec )
342  , mMaxPrec( maxPrec )
343  {}
344 
347  QVariant::Type mType;
348  int mMinLen;
349  int mMaxLen;
350  int mMinPrec;
351  int mMaxPrec;
352  };
353 
357  const QList< NativeType > &nativeTypes() const;
358 
363  virtual bool doesStrictFeatureTypeCheck() const { return true;}
364 
366  static const QStringList &availableEncodings();
367 
371  bool hasErrors();
372 
376  void clearErrors();
377 
381  QStringList errors();
382 
383 
388  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
389 
390  static QVariant convertValue( QVariant::Type type, const QString& value );
391 
395  virtual QgsTransaction* transaction() const { return nullptr; }
396 
404  virtual void forceReload()
405  {
406  emit dataChanged();
407  }
408 
412  virtual QSet<QString> layerDependencies() const;
413 
414  signals:
416  void raiseError( const QString& msg );
417 
418  protected:
419  void clearMinMaxCache();
420  void fillMinMaxCache();
421 
424 
427 
430 
433 
434  void pushError( const QString& msg );
435 
438 
439  private:
441  QMap<QString, QVariant::Type> mOldTypeList;
442 
444  QStringList mErrors;
445 
446  static QStringList smEncodings;
447 
451  virtual void setTransaction( QgsTransaction* /*transaction*/ ) {}
452 
453 };
454 
455 
456 #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:187
WkbType
Used for symbology operations.
Definition: qgis.h:57
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.
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
QMap< int, QVariant > mCacheMinValues
virtual bool isSaveAndLoadStyleToDBSupported()
It returns false by default.