~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/core/qgsvectordataprovider.h

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 *   (at your option) any later version.                                   *
13
13
 *                                                                         *
14
14
 ***************************************************************************/
15
 
/* $Id: qgsvectordataprovider.h 5595 2006-07-14 03:11:25Z morb_au $ */
 
15
/* $Id$ */
16
16
#ifndef QGSVECTORDATAPROVIDER_H
17
17
#define QGSVECTORDATAPROVIDER_H
18
18
 
19
 
class QgsGeometry;
 
19
class QTextCodec;
20
20
 
21
 
//Qt includes
22
 
#include <set>
23
 
#include <map>
24
 
#include <vector>
25
 
// XXX no signals or slots so not needed #include <qobject.h>
26
 
#include <QTextCodec>
 
21
#include <QList>
 
22
#include <QSet>
 
23
#include <QMap>
27
24
 
28
25
//QGIS Includes
29
 
#include <qgsdataprovider.h>
30
 
#include <qgsspatialrefsys.h>
31
 
#include <qgssearchstring.h>
 
26
#include "qgis.h"
 
27
#include "qgsdataprovider.h"
 
28
#include "qgsvectorlayer.h"
 
29
#include "qgsfield.h"
32
30
 
33
 
/** Base class for vector data providers
 
31
/** \ingroup core
 
32
 * This is the base class for vector data providers.
 
33
 *
 
34
 * Data providers abstract the retrieval and writing (where supported)
 
35
 * of feature and attribute information from a spatial datasource.
 
36
 *
 
37
 *
34
38
 */
35
 
 
36
 
class QgsVectorDataProvider : public QgsDataProvider
 
