QGIS API Documentation  master-3f58142
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                : marco.hugentobler@autoform.ch
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 #include <QHash>
00024 
00025 //QGIS Includes
00026 #include "qgis.h"
00027 #include "qgsdataprovider.h"
00028 #include "qgsfeature.h"
00029 #include "qgsfield.h"
00030 #include "qgsrectangle.h"
00031 
00032 typedef QList<int> QgsAttributeList;
00033 typedef QSet<int> QgsAttributeIds;
00034 typedef QHash<int, QString> QgsAttrPalIndexNameHash;
00035 
00036 class QgsFeatureIterator;
00037 
00038 #include "qgsfeaturerequest.h"
00039 
00048 class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider
00049 {
00050     Q_OBJECT
00051 
00052   public:
00053 
00054     // If you add to this, please also add to capabilitiesString()
00058     enum Capability
00059     {
00061       NoCapabilities =                     0,
00063       AddFeatures =                        1,
00065       DeleteFeatures =               1 <<  1,
00067       ChangeAttributeValues =        1 <<  2,
00069       AddAttributes =                1 <<  3,
00071       DeleteAttributes =             1 <<  4,
00073       SaveAsShapefile =              1 <<  5,
00075       CreateSpatialIndex =           1 <<  6,
00077       SelectAtId =                   1 <<  7,
00079       ChangeGeometries =             1 <<  8,
00081       SelectGeometryAtId =           1 <<  9,
00083       RandomSelectGeometryAtId =     1 << 10,
00085       SequentialSelectGeometryAtId = 1 << 11,
00086       CreateAttributeIndex =         1 << 12,
00088       SelectEncoding =               1 << 13,
00089     };
00090 
00092     const static int EditingCapabilities = AddFeatures | DeleteFeatures |
00093                                            ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes;
00094 
00099     QgsVectorDataProvider( QString uri = QString() );
00100 
00104     virtual ~QgsVectorDataProvider();
00105 
00109     virtual QString storageType() const;
00110 
00114     virtual QgsFeatureIterator getFeatures( const QgsFeatureRequest& request = QgsFeatureRequest() ) = 0;
00115 
00120     virtual QGis::WkbType geometryType() const = 0;
00121 
00126     virtual long featureCount() const = 0;
00127 
00133     virtual const QgsFields &fields() const = 0;
00134 
00139     virtual QString dataComment() const;
00140 
00149     virtual QVariant minimumValue( int index );
00150 
00159     virtual QVariant maximumValue( int index );
00160 
00169     virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 );
00170 
00176     virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); }
00177 
00182     virtual bool addFeatures( QgsFeatureList &flist );
00183 
00189     virtual bool deleteFeatures( const QgsFeatureIds &id );
00190 
00197     virtual bool addAttributes( const QList<QgsField> &attributes );
00198 
00204     virtual bool deleteAttributes( const QgsAttributeIds &attributes );
00205 
00211     virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map );
00212 
00216     virtual QVariant defaultValue( int fieldId );
00217 
00225     virtual bool changeGeometryValues( QgsGeometryMap & geometry_map );
00226 
00231     virtual bool createSpatialIndex();
00232 
00234     virtual bool createAttributeIndex( int field );
00235 
00241     virtual int capabilities() const;
00242 
00246     QString capabilitiesString() const;
00247 
00251     virtual void setEncoding( const QString& e );
00252 
00256     QString encoding() const;
00257 
00261     int fieldNameIndex( const QString& fieldName ) const;
00262 
00264     QMap<QString, int> fieldNameMap() const;
00265 
00269     virtual QgsAttributeList attributeIndexes();
00270 
00275     virtual QgsAttributeList pkAttributeIndexes() { return QgsAttributeList(); }
00276 
00280     virtual QgsAttrPalIndexNameHash palAttributeIndexNames() const { return mAttrPalIndexName; }
00281 
00286     bool supportedType( const QgsField &field ) const;
00287 
00288     struct NativeType
00289     {
00290       NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) :
00291           mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {};
00292 
00293       QString mTypeDesc;
00294       QString mTypeName;
00295       QVariant::Type mType;
00296       int mMinLen;
00297       int mMaxLen;
00298       int mMinPrec;
00299       int mMaxPrec;
00300     };
00301 
00306     const QList< NativeType > &nativeTypes() const;
00307 
00311     virtual bool doesStrictFeatureTypeCheck() const { return true;}
00312 
00314     static const QStringList &availableEncodings();
00315 
00316     /* provider has errors to report
00317      * @note added in 1.7
00318      */
00319     bool hasErrors();
00320 
00321     /* clear recorded errors
00322      * @note added in 1.7
00323      */
00324     void clearErrors();
00325 
00326     /* get recorded errors
00327      * @note added in 1.7
00328      */
00329     QStringList errors();
00330 
00331 
00336     virtual bool isSaveAndLoadStyleToDBSupported() { return false; }
00337 
00338   protected:
00339     QVariant convertValue( QVariant::Type type, QString value );
00340 
00341     void clearMinMaxCache();
00342     void fillMinMaxCache();
00343 
00344     bool mCacheMinMaxDirty;
00345     QMap<int, QVariant> mCacheMinValues, mCacheMaxValues;
00346 
00348     QTextCodec* mEncoding;
00349 
00351     bool mFetchFeaturesWithoutGeom;
00352 
00354     bool mFetchGeom;
00355 
00357     QgsAttributeList mAttributesToFetch;
00358 
00360     QList< NativeType > mNativeTypes;
00361 
00362     void pushError( QString msg );
00363 
00365     QgsAttrPalIndexNameHash mAttrPalIndexName;
00366 
00367   private:
00369     QMap<QString, QVariant::Type> mOldTypeList;
00370 
00371     // list of errors
00372     QStringList mErrors;
00373 
00374     static QStringList smEncodings;
00375 
00376 };
00377 
00378 
00379 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines