Skip to content
Permalink
Browse files
Merge pull request #4509 from nyalldawson/exporter
API Cleanups (and rename) for QgsVectorLayerImport, background export of layers when dropping to browser
  • Loading branch information
nyalldawson committed May 12, 2017
2 parents 9adc322 + b6a5cc4 commit 50e972805b4064df2d57816712c30d202cdbaab8
Showing with 821 additions and 642 deletions.
  1. +11 −4 doc/api_break.dox
  2. +1 −1 python/core/core.sip
  3. +200 −0 python/core/qgsvectorlayerexporter.sip
  4. +0 −127 python/core/qgsvectorlayerimport.sip
  5. +1 −0 python/core/raster/qgsrasterfilewritertask.sip
  6. +1 −1 python/plugins/db_manager/db_model.py
  7. +2 −2 python/plugins/db_manager/db_plugins/oracle/TODO.md
  8. +7 −3 python/plugins/db_manager/dlg_export_vector.py
  9. +9 −2 python/plugins/db_manager/dlg_import_vector.py
  10. +2 −3 python/plugins/processing/algs/qgis/ImportIntoPostGIS.py
  11. +2 −3 python/plugins/processing/algs/qgis/ImportIntoSpatialite.py
  12. +3 −2 src/core/CMakeLists.txt
  13. +3 −3 src/core/processing/qgsprocessingutils.cpp
  14. +1 −0 src/core/qgsvectorfilewritertask.h
  15. +94 −51 src/core/{qgsvectorlayerimport.cpp → qgsvectorlayerexporter.cpp}
  16. +248 −0 src/core/qgsvectorlayerexporter.h
  17. +0 −148 src/core/qgsvectorlayerimport.h
  18. +1 −0 src/core/raster/qgsrasterfilewritertask.h
  19. +33 −49 src/providers/db2/qgsdb2dataitems.cpp
  20. +9 −9 src/providers/db2/qgsdb2provider.cpp
  21. +2 −2 src/providers/db2/qgsdb2provider.h
  22. +35 −42 src/providers/mssql/qgsmssqldataitems.cpp
  23. +11 −11 src/providers/mssql/qgsmssqlprovider.cpp
  24. +2 −2 src/providers/mssql/qgsmssqlprovider.h
  25. +7 −7 src/providers/ogr/qgsogrprovider.cpp
  26. +3 −3 src/providers/ogr/qgsogrprovider.h
  27. +32 −42 src/providers/oracle/qgsoracledataitems.cpp
  28. +1 −1 src/providers/oracle/qgsoracledataitems.h
  29. +11 −11 src/providers/oracle/qgsoracleprovider.cpp
  30. +2 −2 src/providers/oracle/qgsoracleprovider.h
  31. +25 −37 src/providers/postgres/qgspostgresdataitems.cpp
  32. +1 −1 src/providers/postgres/qgspostgresdataitems.h
  33. +9 −9 src/providers/postgres/qgspostgresprovider.cpp
  34. +2 −2 src/providers/postgres/qgspostgresprovider.h
  35. +27 −39 src/providers/spatialite/qgsspatialitedataitems.cpp
  36. +9 −9 src/providers/spatialite/qgsspatialiteprovider.cpp
  37. +2 −2 src/providers/spatialite/qgsspatialiteprovider.h
  38. +7 −7 tests/src/python/test_provider_ogr_gpkg.py
  39. +5 −5 tests/src/python/test_provider_postgres.py
