Skip to content

Commit

Permalink
Merge pull request #4509 from nyalldawson/exporter
Browse files Browse the repository at this point in the history
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 50e9728
Show file tree
Hide file tree
Showing 39 changed files with 821 additions and 642 deletions.
15 changes: 11 additions & 4 deletions doc/api_break.dox
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion python/core/core.sip
Expand Up @@ -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
Expand Down
200 changes: 200 additions & 0 deletions python/core/qgsvectorlayerexporter.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 *
************************************************************************/
127 changes: 0 additions & 127 deletions python/core/qgsvectorlayerimport.sip

This file was deleted.

1 change: 1 addition & 0 deletions python/core/raster/qgsrasterfilewritertask.sip
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/db_manager/db_model.py
Expand Up @@ -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
Expand Down

0 comments on commit 50e9728

Please sign in to comment.