QGIS API Documentation  master-6227475
src/core/qgsvectorlayerimport.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                           qgsvectorlayerimport.cpp
00003                           vector layer importer
00004                              -------------------
00005     begin                : Thu Aug 25 2011
00006     copyright            : (C) 2011 by Giuseppe Sucameli
00007     email                : brush.tyler at gmail.com
00008  ***************************************************************************/
00009 
00010 /***************************************************************************
00011  *                                                                         *
00012  *   This program is free software; you can redistribute it and/or modify  *
00013  *   it under the terms of the GNU General Public License as published by  *
00014  *   the Free Software Foundation; either version 2 of the License, or     *
00015  *   (at your option) any later version.                                   *
00016  *                                                                         *
00017  ***************************************************************************/
00018 
00019 #ifndef _QGSVECTORLAYERIMPORT_H_
00020 #define _QGSVECTORLAYERIMPORT_H_
00021 
00022 #include "qgsvectordataprovider.h"
00023 #include "qgsvectorlayer.h"
00024 
00025 class QProgressDialog;
00026 
00036 class CORE_EXPORT QgsVectorLayerImport
00037 {
00038   public:
00039 
00040     enum ImportError
00041     {
00042       NoError = 0,
00043       ErrDriverNotFound,
00044       ErrCreateDataSource,
00045       ErrCreateLayer,
00046       ErrAttributeTypeUnsupported,
00047       ErrAttributeCreationFailed,
00048       ErrProjection,
00049       ErrFeatureWriteFailed,
00050       ErrInvalidLayer,
00051       ErrInvalidProvider,
00052       ErrProviderUnsupportedFeature,
00053       ErrConnectionFailed
00054     };
00055 
00057     static ImportError importLayer( QgsVectorLayer* layer,
00058                                     const QString& uri,
00059                                     const QString& providerKey,
00060                                     const QgsCoordinateReferenceSystem *destCRS,
00061                                     bool onlySelected = false,
00062                                     QString *errorMessage = 0,
00063                                     bool skipAttributeCreation = false,
00064                                     QMap<QString, QVariant> *options = 0,
00065                                     QProgressDialog *progress = 0
00066                                   );
00067 
00069     QgsVectorLayerImport( const QString &uri,
00070                           const QString &provider,
00071                           const QgsFields &fields,
00072                           QGis::WkbType geometryType,
00073                           const QgsCoordinateReferenceSystem* crs,
00074                           bool overwrite = false,
00075                           const QMap<QString, QVariant> *options = 0,
00076                           QProgressDialog *progress = 0
00077                         );
00078 
00080     ImportError hasError();
00081 
00083     QString errorMessage();
00084 
00085     int errorCount() const { return mErrorCount; }
00086 
00088     bool addFeature( QgsFeature& feature );
00089 
00091     ~QgsVectorLayerImport();
00092 
00093   protected:
00095     bool flushBuffer();
00096 
00098     bool createSpatialIndex();
00099 
00101     ImportError mError;
00102     QString mErrorMessage;
00103 
00104     int mErrorCount;
00105 
00106     QgsVectorDataProvider *mProvider;
00107 
00109     QMap<int, int> mOldToNewAttrIdx;
00110     int mAttributeCount;
00111 
00112     QgsFeatureList mFeatureBuffer;
00113     QProgressDialog *mProgress;
00114 };
00115 
00116 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines