QGIS API Documentation  2.7.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 
38 #include "qgsfeaturerequest.h"
39 
48 class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
49 {
50  Q_OBJECT
51 
52  public:
53 
54  // If you add to this, please also add to capabilitiesString()
59  {
61  NoCapabilities = 0,
63  AddFeatures = 1,
65  DeleteFeatures = 1 << 1,
67  ChangeAttributeValues = 1 << 2,
69  AddAttributes = 1 << 3,
71  DeleteAttributes = 1 << 4,
73  SaveAsShapefile = 1 << 5,
75  CreateSpatialIndex = 1 << 6,
77  SelectAtId = 1 << 7,
79  ChangeGeometries = 1 << 8,
81  SelectGeometryAtId = 1 << 9,
83  RandomSelectGeometryAtId = 1 << 10,
85  SequentialSelectGeometryAtId = 1 << 11,
86  CreateAttributeIndex = 1 << 12,
88  SelectEncoding = 1 << 13,
90  SimplifyGeometries = 1 << 14,
92  SimplifyGeometriesWithTopologicalValidation = 1 << 15,
93  };
94 
96  const static int EditingCapabilities = AddFeatures | DeleteFeatures |
97  ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;
98 
103  QgsVectorDataProvider( QString uri = QString() );
104 
108  virtual ~QgsVectorDataProvider();
109 
126  virtual QgsAbstractFeatureSource* featureSource() const { Q_ASSERT( 0 && "All providers must support featureSource()" ); return 0; }
127 
131  virtual QString storageType() const;
132 
136  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
137 
142  virtual QGis::WkbType geometryType() const = 0;
143 
148  virtual long featureCount() const = 0;
149 
155  virtual const QgsFields &fields() const = 0;
156 
161  virtual QString dataComment() const;
162 
171  virtual QVariant minimumValue( int index );
172 
181  virtual QVariant maximumValue( int index );
182 
191  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
192 
199  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
200 
205  virtual bool addFeatures( QgsFeatureList &flist );
206 
212  virtual bool deleteFeatures( const QgsFeatureIds &id );
213 
219  virtual bool addAttributes( const QList<QgsField> &attributes );
220 
226  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
227 
233  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
234 
238  virtual QVariant defaultValue( int fieldId );
239 
247  virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );
248 
253  virtual bool createSpatialIndex();
254 
256  virtual bool createAttributeIndex( int field );
257 
263  virtual int capabilities() const;
264 
268  QString capabilitiesString() const;
269 
273  virtual void setEncoding( const QString& e );
274 
278  QString encoding() const;
279 
283  int fieldNameIndex( const QString& fieldName ) const;
284 
288  QMap<QString, int> fieldNameMap() const;
289 
293  virtual QgsAttributeList attributeIndexes();
294 
299 
303  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
304 
308  bool supportedType( const QgsField &field ) const;
309 
310  struct NativeType
311  {
312  NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
313  mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {};
314 
315  QString mTypeDesc;
316  QString mTypeName;
317  QVariant::Type mType;
318  int mMinLen;
319  int mMaxLen;
320  int mMinPrec;
321  int mMaxPrec;
322  };
323 
327  const QList< NativeType > &nativeTypes() const;
328 
333  virtual bool doesStrictFeatureTypeCheck() const { return true;}
334 
336  static const QStringList &availableEncodings();
337 
341  bool hasErrors();
342 
346  void clearErrors();
347 
351  QStringList errors();
352 
353 
358  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
359 
360  static QVariant convertValue( QVariant::Type type, QString value );
361 
362  protected:
363  void clearMinMaxCache();
364  void fillMinMaxCache();
365 
367  QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
368 
370  QTextCodec* mEncoding;
371 
374 
377 
380 
382  QList< NativeType > mNativeTypes;
383 
384  void pushError( QString msg );
385 
388 
389  private:
391  QMap<QString, QVariant::Type> mOldTypeList;
392 
394  QStringList mErrors;
395 
396  static QStringList smEncodings;
397 
398 };
399 
400 
401 #endif
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:315
static unsigned index
bool mFetchGeom
True if geometry should be added to the features in nextFeature calls.
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
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.
bool mFetchFeaturesWithoutGeom
should provider fetch also features that don't have geometry?
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.
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.