39
class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
37
40
{
38
 
 
39
 
    // XXX no  signals or slots, so not needed Q_OBJECT
40
 
 
41
 
    public:
42
 
 
43
 
      // If you add to this, please also add to capabilitiesString()
44
 
      enum Capability
45
 
      {
46
 
        NoCapabilities =                     0,
47
 
        AddFeatures =                        1,
48
 
        DeleteFeatures =               1 <<  1,
49
 
        ChangeAttributeValues =        1 <<  2,
50
 
        AddAttributes =                1 <<  3,    // TODO: what is this exactly?
51
 
        DeleteAttributes =             1 <<  4,
52
 
        SaveAsShapefile =              1 <<  5,
53
 
        CreateSpatialIndex =           1 <<  6,
54
 
        SelectAtId =                   1 <<  7,
55
 
        ChangeGeometries =             1 <<  8,
56
 
        SelectGeometryAtId =           1 <<  9,
57
 
        RandomSelectGeometryAtId =     1 << 10,
58
 
        SequentialSelectGeometryAtId = 1 << 11
59
 
      };
60
 
 
61
 
      QgsVectorDataProvider();
62
 
 
63
 
      QgsVectorDataProvider( QString const & uri );
64
 
 
65
 
      virtual ~QgsVectorDataProvider() {};
66
 
 
67
 
      /**
68
 
       *   Returns the permanent storage type for this layer as a friendly name.
69
 
       */
70
 
      virtual QString storageType() { return "Generic vector file"; };
71
 
 
72
 
      /**
73
 
       * Select features based on a bounding rectangle. Features can be retrieved 
74
 
       * with calls to getFirstFeature and getNextFeature. Request for features 
75
 
       * for use in drawing the map canvas should set useIntersect to false.
76
 
       * @param mbr QgsRect containing the extent to use in selecting features
77
 
       * @param useIntersect If true, use the intersects function to select features
78
 
       * rather than the PostGIS && operator that selects based on bounding box
79
 
       * overlap.
80
 
       *
81
 
       */
82
 
      virtual void select(QgsRect *mbr, bool useIntersect=false)=0;
83
 
      /**
84
 
       * Update the feature count based on current spatial filter. If not
85
 
       * overridden in the data provider this function returns -1
86
 
       */
87
 
      virtual long updateFeatureCount()
88
 
      {
89
 
        return -1;
90
 
      }
91
 
      
92
 
      /** 
93
 
       * Gets the feature at the given feature ID.
94
 
       * @return  QgsFeature
95
 
       */
96
 
      virtual QgsFeature * getFeatureAtId(int featureId)
97
 
      {
98
 
        return 0;
99
 
      };
100
 
      
101
 
      /** 
102
 
       * Get the first feature resulting from a select operation
103
 
       * @return QgsFeature
104
 
       */
105
 
      virtual QgsFeature * getFirstFeature(bool fetchAttributes = false) = 0;
106
 
 
107
 
      /** 
108
 
       * Get the next feature resutling from a select operation
109
 
       * @return QgsFeature
110
 
       */
111
 
      virtual QgsFeature * getNextFeature(bool fetchAttributes = false) = 0;
112
 
 
113
 
      /**Get the next feature resulting from a select operation.
114
 
       *@param attlist a list containing the indexes of the attribute fields to copy
115
 
     * @param featureQueueSize   a hint to the provider as to how many features are likely to be retrieved in a batch
116
 
       */
117
 
//    virtual QgsFeature* getNextFeature(std::list<int> const & attlist) = 0;
118
 
    
119
 
      virtual QgsFeature* getNextFeature(std::list<int> const & attlist, int featureQueueSize = 1) { return 0; }
120
 
 
121
 
      /**
122
 
       * Get the next feature using new method
123
 
       * TODO - make this pure virtual once it works and change existing providers
124
 
       *        to use this method of fetching features
125
 
       */
126
 
 
127
 
      virtual bool getNextFeature(QgsFeature &feature, bool fetchAttributes = false) = 0;
128
 
 
129
 
      /** Get feature type.
130
 
       * Gets the feature type as defined in WKBTYPE (qgis.h).
131
 
       * @return int representing the feature type
132
 
       */
133
 
      virtual int geometryType() const = 0;
134
 
 
135
 
 
136
 
      /**
137
 
       * Number of features in the layer
138
 
       * @return long containing number of features
139
 
       */
140
 
      virtual long featureCount() const = 0;
141
 
 
142
 
      /**
143
 
       * Get the attributes associated with a feature
144
 
       * TODO: Get rid of "row" and set up provider-internal caching instead
145
 
       */
146
 
      virtual void getFeatureAttributes(int key, int& row, QgsFeature *f) {};
147
 
 
148
 
      /**
149
 
       * Fetch geometry for a particular feature with id "key",
150
 
       * modifies "f" in-place.
151
 
       *
152
 
       * This function is enabled if capabilities() returns "SelectGeometryAtId".
153
 
       */
154
 
      virtual void getFeatureGeometry(int key, QgsFeature *f) {};
155
 
 
156
 
      /**
157
 
       * Number of attribute fields for a feature in the layer
158
 
       */
159
 
      virtual int fieldCount() const = 0;
160
 
 
161
 
      /**
162
 
       * Return a list of field names for this layer
163
 
       * @return vector of field names
164
 
       */
165
 
      virtual std::vector<QgsField> const & fields() const = 0;
166
 
 
167
 
      /** 
168
 
       * Reset the layer to clear any spatial filtering or other contstraints that
169
 
       * would prevent the entire record set from being traversed by call to 
170
 
       * getNextFeature(). Some data stores may not require any special action to
171
 
       * reset the layer. In this case, the provider should simply implement an empty
172
 
       * function body.
173
 
       */
174
 
      virtual void reset() = 0;
175
 
 
176
 
      /**Returns the minimum value of an attributs
177
 
        @param position the number of the attribute*/
178
 
      virtual QString minValue(int position) = 0;
179
 
 
180
 
      /**Returns the maximum value of an attributs
181
 
        @param position the number of the attribute*/
182
 
      virtual QString maxValue(int position) = 0;
183
 
 
184
 
      /**Adds a list of features
185
 
        @return true in case of success and false in case of failure*/
186
 
      virtual bool addFeatures(std::list<QgsFeature*> const flist);
187
 
 
188
 
      /**Deletes a feature
189
 
        @param id list containing feature ids to delete
190
 
        @return true in case of success and false in case of failure*/
191
 
      virtual bool deleteFeatures(std::list<int> const & id);
192
 
 
193
 
      /**Adds new attributes
194
 
        @param name map with attribute name as key and type as value
195
 
        @return true in case of success and false in case of failure*/
196
 
      virtual bool addAttributes(std::map<QString,QString> const & name);
197
 
 
198
 
      /**Deletes existing attributes
199
 
        @param names of the attributes to delete
200
 
        @return true in case of success and false in case of failure*/
201
 
      virtual bool deleteAttributes(std::set<QString> const & name);
202
 
 
203
 
      /**Changes attribute values of existing features
204
 
        @param attr_map a map containing the new attributes. The integer is the feature id,
205
 
        the first QString is the attribute name and the second one is the new attribute value
206
 
        @return true in case of success and false in case of failure*/
207
 
      virtual bool changeAttributeValues(std::map<int,std::map<QString,QString> > const & attr_map);
208
 
 
209
 
      /**Returns the default value for attribute @c attr for feature @c f. */
210
 
      virtual QString getDefaultValue(const QString & attr, QgsFeature* f);
211
 
 
212
 
      /**
213
 
       Changes geometries of existing features
214
 
       @param geometry_map   A std::map containing the feature IDs to change the geometries of. 
215
 
                             the second map parameter being the new geometries themselves
216
 
       @return               true in case of success and false in case of failure
217
 
     */
218
 
    virtual bool changeGeometryValues(std::map<int, QgsGeometry> & geometry_map);
219
 
 
220
 
    /**
221
 
       * Identify features within the search radius specified by rect
222
 
       * @param rect Bounding rectangle of search radius
223
 
       * @return std::vector containing QgsFeature objects that intersect rect
224
 
       */
225
 
      virtual std::vector<QgsFeature>& identify(QgsRect *rect) = 0;
226
 
 
227
 
      /** saves current data as Shape file, if it can */
228
 
      virtual bool saveAsShapefile()
229
 
      {
230
 
        // NOP by default
231
 
        return false;
232
 
      }
233
 
 
234
 
      /**Creates a spatial index on the datasource (if supported by the provider type). Returns true in case of success*/
235
 
      virtual bool createSpatialIndex();
236
 
 
237
 
      /** Sets filter based on attribute values. Returns false when input string contains errors */
238
 
      virtual bool setAttributeFilter(const QgsSearchString& attributeFilter);
239
 
 
240
 
      /** Returns current attribute filter */
241
 
      virtual QgsSearchString getAttributeFilter() { return mAttributeFilter; }
242
 
      
243
 
      /** Returns a bitmask containing the supported capabilities
244
 
          Note, some capabilities may change depending on whether
245
 
          a spatial filter is active on this provider, so it may
246
 
          be prudent to check this value per intended operation.
247
 
       */
248
 
      virtual int capabilities() const {return QgsVectorDataProvider::NoCapabilities;}
249
 
 
250
 
      /**
251
 
       *  Returns the above in friendly format.
252
 
       */
253
 
      QString capabilitiesString() const;
254
 
 
255
 
      const std::list<QString>& nonNumericalTypes(){return mNonNumericalTypes;}
256
 
      const std::list<QString>& numericalTypes(){return mNumericalTypes;}
257
 
 
258
 
      virtual void setEncoding(const QString& e);
259
 
      QString encoding() const;
260
 
 
261
 
      /*! Indicates if the provider does its own coordinate transforms
262
 
       * @return true if the provider transforms its coordinates, otherwise false
263
 
       */
264
 
      virtual bool supportsNativeTransform(){return false;};
265
 
      /*! Used to determine if the provider supports transformation using the
266
 
       * SRID of the target SRS.
267
 
       *
268
 
       * @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
269
 
       *       XXXXX in favour of SpatialRefSys accessors
270
 
       *       XXXXX and mutators!
271
 
       *
272
 
       * @return true if SRID is used, otherwise false
273
 
       */
274
 
      virtual bool usesSrid(){return false;};
275
 
      /*! Used to determine if the provider supports transformation using the
276
 
       * WKT of the target SRS.
277
 
       *
278
 
       * @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
279
 
       *       XXXXX in favour of SpatialRefSys accessors
280
 
       *       XXXXX and mutators!
281
 
       *
282
 
       * @return true if WKT is used, otherwise false
283
 
       */
284
 
      virtual bool usesWKT(){return false;};
285
 
      /*! Set the SRID of the target SRS.
286
 
       * This is only implemented if the provider supports native
287
 
       * transformation of its coordinates
288
 
       *
289
 
       * @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
290
 
       *       XXXXX in favour of SpatialRefSys accessors
291
 
       *       XXXXX and mutators!
292
 
       *
293
 
       * @param srid Spatial reference id of the target (map canvas)
294
 
       */
295
 
      virtual void setSrid(int srid){};
296
 
      /*! Get the SRID of the target SRS
297
 
       * If the provider isn't capable of reporting the SRID of
298
 
       * the projection, ti will return 0
299
 
       *
300
 
       * @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
301
 
       *       XXXXX in favour of SpatialRefSys accessors
302
 
       *       XXXXX and mutators!
303
 
       *
304
 
       */
305
 
      virtual int getSrid(){return 0;};
306
 
      /*! Set the WKT of the target SRS.
307
 
       * This is only implemented if the provider supports native
308
 
       * transformation of its coordinates
309
 
       *
310
 
       * @note XXXXX WARNING THIS METHOD WILL BE DEPRECATED
311
 
       *       XXXXX in favour of SpatialRefSys accessors
312
 
       *       XXXXX and mutators!
313
 
       *
314
 
       * @param wkt Well known text of the target (map canvas) SRS
315
 
       */
316
 
      virtual void setWKT(QString wkt){};
317
 
 
318
 
      /**Returns the index of a field name or -1 if the field does not exist*/
319
 
      int indexFromFieldName(const QString& fieldName) const;
320
 
 
321
 
    protected:
322
 
      /**Encoding*/
323
 
      QTextCodec* mEncoding;
324
 
      /**List of type names for non-numerical types*/
325
 
      std::list<QString> mNonNumericalTypes;
326
 
      /**List of type names for numerical types*/
327
 
      std::list<QString> mNumericalTypes;
328
 
      /** attribute filter (in 'simple search string' format) */
329
 
      QgsSearchString mAttributeFilter;
330
 
 
331
 
      /** The spatial reference id of the map canvas. This is the 
332
 
       * SRID the provider should transform its coordinates to if 
333
 
       * supportsNativeTransform is true. Otherwise this member is unused.
334
 
       *
335
 
       * @note XXXXX WARNING THIS MEMBER WILL BE DEPRECATED
336
 
       *       XXXXX in favour of SpatialRefSys accessors
337
 
       *       XXXXX and mutators!
338
 
       *
339
 
       */
340
 
      int mTargetSrid;
341
 
      /** The WKT of the SRS of the map canvas. This is the 
342
 
       * SRS the provider should transform its coordinates to if 
343
 
       * supportsNativeTransform is true. Otherwise this member is unused.
344
 
       * The provider may choose to support transformation using SRID or WKT.
345
 
       *
346
 
       * @note XXXXX WARNING THIS MEMBER WILL BE DEPRECATED
347
 
       *       XXXXX in favour of SpatialRefSys accessors
348
 
       *       XXXXX and mutators!
349
 
       *
350
 
       */
 
41
  public:
 
42
 
 
43
    // If you add to this, please also add to capabilitiesString()
 
44
    /**
 
45
     * enumeration with capabilities that providers might implement
 
46
     */
 
47
    enum Capability
 
48
    {
 
49
      /** provider has no capabilities */
 
50
      NoCapabilities =                     0,
 
51
      /** allows adding features */
 
52
      AddFeatures =                        1,
 
53
      /** allows deletion of features */
 
54
      DeleteFeatures =               1 <<  1,
 
55
      /** allows modification of attribute values */
 
56
      ChangeAttributeValues =        1 <<  2,
 
57
      /** allows addition of new attributes (fields) */
 
58
      AddAttributes =                1 <<  3,
 
59
      /** allows deletion of attributes (fields) */
 
60
      DeleteAttributes =             1 <<  4,
 
61
      /** DEPRECATED - do not use */
 
62
      SaveAsShapefile =              1 <<  5,
 
63
      /** allows creation of spatial index */
 
64
      CreateSpatialIndex =           1 <<  6,
 
65
      /** fast access to features using their ID */
 
66
      SelectAtId =                   1 <<  7,
 
67
      /** allows modifications of geometries */
 
68
      ChangeGeometries =             1 <<  8,
 
69
      /** DEPRECATED - do not use */
 
70
      SelectGeometryAtId =           1 <<  9,
 
71
      /** DEPRECATED - do not use */
 
72
      RandomSelectGeometryAtId =     1 << 10,
 
73
      /** DEPRECATED - do not use */
 
74
      SequentialSelectGeometryAtId = 1 << 11,
 
75
    };
 
76
 
 
77
    /** bitmask of all provider's editing capabilities */
 
78
    const static int EditingCapabilities = AddFeatures | DeleteFeatures |
 
79
                                           ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;
 
80
 
 
81
    /**
 
82
     * Constructor of the vector provider
 
83
     * @param uri  uniform resource locator (URI) for a dataset
 
84
     */
 
85
    QgsVectorDataProvider( QString uri = QString() );
 
86
 
 
87
    /**
 
88
     * Destructor
 
89
     */
 
90
    virtual ~QgsVectorDataProvider();
 
91
 
 
92
    /**
 
93
     * Returns the permanent storage type for this layer as a friendly name.
 
94
     */
 
95
    virtual QString storageType() const;
 
96
 
 
97
    /** Select features based on a bounding rectangle. Features can be retrieved with calls to nextFeature.
 
98
     * @param fetchAttributes list of attributes which should be fetched
 
99
     * @param rect spatial filter
 
100
     * @param fetchGeometry true if the feature geometry should be fetched
 
101
     * @param useIntersect true if an accurate intersection test should be used,
 
102
     *                     false if a test based on bounding box is sufficient
 
103
     */
 
104
    virtual void select( QgsAttributeList fetchAttributes = QgsAttributeList(),
 
105
                         QgsRectangle rect = QgsRectangle(),
 
106
                         bool fetchGeometry = true,
 
107
                         bool useIntersect = false ) = 0;
 
108
 
 
109
    /**
 
110
     * Update the feature count based on current spatial filter. If not
 
111
     * overridden in the data provider this function returns -1
 
112
     */
 
113
    virtual long updateFeatureCount();
 
114
 
 
115
    /**
 
116
     * Gets the feature at the given feature ID.
 
117
     * @param featureId of the feature to be returned
 
118
     * @param feature which will receive the data
 
119
     * @param fetchGeometry flag which if true, will cause the geometry to be fetched from the provider
 
120
     * @param fetchAttributes a list containing the indexes of the attribute fields to copy
 
121
     * @return True when feature was found, otherwise false
 
122
     *
 
123
     * Default implementation traverses all features until it finds the one with correct ID.
 
124
     * In case the provider supports reading the feature directly, override this function.
 
125
     */
 
126
    virtual bool featureAtId( int featureId,
 
127
                              QgsFeature& feature,
 
128
                              bool fetchGeometry = true,
 
129
                              QgsAttributeList fetchAttributes = QgsAttributeList() );
 
130
 
 
131
    /**
 
132
     * Get the next feature resulting from a select operation.
 
133
     * @param feature feature which will receive data from the provider
 
134
     * @return true when there was a feature to fetch, false when end was hit
 
135
     */
 
136
    virtual bool nextFeature( QgsFeature& feature ) = 0;
 
137
 
 
138
    /**
 
139
     * Get feature type.
 
140
     * @return int representing the feature type
 
141
     */
 
142
    virtual QGis::WkbType geometryType() const = 0;
 
143
 
 
144
 
 
145
    /**
 
146
     * Number of features in the layer
 
147
     * @return long containing number of features
 
148
     */
 
149
    virtual long featureCount() const = 0;
 
150
 
 
151
 
 
152
    /**
 
153
     * Number of attribute fields for a feature in the layer
 
154
     */
 
155
    virtual uint fieldCount() const = 0;
 
156
 
 
157
    /**
 
158
     * Return a map of indexes with field names for this layer
 
159
     * @return map of fields
 
160
     * @see QgsFieldMap
 
161
     */
 
162
    virtual const QgsFieldMap &fields() const = 0;
 
163
 
 
164
    /**
 
165
     * Return a short comment for the data that this provider is
 
166
     * providing access to (e.g. the comment for postgres table).
 
167
     */
 
168
    virtual QString dataComment() const;
 
169
 
 
170
    /** Restart reading features from previous select operation */
 
171
    virtual void rewind() = 0;
 
172
 
 
173
    /**
 
174
     * Returns the minimum value of an attribute
 
175
     * @param index the index of the attribute
 
176
     *
 
177
     * Default implementation walks all numeric attributes and caches minimal
 
178
     * and maximal values. If provider has facilities to retrieve minimal
 
179
     * value directly, override this function.
 
180
     */
 
181
    virtual QVariant minimumValue( int index );
 
182
 
 
183
    /**
 
184
     * Returns the maximum value of an attribute
 
185
     * @param index the index of the attribute
 
186
     *
 
187
     * Default implementation walks all numeric attributes and caches minimal
 
188
     * and maximal values. If provider has facilities to retrieve maximal
 
189
     * value directly, override this function.
 
190
     */
 
191
    virtual QVariant maximumValue( int index );
 
192
 
 
193
    /**
 
194
     * Return unique values of an attribute
 
195
     * @param index the index of the attribute
 
196
     * @param values reference to the list to fill
 
197
     * @param limit maxmum number of the values to return (added in 1.4)
 
198
     *
 
199
     * Default implementation simply iterates the features
 
200
     */
 
201
    virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
 
202
 
 
203
    /**Returns the possible enum values of an attribute. Returns an empty stringlist if a provider does not support enum types
 
204
      or if the given attribute is not an enum type.
 
205
     * @param index the index of the attribute
 
206
     * @param enumList reference to the list to fill
 
207
      @note: added in version 1.2*/
 
208
    virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
 
209
 
 
210
    /**
 
211
     * Adds a list of features
 
212
     * @return true in case of success and false in case of failure
 
213
     */
 
214
    virtual bool addFeatures( QgsFeatureList &flist );
 
215
 
 
216
    /**
 
217
     * Deletes one or more features
 
218
     * @param id list containing feature ids to delete
 
219
     * @return true in case of success and false in case of failure
 
220
     */
 
221
    virtual bool deleteFeatures( const QgsFeatureIds &id );
 
222
 
 
223
    /**
 
224
     * Adds new attributes
 
225
     * @param attributes list of new attributes
 
226
     * @return true in case of success and false in case of failure
 
227
     * @note added in 1.2
 
228
     */
 
229
    virtual bool addAttributes( const QList<QgsField> &attributes );
 
230
 
 
231
    /**
 
232
     * Add new attributes
 
233
     * @param attributes map of attributes name as key and type as value
 
234
     * @return true in case of success and false in case of failure
 
235
     * @note deprecated
 
236
     */
 
237
    virtual bool addAttributes( const QMap<QString, QString> &attributes );
 
238
 
 
239
    /**
 
240
     * Deletes existing attributes
 
241
     * @param attributes a set containing names of attributes
 
242
     * @return true in case of success and false in case of failure
 
243
     */
 
244
    virtual bool deleteAttributes( const QgsAttributeIds &attributes );
 
245
 
 
246
    /**
 
247
     * Changes attribute values of existing features.
 
248
     * @param attr_map a map containing changed attributes
 
249
     * @return true in case of success and false in case of failure
 
250
     */
 
251
    virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
 
252
 
 
253
    /**
 
254
     * Returns the default value for field specified by @c fieldId
 
255
     */
 
256
    virtual QVariant defaultValue( int fieldId );
 
257
 
 
258
    /**
 
259
     * Changes geometries of existing features
 
260
     * @param geometry_map   A QgsGeometryMap whose index contains the feature IDs
 
261
     *                       that will have their geometries changed.
 
262
     *                       The second map parameter being the new geometries themselves
 
263
     * @return               True in case of success and false in case of failure
 
264
     */
 
265
    virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );
 
