QGIS API Documentation  2.6.0-Brighton
 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 : 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 
332  virtual bool doesStrictFeatureTypeCheck() const { return true;}
333 
335  static const QStringList &availableEncodings();
336 
340  bool hasErrors();
341 
345  void clearErrors();
346 
350  QStringList errors();
351 
352 
357  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
358 
359  static QVariant convertValue( QVariant::Type type, QString value );
360 
361  protected:
362  void clearMinMaxCache();
363  void fillMinMaxCache();
364 
366  QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
367 
369  QTextCodec* mEncoding;
370 
373 
376 
379 
381  QList< NativeType > mNativeTypes;
382 
383  void pushError( QString msg );
384 
387 
388  private:
390  QMap<QString, QVariant::Type> mOldTypeList;
391 
393  QStringList mErrors;
394 
395  static QStringList smEncodings;
396 
397 };
398 
399 
400 #endif