QGIS API Documentation  2.2.0-Valmiera
 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 
113  virtual QString storageType() const;
114 
118  virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
119 
124  virtual QGis::WkbType geometryType() const = 0;
125 
130  virtual long featureCount() const = 0;
131 
137  virtual const QgsFields &fields() const = 0;
138 
143  virtual QString dataComment() const;
144 
153  virtual QVariant minimumValue( int index );
154 
163  virtual QVariant maximumValue( int index );
164 
173  virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
174 
182  virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
183 
188  virtual bool addFeatures( QgsFeatureList &flist );
189 
195  virtual bool deleteFeatures( const QgsFeatureIds &id );
196 
203  virtual bool addAttributes( const QList<QgsField> &attributes );
204 
210  virtual bool deleteAttributes( const QgsAttributeIds &attributes );
211 
217  virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
218 
222  virtual QVariant defaultValue( int fieldId );
223 
231  virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );
232 
237  virtual bool createSpatialIndex();
238 
240  virtual bool createAttributeIndex( int field );
241 
247  virtual int capabilities() const;
248 
252  QString capabilitiesString() const;
253 
257  virtual void setEncoding( const QString& e );
258 
262  QString encoding() const;
263 
267  int fieldNameIndex( const QString& fieldName ) const;
268 
272  QMap<QString, int> fieldNameMap() const;
273 
277  virtual QgsAttributeList attributeIndexes();
278 
284 
288  virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
289 
294  bool supportedType( const QgsField &field ) const;
295 
296  struct NativeType
297  {
298  NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
299  mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {};
300 
301  QString mTypeDesc;
302  QString mTypeName;
303  QVariant::Type mType;
304  int mMinLen;
305  int mMaxLen;
306  int mMinPrec;
307  int mMaxPrec;
308  };
309 
314  const QList< NativeType > &nativeTypes() const;
315 
319  virtual bool doesStrictFeatureTypeCheck() const { return true;}
320 
322  static const QStringList &availableEncodings();
323 
328  bool hasErrors();
329 
334  void clearErrors();
335 
340  QStringList errors();
341 
342 
347  virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
348 
349  protected:
350  QVariant convertValue( QVariant::Type type, QString value );
351 
352  void clearMinMaxCache();
353  void fillMinMaxCache();
354 
356  QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
357 
359  QTextCodec* mEncoding;
360 
363 
366 
369 
371  QList< NativeType > mNativeTypes;
372 
373  void pushError( QString msg );
374 
377 
378  private:
380  QMap<QString, QVariant::Type> mOldTypeList;
381 
383  QStringList mErrors;
384 
385  static QStringList smEncodings;
386 
387 };
388 
389 
390 #endif