Quantum GIS API Documentation  1.8
src/core/qgsvectordataprovider.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsvectordataprovider.h - DataProvider Interface for vector layers
00003      --------------------------------------
00004     Date                 : 23-Sep-2004
00005     Copyright            : (C) 2004 by Marco Hugentobler
00006     email                : [email protected]
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 #ifndef QGSVECTORDATAPROVIDER_H
00016 #define QGSVECTORDATAPROVIDER_H
00017 
00018 class QTextCodec;
00019 
00020 #include <QList>
00021 #include <QSet>
00022 #include <QMap>
00023 
00024 //QGIS Includes
00025 #include "qgis.h"
00026 #include "qgsdataprovider.h"
00027 #include "qgsfeature.h"
00028 #include "qgsfield.h"
00029 #include "qgsrectangle.h"
00030 
00031 typedef QList<int> QgsAttributeList;
00032 typedef QSet<int> QgsAttributeIds;
00033 
00042 class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
00043 {
00044     Q_OBJECT
00045 
00046   public:
00047 
00048     // If you add to this, please also add to capabilitiesString()
00052     enum Capability
00053     {
00055       NoCapabilities =                     0,
00057       AddFeatures =                        1,
00059       DeleteFeatures =               1 <<  1,
00061       ChangeAttributeValues =        1 <<  2,
00063       AddAttributes =                1 <<  3,
00065       DeleteAttributes =             1 <<  4,
00067       SaveAsShapefile =              1 <<  5,
00069       CreateSpatialIndex =           1 <<  6,
00071       SelectAtId =                   1 <<  7,
00073       ChangeGeometries =             1 <<  8,
00075       SelectGeometryAtId =           1 <<  9,
00077       RandomSelectGeometryAtId =     1 << 10,
00079       SequentialSelectGeometryAtId = 1 << 11,
00080       CreateAttributeIndex = 1 << 12,
00082       SetEncoding = 1 << 13,
00083     };
00084 
00086     const static int EditingCapabilities = AddFeatures | DeleteFeatures |
00087                                            ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;
00088 
00093     QgsVectorDataProvider( QString uri = QString() );
00094 
00098     virtual ~QgsVectorDataProvider();
00099 
00103     virtual QString storageType() const;
00104 
00112     virtual void select( QgsAttributeList fetchAttributes = QgsAttributeList(),
00113                          QgsRectangle rect = QgsRectangle(),
00114                          bool fetchGeometry = true,
00115                          bool useIntersect = false ) = 0;
00116 
00121     virtual long updateFeatureCount();
00122 
00134     virtual bool featureAtId( QgsFeatureId featureId,
00135                               QgsFeature& feature,
00136                               bool fetchGeometry = true,
00137                               QgsAttributeList fetchAttributes = QgsAttributeList() );
00138 
00144     virtual bool nextFeature( QgsFeature& feature ) = 0;
00145 
00150     virtual QGis::WkbType geometryType() const = 0;
00151 
00152 
00157     virtual long featureCount() const = 0;
00158 
00159 
00163     virtual uint fieldCount() const = 0;
00164 
00170     virtual const QgsFieldMap &fields() const = 0;
00171 
00176     virtual QString dataComment() const;
00177 
00179     virtual void rewind() = 0;
00180 
00189     virtual QVariant minimumValue( int index );
00190 
00199     virtual QVariant maximumValue( int index );
00200 
00209     virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
00210 
00216     virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
00217 
00222     virtual bool addFeatures( QgsFeatureList &flist );
00223 
00229     virtual bool deleteFeatures( const QgsFeatureIds &id );
00230 
00237     virtual bool addAttributes( const QList<QgsField> &attributes );
00238 
00245     Q_DECL_DEPRECATED virtual bool addAttributes( const QMap<QString, QString> &attributes );
00246 
00252     virtual bool deleteAttributes( const QgsAttributeIds &attributes );
00253 
00259     virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
00260 
00264     virtual QVariant defaultValue( int fieldId );
00265 
00273     virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );
00274 
00279     virtual bool createSpatialIndex();
00280 
00282     virtual bool createAttributeIndex( int field );
00283 
00289     virtual int capabilities() const;
00290 
00294     QString capabilitiesString() const;
00295 
00299     virtual void setEncoding( const QString& e );
00300 
00304     QString encoding() const;
00305 
00309     int fieldNameIndex( const QString& fieldName ) const;
00310 
00312     QMap<QString, int> fieldNameMap() const;
00313 
00317     virtual QgsAttributeList attributeIndexes();
00318 
00323     void enableGeometrylessFeatures( bool fetch );
00324 
00329     bool supportedType( const QgsField &field ) const;
00330 
00331     struct NativeType
00332     {
00333       NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
00334           mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {};
00335 
00336       QString mTypeDesc;
00337       QString mTypeName;
00338       QVariant::Type mType;
00339       int mMinLen, mMaxLen;
00340       int mMinPrec, mMaxPrec;
00341     };
00342 
00343 
00348     const QList< NativeType > &nativeTypes() const;
00349 
00350 
00355     Q_DECL_DEPRECATED const QMap<QString, QVariant::Type> &supportedNativeTypes() const;
00356 
00360     virtual bool doesStrictFeatureTypeCheck() const { return true;}
00361 
00362 
00363     static const QStringList &availableEncodings();
00364 
00365     /* provider has errors to report
00366      * @note added in 1.7
00367      */
00368     bool hasErrors();
00369 
00370     /* clear recorded errors
00371      * @note added in 1.7
00372      */
00373     void clearErrors();
00374 
00375     /* get recorded errors
00376      * @note added in 1.7
00377      */
00378     QStringList errors();
00379 
00380 
00381   protected:
00382     QVariant convertValue( QVariant::Type type, QString value );
00383 
00384     void clearMinMaxCache();
00385     void fillMinMaxCache();
00386 
00387     bool mCacheMinMaxDirty;
00388     QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
00389 
00391     QTextCodec* mEncoding;
00392 
00394     bool mFetchFeaturesWithoutGeom;
00395 
00397     bool mFetchGeom;
00398 
00400     QgsAttributeList mAttributesToFetch;
00401 
00403     QList< NativeType > mNativeTypes;
00404 
00405     void pushError( QString msg );
00406 
00407   private:
00409     QMap<QString, QVariant::Type> mOldTypeList;
00410 
00411     // list of errors
00412     QStringList mErrors;
00413 
00414     static QStringList smEncodings;
00415 
00416 };
00417 
00418 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines