QGIS API Documentation  2.9.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 
32 typedef QList<int> QgsAttributeList;
33 typedef QSet<int> QgsAttributeIds;
34 typedef QHash<int, QString> QgsAttrPalIndexNameHash;
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
98  };
99 
101  const static int EditingCapabilities = AddFeatures | DeleteFeatures |
102  ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;
103 
108  QgsVectorDataProvider( QString uri = QString() );
109 
113  virtual ~QgsVectorDataProvider();
114 
131  virtual QgsAbstractFeatureSource* featureSource() const { Q_ASSERT( 0 && "All providers must support featureSource()" ); return 0; }
132 
136  virtual QString storageType() const;
137 
141  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
142 
147  virtual QGis::WkbType geometryType() const = 0;
148 
153  virtual long featureCount() const = 0;
154 
160  virtual const QgsFields &fields() const = 0;
161 
166  virtual QString dataComment() const;
167 
176  virtual QVariant minimumValue( int index );
177 
186  virtual QVariant maximumValue( int index );
187 
196  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
197 
204  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
205 
210  virtual bool addFeatures( QgsFeatureList &flist );
211 
217  virtual bool deleteFeatures( const QgsFeatureIds &id );
218 
224  virtual bool addAttributes( const QList<QgsField> &attributes );
225 
231  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
232 
238  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
239 
243  virtual QVariant defaultValue( int fieldId );
244 
252  virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );
253 
258  virtual bool createSpatialIndex();
259 
261  virtual bool createAttributeIndex( int field );
262 
268  virtual int capabilities() const;
269 
273  QString capabilitiesString() const;
274 
278  virtual void setEncoding( const QString& e );
279 
283  QString encoding() const;
284 
288  int fieldNameIndex( const QString& fieldName ) const;
289 
293  QMap<QString, int> fieldNameMap() const;
294 
298  virtual QgsAttributeList attributeIndexes();
299 
304 
308  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
309 
313  bool supportedType( const QgsField &field ) const;
314 
315  struct NativeType
316  {
317  NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
318  mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {};
319 
320  QString mTypeDesc;
321  QString mTypeName;
322  QVariant::Type mType;
323  int mMinLen;
324  int mMaxLen;
325  int mMinPrec;
326  int mMaxPrec;
327  };
328 
332  const QList< NativeType > &nativeTypes() const;
333 
338  virtual bool doesStrictFeatureTypeCheck() const { return true;}
339 
341  static const QStringList &availableEncodings();
342 
346  bool hasErrors();
347 
351  void clearErrors();
352 
356  QStringList errors();
357 
358 
363  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
364 
365  static QVariant convertValue( QVariant::Type type, QString value );
366 
370  virtual QgsTransaction* transaction() const { return 0; }
371 
372  protected:
373  void clearMinMaxCache();
374  void fillMinMaxCache();
375 
377  QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
378 
380  QTextCodec* mEncoding;
381 
384 
386  QList< NativeType > mNativeTypes;
387 
388  void pushError( QString msg );
389 
392 
393  private:
395  QMap<QString, QVariant::Type> mOldTypeList;
396 
398  QStringList mErrors;
399 
400  static QStringList smEncodings;
401 
405  virtual void setTransaction( QgsTransaction* /*transaction*/ ) {}
406 
407 };
408 
409 
410 #endif
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:315
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.
QSet< QgsFeatureId > QgsFeatureIds
Definition: qgsfeature.h:317
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:322
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:172
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< int > QgsAttributeList
QList< NativeType > mNativeTypes
The names of the providers native types.
Encapsulate a field in an attribute table or data source.
Definition: qgsfield.h:33
base class that can be used for any class that is capable of returning features
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:312
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.