QGIS API Documentation  2.4.0-Chugiak
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 : [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 
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 
200  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
201 
206  virtual bool addFeatures( QgsFeatureList &flist );
207 
213  virtual bool deleteFeatures( const QgsFeatureIds &id );
214 
221  virtual bool addAttributes( const QList<QgsField> &attributes );
222 
228  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
229 
235  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
236 
240  virtual QVariant defaultValue( int fieldId );
241 
249  virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );
250 
255  virtual bool createSpatialIndex();
256 
258  virtual bool createAttributeIndex( int field );
259 
265  virtual int capabilities() const;
266 
270  QString capabilitiesString() const;
271 
275  virtual void setEncoding( const QString& e );
276 
280  QString encoding() const;
281 
285  int fieldNameIndex( const QString& fieldName ) const;
286 
290  QMap<QString, int> fieldNameMap() const;
291 
295  virtual QgsAttributeList attributeIndexes();
296 
302 
306  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
307 
312  bool supportedType( const QgsField &field ) const;
313 
314  struct NativeType
315  {
316  NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
317  mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {};
318 
319  QString mTypeDesc;
320  QString mTypeName;
321  QVariant::Type mType;
322  int mMinLen;
323  int mMaxLen;
324  int mMinPrec;
325  int mMaxPrec;
326  };
327 
332  const QList< NativeType > &nativeTypes() const;
333 
337  virtual bool doesStrictFeatureTypeCheck() const { return true;}
338 
340  static const QStringList &availableEncodings();
341 
346  bool hasErrors();
347 
352  void clearErrors();
353 
358  QStringList errors();
359 
360 
365  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
366 
367  static QVariant convertValue( QVariant::Type type, QString value );
368 
369  protected:
370  void clearMinMaxCache();
371  void fillMinMaxCache();
372 
374  QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
375 
377  QTextCodec* mEncoding;
378 
381 
384 
387 
389  QList< NativeType > mNativeTypes;
390 
391  void pushError( QString msg );
392 
395 
396  private:
398  QMap<QString, QVariant::Type> mOldTypeList;
399 
401  QStringList mErrors;
402 
403  static QStringList smEncodings;
404 
405 };
406 
407 
408 #endif
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QgsFeatureId, QgsGeometry > QgsGeometryMap
Definition: qgsfeature.h:323
static unsigned index
bool mFetchGeom
True if geometry should be added to the features in nextFeature calls.
QMap< QString, QVariant::Type > mOldTypeList
old notation
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:325
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:330
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:161
WkbType
Used for symbology operations.
Definition: qgis.h:53
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'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.
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< 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:31
base class that can be used for any class that is capable of returning features
QStringList mErrors
list of errors
QMap< QgsFeatureId, QgsAttributeMap > QgsChangedAttributesMap
Definition: qgsfeature.h:320
static QStringList smEncodings
virtual bool doesStrictFeatureTypeCheck() const
Returns true if the provider is strict about the type of inserted features (e.g.
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.