Skip to content

Commit 50e9728

Browse files
authored
Merge pull request #4509 from nyalldawson/exporter
API Cleanups (and rename) for QgsVectorLayerImport, background export of layers when dropping to browser
2 parents 9adc322 + b6a5cc4 commit 50e9728

39 files changed

+821
-642
lines changed

doc/api_break.dox

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ Renamed Classes {#qgis_api_break_3_0_renamed_classes}
186186
<tr><td>QgsVectorGradientColorRampV2DialogBase<td>QgsGradientColorRampDialogBase
187187
<tr><td>QgsVectorGradientRampV2<td>QgsVectorGradientRamp
188188
<tr><td>QgsVectorJoinInfo<td>QgsVectorLayerJoinInfo
189+
<tr><td>QgsVectorLayerImport<td>QgsVectorLayerExporter
189190
<tr><td>QgsVectorLayersetRendererV2<td>QgsVectorLayersetRenderer
190191
<tr><td>QgsVectorRandomColorRampV2<td>QgsLimitedRandomColorRamp
191192
<tr><td>QgsVectorRandomColorRampV2Dialog<td>QgsLimitedRandomColorRampDialog
@@ -2180,15 +2181,21 @@ QgsVectorLayerEditUtils {#qgis_api_break_3_0_QgsVectorLayerEditUtils}
21802181
- cache() has been removed.
21812182

21822183

2183-
QgsVectorLayerImport {#qgis_api_break_3_0_QgsVectorLayerImport}
2184+
QgsVectorLayerExporter (renamed from QgsVectorLayerImport) {#qgis_api_break_3_0_QgsVectorLayerExporter}
21842185
--------------------
21852186

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

21932200

21942201
QgsVectorLayerJoinBuffer {#qgis_api_break_3_0_QgsVectorLayerJoinBuffer}

python/core/core.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@
165165
%Include qgsvectorlayercache.sip
166166
%Include qgsvectorlayereditbuffer.sip
167167
%Include qgsvectorlayereditpassthrough.sip
168+
%Include qgsvectorlayerexporter.sip
168169
%Include qgsvectorlayerfeaturecounter.sip
169-
%Include qgsvectorlayerimport.sip
170170
%Include qgsvectorlayerjoinbuffer.sip
171171
%Include qgsvectorlayerjoininfo.sip
172172
%Include qgsvectorlayertools.sip
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/core/qgsvectorlayerexporter.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
13+
class QgsVectorLayerExporter : QgsFeatureSink
14+
{
15+
%Docstring
16+
A convenience class for exporting vector layers to a destination data provider.
17+
18+
QgsVectorLayerExporter can be used in two ways:
19+
20+
1. Using a static call to QgsVectorLayerExporter.exportLayer(...) which exports the
21+
entire layer to the destination provider.
22+
23+
2. Create an instance of the class and issue calls to addFeature(...)
24+
25+
.. versionadded:: 3.0
26+
%End
27+
28+
%TypeHeaderCode
29+
#include "qgsvectorlayerexporter.h"
30+
%End
31+
public:
32+
33+
enum ExportError
34+
{
35+
NoError,
36+
ErrCreateDataSource,
37+
ErrCreateLayer,
38+
ErrAttributeTypeUnsupported,
39+
ErrAttributeCreationFailed,
40+
ErrProjection,
41+
ErrFeatureWriteFailed,
42+
ErrInvalidLayer,
43+
ErrInvalidProvider,
44+
ErrProviderUnsupportedFeature,
45+
ErrConnectionFailed,
46+
ErrUserCanceled,
47+
};
48+
49+
static ExportError exportLayer( QgsVectorLayer *layer,
50+
const QString &uri,
51+
const QString &providerKey,
52+
const QgsCoordinateReferenceSystem &destCRS,
53+
bool onlySelected = false,
54+
QString *errorMessage /Out/ = 0,
55+
QMap<QString, QVariant> *options = 0,
56+
QgsFeedback *feedback = 0
57+
);
58+
%Docstring
59+
Writes the contents of vector layer to a different datasource.
60+
\param layer source layer
61+
\param uri URI for destination data source
62+
\param providerKey string key for destination data provider
63+
\param destCRS destination CRS, or an invalid (default constructed) CRS if
64+
not available
65+
\param onlySelected set to true to export only selected features
66+
\param errorMessage if non-null, will be set to any error messages
67+
\param options optional provider dataset options
68+
\param feedback optional feedback object to show progress and cancelation of export
69+
:return: NoError for a successful export, or encountered error
70+
:rtype: ExportError
71+
%End
72+
73+
QgsVectorLayerExporter( const QString &uri,
74+
const QString &provider,
75+
const QgsFields &fields,
76+
QgsWkbTypes::Type geometryType,
77+
const QgsCoordinateReferenceSystem &crs,
78+
bool overwrite = false,
79+
const QMap<QString, QVariant> *options = 0 );
80+
%Docstring
81+
Constructor for QgsVectorLayerExporter.
82+
\param uri URI for destination data source
83+
\param provider string key for destination data provider
84+
\param fields fields to include in created layer
85+
\param geometryType destination geometry type
86+
\param crs desired CRS, or an invalid (default constructed) CRS if
87+
not available
88+
\param overwrite set to true to overwrite any existing data source
89+
\param options optional provider dataset options
90+
%End
91+
92+
93+
ExportError errorCode() const;
94+
%Docstring
95+
Returns any encountered error code, or false if no error was encountered.
96+
.. seealso:: errorMessage()
97+
.. seealso:: errorCount()
98+
:rtype: ExportError
99+
%End
100+
101+
QString errorMessage() const;
102+
%Docstring
103+
Returns any error message encountered during the export.
104+
.. seealso:: errorCount()
105+
.. seealso:: errorCode()
106+
:rtype: str
107+
%End
108+
109+
int errorCount() const;
110+
%Docstring
111+
Returns the number of error messages encountered during the export.
112+
.. seealso:: errorMessage()
113+
.. seealso:: errorCode()
114+
:rtype: int
115+
%End
116+
117+
virtual bool addFeatures( QgsFeatureList &features );
118+
119+
virtual bool addFeature( QgsFeature &feature );
120+
121+
122+
~QgsVectorLayerExporter();
123+
%Docstring
124+
Finalizes the export and closes the new created layer.
125+
%End
126+
127+
private:
128+
QgsVectorLayerExporter( const QgsVectorLayerExporter &rh );
129+
};
130+
131+
132+
class QgsVectorLayerExporterTask : QgsTask
133+
{
134+
%Docstring
135+
QgsTask task which performs a QgsVectorLayerExporter layer export operation as a background
136+
task. This can be used to export a vector layer out to a provider without blocking the
137+
QGIS interface.
138+
.. versionadded:: 3.0
139+
.. seealso:: QgsVectorFileWriterTask
140+
.. seealso:: QgsRasterFileWriterTask
141+
%End
142+
143+
%TypeHeaderCode
144+
#include "qgsvectorlayerexporter.h"
145+
%End
146+
public:
147+
148+
QgsVectorLayerExporterTask( QgsVectorLayer *layer,
149+
const QString &uri,
150+
const QString &providerKey,
151+
const QgsCoordinateReferenceSystem &destinationCrs,
152+
QMap<QString, QVariant> *options = 0 );
153+
%Docstring
154+
Constructor for QgsVectorLayerExporterTask. Takes a source ``layer``, destination ``uri``
155+
and ``providerKey``, and various export related parameters such as destination CRS
156+
and export ``options``.
157+
%End
158+
159+
static QgsVectorLayerExporterTask *withLayerOwnership( QgsVectorLayer *layer /Transfer/,
160+
const QString &uri,
161+
const QString &providerKey,
162+
const QgsCoordinateReferenceSystem &destinationCrs,
163+
QMap<QString, QVariant> *options = 0 ) /Factory/;
164+
%Docstring
165+
Creates a new QgsVectorLayerExporterTask which has ownership over a source ``layer``.
166+
When the export task has completed (successfully or otherwise) ``layer`` will be
167+
deleted. The destination ``uri`` and ``providerKey``, and various export related parameters such as destination CRS
168+
and export ``options`` must be specified.
169+
:rtype: QgsVectorLayerExporterTask
170+
%End
171+
172+
virtual void cancel();
173+
174+
signals:
175+
176+
void exportComplete();
177+
%Docstring
178+
Emitted when exporting the layer is successfully completed.
179+
%End
180+
181+
void errorOccurred( int error, const QString &errorMessage );
182+
%Docstring
183+
Emitted when an error occurs which prevented the layer being exported (or if
184+
the task is canceled). The export ``error`` and ``errorMessage`` will be reported.
185+
%End
186+
187+
protected:
188+
189+
virtual bool run();
190+
virtual void finished( bool result );
191+
192+
};
193+
194+
/************************************************************************
195+
* This file has been generated automatically from *
196+
* *
197+
* src/core/qgsvectorlayerexporter.h *
198+
* *
199+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
200+
************************************************************************/

python/core/qgsvectorlayerimport.sip

Lines changed: 0 additions & 127 deletions
This file was deleted.

python/core/raster/qgsrasterfilewritertask.sip

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class QgsRasterFileWriterTask : QgsTask
1616
task. This can be used to save a raster layer out to a file without blocking the
1717
QGIS interface.
1818
.. seealso:: QgsVectorFileWriterTask
19+
.. seealso:: QgsVectorFileExporterTask
1920
.. versionadded:: 3.0
2021
%End
2122

python/plugins/db_manager/db_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from . import resources_rc # NOQA
3737

3838
try:
39-
from qgis.core import QgsVectorLayerImport # NOQA
39+
from qgis.core import QgsVectorLayerExporter # NOQA
4040
isImportVectorAvail = True
4141
except:
4242
isImportVectorAvail = False

0 commit comments

Comments
 (0)