QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 : marco.hugentobler@autoform.ch
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,
89  CreateAttributeIndex = 1 << 12,
91  SelectEncoding = 1 << 13,
93  SimplifyGeometries = 1 << 14,
95  SimplifyGeometriesWithTopologicalValidation = 1 << 15,
97  TransactionSupport = 1 << 16,
99  CircularGeometries = 1 << 17
100  };
101 
103  const static int EditingCapabilities = AddFeatures | DeleteFeatures |
104  ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;
105 
111 
115  virtual ~QgsVectorDataProvider();
116 
133  virtual QgsAbstractFeatureSource* featureSource() const { Q_ASSERT( 0 && "All providers must support featureSource()" ); return 0; }
134 
138  virtual QString storageType() const;
139 
143  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
144 
149  virtual QGis::WkbType geometryType() const = 0;
150 
155  virtual long featureCount() const = 0;
156 
162  virtual const QgsFields &fields() const = 0;
163 
168  virtual QString dataComment() const;
169 
178  virtual QVariant minimumValue( int index );
179 
188  virtual QVariant maximumValue( int index );
189 
198  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
199 
206  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
207 
212  virtual bool addFeatures( QgsFeatureList &flist );
213 
219  virtual bool deleteFeatures( const QgsFeatureIds &id );
220 
226  virtual bool addAttributes( const QList<QgsField> &attributes );
227 
233  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
234 
240  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
241 
245  virtual QVariant defaultValue( int fieldId );
246 
254  virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );
255 
260  virtual bool createSpatialIndex();
261 
263  virtual bool createAttributeIndex( int field );
264 
270  virtual int capabilities() const;
271 
275  QString capabilitiesString() const;
276 
280  virtual void setEncoding( const QString& e );
281 
285  QString encoding() const;
286 
290  int fieldNameIndex( const QString& fieldName ) const;
291 
295  QMap<QString, int> fieldNameMap() const;
296 
300  virtual QgsAttributeList attributeIndexes();
301 
306 
310  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
311 
315  bool supportedType( const QgsField &field ) const;
316 
317  struct NativeType
318  {
319  NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
320  mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {};
321 
322  QString mTypeDesc;
324  QVariant::Type mType;
325  int mMinLen;
326  int mMaxLen;
327  int mMinPrec;
328  int mMaxPrec;
329  };
330 
334  const QList< NativeType > &nativeTypes() const;
335 
340  virtual bool doesStrictFeatureTypeCheck() const { return true;}
341 
343  static const QStringList &availableEncodings();
344 
348  bool hasErrors();
349 
353  void clearErrors();
354 
358  QStringList errors();
359 
360 
365  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
366 
367  static QVariant convertValue( QVariant::Type type, QString value );
368 
372  virtual QgsTransaction* transaction() const { return 0; }
373 
374  protected:
375  void clearMinMaxCache();
376  void fillMinMaxCache();
377 
380 
383 
386 
389 
390  void pushError( QString msg );
391 
394 
395  private:
397  QMap<QString, QVariant::Type> mOldTypeList;
398 
400  QStringList mErrors;
401 
402  static QStringList smEncodings;
403 
407  virtual void setTransaction( QgsTransaction* /*transaction*/ ) {}
408 
409 };
410 
411 
412 #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.
NativeType(QString typeDesc, QString typeName, QVariant::Type type, int minLen=0, int maxLen=0, int minPrec=0, int maxPrec=0)
Container of fields for a vector layer.
Definition: qgsfield.h:177
Abstract base class for spatial data provider implementations.
QList< int > QgsAttributeList
WkbType
Used for symbology operations.
Definition: qgis.h:53
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's data.
QSet< int > QgsAttributeIds
QTextCodec * mEncoding
Encoding.
virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const
Return list of indexes to names for QgsPalLabeling fix.
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:40
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 to include a set of layers in a database-side transaction, provided the layer data ...
Capability
enumeration with capabilities that providers might implement
QgsAttrPalIndexNameHash mAttrPalIndexName
Old-style mapping of index to name for QgsPalLabeling fix.
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.