Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 /* $Id$ */
16 #ifndef QGSVECTORDATAPROVIDER_H
17 #define QGSVECTORDATAPROVIDER_H
18 
19 class QTextCodec;
20 
21 #include <QList>
22 #include <QSet>
23 #include <QMap>
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> QgsFeatureIds;
34 typedef QSet<int> QgsAttributeIds;
35 
44 class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
45 {
46  Q_OBJECT
47 
48  public:
49 
50  // If you add to this, please also add to capabilitiesString()
55  {
57  NoCapabilities = 0,
59  AddFeatures = 1,
61  DeleteFeatures = 1 << 1,
63  ChangeAttributeValues = 1 << 2,
65  AddAttributes = 1 << 3,
67  DeleteAttributes = 1 << 4,
69  SaveAsShapefile = 1 << 5,
71  CreateSpatialIndex = 1 << 6,
73  SelectAtId = 1 << 7,
75  ChangeGeometries = 1 << 8,
77  SelectGeometryAtId = 1 << 9,
79  RandomSelectGeometryAtId = 1 << 10,
81  SequentialSelectGeometryAtId = 1 << 11,
82  CreateAttributeIndex = 1 << 12,
84  SetEncoding = 1 << 13,
85  };
86 
88  const static int EditingCapabilities = AddFeatures | DeleteFeatures |
89  ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;
90 
95  QgsVectorDataProvider( QString uri = QString() );
96 
100  virtual ~QgsVectorDataProvider();
101 
105  virtual QString storageType() const;
106 
114  virtual void select( QgsAttributeList fetchAttributes = QgsAttributeList(),
115  QgsRectangle rect = QgsRectangle(),
116  bool fetchGeometry = true,
117  bool useIntersect = false ) = 0;
118 
123  virtual long updateFeatureCount();
124 
136  virtual bool featureAtId( int featureId,
137  QgsFeature& feature,
138  bool fetchGeometry = true,
139  QgsAttributeList fetchAttributes = QgsAttributeList() );
140 
146  virtual bool nextFeature( QgsFeature& feature ) = 0;
147 
152  virtual QGis::WkbType geometryType() const = 0;
153 
154 
159  virtual long featureCount() const = 0;
160 
161 
165  virtual uint fieldCount() const = 0;
166 
172  virtual const QgsFieldMap &fields() const = 0;
173 
178  virtual QString dataComment() const;
179 
181  virtual void rewind() = 0;
182 
191  virtual QVariant minimumValue( int index );
192 
201  virtual QVariant maximumValue( int index );
202 
211  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
212 
218  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
219 
224  virtual bool addFeatures( QgsFeatureList &flist );
225 
231  virtual bool deleteFeatures( const QgsFeatureIds &id );
232 
239  virtual bool addAttributes( const QList<QgsField> &attributes );
240 
247  Q_DECL_DEPRECATED virtual bool addAttributes( const QMap<QString, QString> &attributes );
248 
254  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
255 
261  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
262 
266  virtual QVariant defaultValue( int fieldId );
267 
275  virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );
276 
281  virtual bool createSpatialIndex();
282 
284  virtual bool createAttributeIndex( int field );
285 
291  virtual int capabilities() const;
292 
296  QString capabilitiesString() const;
297 
301  virtual void setEncoding( const QString& e );
302 
306  QString encoding() const;
307 
311  int fieldNameIndex( const QString& fieldName ) const;
312 
314  QMap<QString, int> fieldNameMap() const;
315 
319  virtual QgsAttributeList attributeIndexes();
320 
325  void enableGeometrylessFeatures( bool fetch );
326 
331  bool supportedType( const QgsField &field ) const;
332 
333  struct NativeType
334  {
335  NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
336  mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {};
337 
338  QString mTypeDesc;
339  QString mTypeName;
340  QVariant::Type mType;
341  int mMinLen, mMaxLen;
342  int mMinPrec, mMaxPrec;
343  };
344 
345 
350  const QList< NativeType > &nativeTypes() const;
351 
352 
357  Q_DECL_DEPRECATED const QMap<QString, QVariant::Type> &supportedNativeTypes() const;
358 
362  virtual bool doesStrictFeatureTypeCheck() const { return true;}
363 
364 
365  static const QStringList &availableEncodings();
366 
367  /* provider has errors to report
368  * @note added in 1.7
369  */
370  bool hasErrors();
371 
372  /* clear recorded errors
373  * @note added in 1.7
374  */
375  void clearErrors();
376 
377  /* get recorded errors
378  * @note added in 1.7
379  */
380  QStringList errors();
381 
382 
383  protected:
384  QVariant convertValue( QVariant::Type type, QString value );
385 
386  void clearMinMaxCache();
387  void fillMinMaxCache();
388 
390  QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
391 
393  QTextCodec* mEncoding;
394 
397 
400 
403 
405  QList< NativeType > mNativeTypes;
406 
407  void pushError( QString msg );
408 
409  private:
411  QMap<QString, QVariant::Type> mOldTypeList;
412 
413  // list of errors
414  QStringList mErrors;
415 
416 
417  static QStringList smEncodings;
418 
419 };
420 
421 #endif