266
 
 
267
    /**
 
268
     * Creates a spatial index on the datasource (if supported by the provider type).
 
269
     * @return true in case of success
 
270
     */
 
271
    virtual bool createSpatialIndex();
 
272
 
 
273
    /** Returns a bitmask containing the supported capabilities
 
274
        Note, some capabilities may change depending on whether
 
275
        a spatial filter is active on this provider, so it may
 
276
        be prudent to check this value per intended operation.
 
277
     */
 
278
    virtual int capabilities() const;
 
279
 
 
280
    /**
 
281
     *  Returns the above in friendly format.
 
282
     */
 
283
    QString capabilitiesString() const;
 
284
 
 
285
    /**
 
286
     * Set encoding used for accessing data from layer
 
287
     */
 
288
    virtual void setEncoding( const QString& e );
 
289
 
 
290
    /**
 
291
     * Get encoding which is used for accessing data
 
292
     */
 
293
    QString encoding() const;
 
294
 
 
295
    /**
 
296
     * Returns the index of a field name or -1 if the field does not exist
 
297
     */
 
298
    int fieldNameIndex( const QString& fieldName ) const;
 
299
 
 
300
    /**Return a map where the key is the name of the field and the value is its index*/
 
301
    QMap<QString, int> fieldNameMap() const;
 
