Quantum GIS API Documentation
1.7.4
|
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 /* $Id$ */ 00016 #ifndef QGSVECTORDATAPROVIDER_H 00017 #define QGSVECTORDATAPROVIDER_H 00018 00019 class QTextCodec; 00020 00021 #include <QList> 00022 #include <QSet> 00023 #include <QMap> 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> QgsFeatureIds; 00034 typedef QSet<int> QgsAttributeIds; 00035 00044 class CORE_EXPORT QgsVectorDataProvider : public QgsDataProvider 00045 { 00046 Q_OBJECT 00047 00048 public: 00049 00050 // If you add to this, please also add to capabilitiesString() 00054 enum Capability 00055 { 00057 NoCapabilities = 0, 00059 AddFeatures = 1, 00061 DeleteFeatures = 1 << 1, 00063 ChangeAttributeValues = 1 << 2, 00065 AddAttributes = 1 << 3, 00067 DeleteAttributes = 1 << 4, 00069 SaveAsShapefile = 1 << 5, 00071 CreateSpatialIndex = 1 << 6, 00073 SelectAtId = 1 << 7, 00075 ChangeGeometries = 1 << 8, 00077 SelectGeometryAtId = 1 << 9, 00079 RandomSelectGeometryAtId = 1 << 10, 00081 SequentialSelectGeometryAtId = 1 << 11, 00082 CreateAttributeIndex = 1 << 12, 00084 SetEncoding = 1 << 13, 00085 }; 00086 00088 const static int EditingCapabilities = AddFeatures | DeleteFeatures | 00089 ChangeAttributeValues | ChangeGeometries | AddAttributes | DeleteAttributes; 00090 00095 QgsVectorDataProvider( QString uri = QString() ); 00096 00100 virtual ~QgsVectorDataProvider(); 00101 00105 virtual QString storageType() const; 00106 00114 virtual void select( QgsAttributeList fetchAttributes = QgsAttributeList(), 00115 QgsRectangle rect = QgsRectangle(), 00116 bool fetchGeometry = true, 00117 bool useIntersect = false ) = 0; 00118 00123 virtual long updateFeatureCount(); 00124 00136 virtual bool featureAtId( int featureId, 00137 QgsFeature& feature, 00138 bool fetchGeometry = true, 00139 QgsAttributeList fetchAttributes = QgsAttributeList() ); 00140 00146 virtual bool nextFeature( QgsFeature& feature ) = 0; 00147 00152 virtual QGis::WkbType geometryType() const = 0; 00153 00154 00159 virtual long featureCount() const = 0; 00160 00161 00165 virtual uint fieldCount() const = 0; 00166 00172 virtual const QgsFieldMap &fields() const = 0; 00173 00178 virtual QString dataComment() const; 00179 00181 virtual void rewind() = 0; 00182 00191 virtual QVariant minimumValue( int index ); 00192 00201 virtual QVariant maximumValue( int index ); 00202 00211 virtual void uniqueValues( int index, QList<QVariant> &uniqueValues, int limit = -1 ); 00212 00218 virtual void enumValues( int index, QStringList& enumList ) { Q_UNUSED( index ); enumList.clear(); } 00219 00224 virtual bool addFeatures( QgsFeatureList &flist ); 00225 00231 virtual bool deleteFeatures( const QgsFeatureIds &id ); 00232 00239 virtual bool addAttributes( const QList<QgsField> &attributes ); 00240 00247 Q_DECL_DEPRECATED virtual bool addAttributes( const QMap<QString, QString> &attributes ); 00248 00254 virtual bool deleteAttributes( const QgsAttributeIds &attributes ); 00255 00261 virtual bool changeAttributeValues( const QgsChangedAttributesMap &attr_map ); 00262 00266 virtual QVariant defaultValue( int fieldId ); 00267 00275 virtual bool changeGeometryValues( QgsGeometryMap & geometry_map ); 00276 00281 virtual bool createSpatialIndex(); 00282 00284 virtual bool createAttributeIndex( int field ); 00285 00291 virtual int capabilities() const; 00292 00296 QString capabilitiesString() const; 00297 00301 virtual void setEncoding( const QString& e ); 00302 00306 QString encoding() const; 00307 00311 int fieldNameIndex( const QString& fieldName ) const; 00312 00314 QMap<QString, int> fieldNameMap() const; 00315 00319 virtual QgsAttributeList attributeIndexes(); 00320 00325 void enableGeometrylessFeatures( bool fetch ); 00326 00331 bool supportedType( const QgsField &field ) const; 00332 00333 struct NativeType 00334 { 00335 NativeType( QString typeDesc, QString typeName, QVariant::Type type, int minLen = 0, int maxLen = 0, int minPrec = 0, int maxPrec = 0 ) : 00336 mTypeDesc( typeDesc ), mTypeName( typeName ), mType( type ), mMinLen( minLen ), mMaxLen( maxLen ), mMinPrec( minPrec ), mMaxPrec( maxPrec ) {}; 00337 00338 QString mTypeDesc; 00339 QString mTypeName; 00340 QVariant::Type mType; 00341 int mMinLen, mMaxLen; 00342 int mMinPrec, mMaxPrec; 00343 }; 00344 00345 00350 const QList< NativeType > &nativeTypes() const; 00351 00352 00357 Q_DECL_DEPRECATED const QMap<QString, QVariant::Type> &supportedNativeTypes() const; 00358 00362 virtual bool doesStrictFeatureTypeCheck() const { return true;} 00363 00364 00365 static const QStringList &availableEncodings(); 00366 00367 /* provider has errors to report 00368 * @note added in 1.7 00369 */ 00370 bool hasErrors(); 00371 00372 /* clear recorded errors 00373 * @note added in 1.7 00374 */ 00375 void clearErrors(); 00376 00377 /* get recorded errors 00378 * @note added in 1.7 00379 */ 00380 QStringList errors(); 00381 00382 00383 protected: 00384 QVariant convertValue( QVariant::Type type, QString value ); 00385 00386 void clearMinMaxCache(); 00387 void fillMinMaxCache(); 00388 00389 bool mCacheMinMaxDirty; 00390 QMap<int, QVariant> mCacheMinValues, mCacheMaxValues; 00391 00393 QTextCodec* mEncoding; 00394 00396 bool mFetchFeaturesWithoutGeom; 00397 00399 bool mFetchGeom; 00400 00402 QgsAttributeList mAttributesToFetch; 00403 00405 QList< NativeType > mNativeTypes; 00406 00407 void pushError( QString msg ); 00408 00409 private: 00411 QMap<QString, QVariant::Type> mOldTypeList; 00412 00413 // list of errors 00414 QStringList mErrors; 00415 00416 00417 static QStringList smEncodings; 00418 00419 }; 00420 00421 #endif