QGIS API Documentation  2.13.0-Master
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, const QgsGeometryMap &geometry_map );
256 
260  virtual QVariant defaultValue( int fieldId );
261 
269  virtual bool changeGeometryValues( const QgsGeometryMap &geometry_map );
270 
275  virtual bool createSpatialIndex();
276 
278  virtual bool createAttributeIndex( int field );
279 
285  virtual int capabilities() const;
286 
290  QString capabilitiesString() const;
291 
295  virtual void setEncoding( const QString& e );
296 
300  QString encoding() const;
301 
305  int fieldNameIndex( const QString& fieldName ) const;
306 
310  QMap<QString, int> fieldNameMap() const;
311 
315  virtual QgsAttributeList attributeIndexes();
316 
321 
325  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
326 
330  bool supportedType( const QgsField &field ) const;
331 
332  struct NativeType
333  {
334  NativeType( const QString& typeDesc, const QString& typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
335  mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {}
336 
339  QVariant::Type mType;
340  int mMinLen;
341  int mMaxLen;
342  int mMinPrec;
343  int mMaxPrec;
344  };
345 
349  const QList< NativeType > &nativeTypes() const;
350 
355  virtual bool doesStrictFeatureTypeCheck() const { return true;}
356 
358  static const QStringList &availableEncodings();
359 
363  bool hasErrors();
364 
368  void clearErrors();
369 
373  QStringList errors();
374 
375 
380  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
381 
382  static QVariant convertValue( QVariant::Type type, const QString& value );
383 
387  virtual QgsTransaction* transaction() const { return nullptr; }
388 
396  virtual void forceReload()
397  {
398  emit dataChanged();
399  }
400 
404  virtual QSet<QString> layerDependencies() const;
405 
406  protected:
407  void clearMinMaxCache();
408  void fillMinMaxCache();
409 
412 
415 
418 
421 
422  void pushError( const QString& msg );
423 
426 
427  private:
429  QMap<QString, QVariant::Type> mOldTypeList;
430 
432  QStringList mErrors;
433 
434  static QStringList smEncodings;
435 
439  virtual void setTransaction( QgsTransaction* /*transaction*/ ) {}
440 
441 };
442 
443 
444 #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:189
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.