302
 
 
303
    /**
 
304
     * Return list of indexes to fetch all attributes in nextFeature()
 
305
     */
 
306
    virtual QgsAttributeList attributeIndexes();
 
307
 
 
308
    /**
 
309
     * Set whether provider should also return features that don't have
 
310
     * associated geometry. FALSE by default
 
311
     */
 
312
    void enableGeometrylessFeatures( bool fetch );
 
313
 
 
314
    /**
 
315
     * check if provider supports type of field
 
316
     * @note added in 1.2
 
317
     */
 
318
    bool supportedType( const QgsField &field ) const;
 
319
 
 
320
    struct NativeType
 
321
    {
 
322
      NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
 
323
          mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {};
 
324
 
 
325
      QString mTypeDesc;
 
326
      QString mTypeName;
 
327
      QVariant::Type mType;
 
328
      int mMinLen, mMaxLen;
 
329
      int mMinPrec, mMaxPrec;
 
330
    };
 
331
 
 
332
 
 
333
    /**
 
334
     * Returns the names of the supported types
 
335
     * @note added in 1.2
 
336
     */
 
337
    const QList< NativeType > &nativeTypes() const;
 
338
 
 
339
 
 
340
    /**
 
341
     * Returns the names of the supported types
 
342
     * @note deprecated
 
343
     */
 