@@ -186,6 +186,7 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
<tr><td>QgsVectorGradientColorRampV2DialogBase<td>QgsGradientColorRampDialogBase
<tr><td>QgsVectorGradientRampV2<td>QgsVectorGradientRamp
<tr><td>QgsVectorJoinInfo<td>QgsVectorLayerJoinInfo
<tr><td>QgsVectorLayerImport<td>QgsVectorLayerExporter
<tr><td>QgsVectorLayersetRendererV2<td>QgsVectorLayersetRenderer
<tr><td>QgsVectorRandomColorRampV2<td>QgsLimitedRandomColorRamp
<tr><td>QgsVectorRandomColorRampV2Dialog<td>QgsLimitedRandomColorRampDialog
@@ -2180,15 +2181,21 @@ QgsVectorLayerEditUtils {#qgis_api_break_3_0_QgsVectorLayerEditUtils}
- cache() has been removed.


QgsVectorLayerImport {#qgis_api_break_3_0_QgsVectorLayerImport}
QgsVectorLayerExporter (renamed from QgsVectorLayerImport) {#qgis_api_break_3_0_QgsVectorLayerExporter}
--------------------

- QgsVectorLayerImport now takes references instead of pointers to QgsCoordinateReferenceSystem objects. Since
- QgsVectorLayerExporter now takes references instead of pointers to QgsCoordinateReferenceSystem objects. Since
QgsCoordinateReferenceSystem is now implicitly shared, using references to QgsCoordinateReferenceSystem rather than
pointers makes for more robust, safer code. Use an invalid (default constructed) QgsCoordinateReferenceSystem
in code which previously passed a null pointer to QgsVectorLayerImport.
- The unused QProgressBar argument in the QgsVectorLayerImport was removed
- ErrUserCancelled (ImportError enum value) has been renamed to ErrUserCanceled <!--#spellok-->
- importLayer was renamed to exportLayer
- The unused skipAttributeCreation in exportLayer() was removed
- The QProgressDialog argument in exportLayer() was changed to a QgsFeedback object.
- The unused QProgressDialog argument in the QgsVectorLayerImport was removed
- ImportError was renamed to ExportError
- The unused enum value ErrDriverNotFound was removed
- hasError() was renamed to errorCode()
- ErrUserCancelled (ExportError enum value) has been renamed to ErrUserCanceled <!--#spellok-->


QgsVectorLayerJoinBuffer {#qgis_api_break_3_0_QgsVectorLayerJoinBuffer}
@@ -165,8 +165,8 @@
%Include qgsvectorlayercache.sip
%Include qgsvectorlayereditbuffer.sip
%Include qgsvectorlayereditpassthrough.sip
%Include qgsvectorlayerexporter.sip
%Include qgsvectorlayerfeaturecounter.sip
%Include qgsvectorlayerimport.sip
%Include qgsvectorlayerjoinbuffer.sip
%Include qgsvectorlayerjoininfo.sip
%Include qgsvectorlayertools.sip
@@ -0,0 +1,200 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsvectorlayerexporter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/





class QgsVectorLayerExporter : QgsFeatureSink
{
%Docstring
A convenience class for exporting vector layers to a destination data provider.

QgsVectorLayerExporter can be used in two ways:

1. Using a static call to QgsVectorLayerExporter.exportLayer(...) which exports the
entire layer to the destination provider.

2. Create an instance of the class and issue calls to addFeature(...)

.. versionadded:: 3.0
%End

%TypeHeaderCode
#include "qgsvectorlayerexporter.h"
%End
public:

enum ExportError
{
NoError,
ErrCreateDataSource,
ErrCreateLayer,
ErrAttributeTypeUnsupported,
ErrAttributeCreationFailed,
ErrProjection,
ErrFeatureWriteFailed,
ErrInvalidLayer,
ErrInvalidProvider,
ErrProviderUnsupportedFeature,
ErrConnectionFailed,
ErrUserCanceled,
};

static ExportError exportLayer( QgsVectorLayer *layer,
const QString &uri,
const QString &providerKey,
const QgsCoordinateReferenceSystem &destCRS,
bool onlySelected = false,
QString *errorMessage /Out/ = 0,
QMap<QString, QVariant> *options = 0,
QgsFeedback *feedback = 0
);
%Docstring
Writes the contents of vector layer to a different datasource.
\param layer source layer
\param uri URI for destination data source
\param providerKey string key for destination data provider
\param destCRS destination CRS, or an invalid (default constructed) CRS if
not available
\param onlySelected set to true to export only selected features
\param errorMessage if non-null, will be set to any error messages
\param options optional provider dataset options
\param feedback optional feedback object to show progress and cancelation of export
:return: NoError for a successful export, or encountered error
:rtype: ExportError
%End

QgsVectorLayerExporter( const QString &uri,
const QString &provider,
const QgsFields &fields,
QgsWkbTypes::Type geometryType,
const QgsCoordinateReferenceSystem &crs,
bool overwrite = false,
const QMap<QString, QVariant> *options = 0 );
%Docstring
Constructor for QgsVectorLayerExporter.
\param uri URI for destination data source
\param provider string key for destination data provider
\param fields fields to include in created layer
\param geometryType destination geometry type
\param crs desired CRS, or an invalid (default constructed) CRS if
not available
\param overwrite set to true to overwrite any existing data source
\param options optional provider dataset options
%End


ExportError errorCode() const;
%Docstring
Returns any encountered error code, or false if no error was encountered.
.. seealso:: errorMessage()
.. seealso:: errorCount()
:rtype: ExportError
%End

QString errorMessage() const;
%Docstring
Returns any error message encountered during the export.
.. seealso:: errorCount()
.. seealso:: errorCode()
:rtype: str
%End

int errorCount() const;
%Docstring
Returns the number of error messages encountered during the export.
.. seealso:: errorMessage()
.. seealso:: errorCode()
:rtype: int
%End

virtual bool addFeatures( QgsFeatureList &features );

virtual bool addFeature( QgsFeature &feature );


~QgsVectorLayerExporter();
%Docstring
Finalizes the export and closes the new created layer.
%End

private:
QgsVectorLayerExporter( const QgsVectorLayerExporter &rh );
};


class QgsVectorLayerExporterTask : QgsTask
{
%Docstring
QgsTask task which performs a QgsVectorLayerExporter layer export operation as a background
task. This can be used to export a vector layer out to a provider without blocking the
QGIS interface.
.. versionadded:: 3.0
.. seealso:: QgsVectorFileWriterTask
.. seealso:: QgsRasterFileWriterTask
%End

%TypeHeaderCode
#include "qgsvectorlayerexporter.h"
%End
public:

QgsVectorLayerExporterTask( QgsVectorLayer *layer,
const QString &uri,
const QString &providerKey,
const QgsCoordinateReferenceSystem &destinationCrs,
QMap<QString, QVariant> *options = 0 );
%Docstring
Constructor for QgsVectorLayerExporterTask. Takes a source ``layer``, destination ``uri``
and ``providerKey``, and various export related parameters such as destination CRS
and export ``options``.
%End

static QgsVectorLayerExporterTask *withLayerOwnership( QgsVectorLayer *layer /Transfer/,
const QString &uri,
const QString &providerKey,
const QgsCoordinateReferenceSystem &destinationCrs,
QMap<QString, QVariant> *options = 0 ) /Factory/;
%Docstring
Creates a new QgsVectorLayerExporterTask which has ownership over a source ``layer``.
When the export task has completed (successfully or otherwise) ``layer`` will be
deleted. The destination ``uri`` and ``providerKey``, and various export related parameters such as destination CRS
and export ``options`` must be specified.
:rtype: QgsVectorLayerExporterTask
%End

virtual void cancel();

signals:

void exportComplete();
%Docstring
Emitted when exporting the layer is successfully completed.
%End

void errorOccurred( int error, const QString &errorMessage );
%Docstring
Emitted when an error occurs which prevented the layer being exported (or if
the task is canceled). The export ``error`` and ``errorMessage`` will be reported.
%End

protected:

virtual bool run();
virtual void finished( bool result );

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/qgsvectorlayerexporter.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

This file was deleted.

@@ -16,6 +16,7 @@ class QgsRasterFileWriterTask : QgsTask
task. This can be used to save a raster layer out to a file without blocking the
QGIS interface.
.. seealso:: QgsVectorFileWriterTask
.. seealso:: QgsVectorFileExporterTask
.. versionadded:: 3.0
%End

@@ -36,7 +36,7 @@
from . import resources_rc # NOQA

try:
from qgis.core import QgsVectorLayerImport # NOQA
from qgis.core import QgsVectorLayerExporter # NOQA
isImportVectorAvail = True
except:
isImportVectorAvail = False

0 comments on commit 50e9728

Please sign in to comment.