QGIS API Documentation  2.0.1-Dufour
 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,
89  };
90 
92  const static int EditingCapabilities = AddFeatures | DeleteFeatures |
93  ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;
94 
99  QgsVectorDataProvider( QString uri = QString() );
100 
104  virtual ~QgsVectorDataProvider();
105 
109  virtual QString storageType() const;
110 
114  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
115 
120  virtual QGis::WkbType geometryType() const = 0;
121 
126  virtual long featureCount() const = 0;
127 
133  virtual const QgsFields &fields() const = 0;
134 
139  virtual QString dataComment() const;
140 
149  virtual QVariant minimumValue( int index );
150 
159  virtual QVariant maximumValue( int index );
160 
169  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
170 
176  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
177 
182  virtual bool addFeatures( QgsFeatureList &flist );
183 
189  virtual bool deleteFeatures( const QgsFeatureIds &id );
190 
197  virtual bool addAttributes( const QList<QgsField> &attributes );
198 
204  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
205 
211  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
212 
216  virtual QVariant defaultValue( int fieldId );
217 
225  virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );
226 
231  virtual bool createSpatialIndex();
232 
234  virtual bool createAttributeIndex( int field );
235 
241  virtual int capabilities() const;
242 
246  QString capabilitiesString() const;
247 
251  virtual void setEncoding( const QString& e );
252 
256  QString encoding() const;
257 
261  int fieldNameIndex( const QString& fieldName ) const;
262 
264  QMap<QString, int> fieldNameMap() const;
265 
269  virtual QgsAttributeList attributeIndexes();
270 
276 
280  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
281 
286  bool supportedType( const QgsField &field ) const;
287 
288  struct NativeType
289  {
290  NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
291  mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {};
292 
293  QString mTypeDesc;
294  QString mTypeName;
295  QVariant::Type mType;
296  int mMinLen;
297  int mMaxLen;
298  int mMinPrec;
299  int mMaxPrec;
300  };
301 
306  const QList< NativeType > &nativeTypes() const;
307 
311  virtual bool doesStrictFeatureTypeCheck() const { return true;}
312 
314  static const QStringList &availableEncodings();
315 
316  /* provider has errors to report
317  * @note added in 1.7
318  */
319  bool hasErrors();
320 
321  /* clear recorded errors
322  * @note added in 1.7
323  */
324  void clearErrors();
325 
326  /* get recorded errors
327  * @note added in 1.7
328  */
329  QStringList errors();
330 
331 
336  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
337 
338  protected:
339  QVariant convertValue( QVariant::Type type, QString value );
340 
341  void clearMinMaxCache();
342  void fillMinMaxCache();
343 
345  QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
346 
348  QTextCodec* mEncoding;
349 
352 
355 
358 
360  QList< NativeType > mNativeTypes;
361 
362  void pushError( QString msg );
363 
366 
367  private:
369  QMap<QString, QVariant::Type> mOldTypeList;
370 
371  // list of errors
372  QStringList mErrors;
373 
374  static QStringList smEncodings;
375 
376 };
377 
378 
379 #endif