344
    const QMap<QString, QVariant::Type> &supportedNativeTypes() const;
 
345
 
 
346
    /** Returns true if the provider is strict about the type of inserted features
 
347
          (e.g. no multipolygon in a polygon layer)
 
348
          @note: added in version 1.4*/
 
349
    virtual bool doesStrictFeatureTypeCheck() const { return true;}
 
350
 
 
351
  protected:
 
352
    QVariant convertValue( QVariant::Type type, QString value );
 
353
 
 
354
    void fillMinMaxCache();
 
355
 
 
356
    bool mCacheMinMaxDirty;
 
357
    QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
 
358
 
 
359
    /** Encoding */
 
360
    QTextCodec* mEncoding;
 
361
 
 
362
    /** should provider fetch also features that don't have geometry? */
 
363
    bool mFetchFeaturesWithoutGeom;
 
364
 
 
365
    /**True if geometry should be added to the features in nextFeature calls*/
 
366
    bool mFetchGeom;
 
367
 
 
368
    /**List of attribute indices to fetch with nextFeature calls*/
 
369
    QgsAttributeList mAttributesToFetch;
 
370
 
 
371
    /**The names of the providers native types*/
 
372
    QList< NativeType > mNativeTypes;
 
373
 
 
374
  private:
 
375
    /** old notation **/
 
376
    QMap<QString, QVariant::Type> mOldTypeList;
351
377
};
352
378
 
353
379
#endif