Skip to content

Commit 384369c

Browse files
committed
Rename QgsVectorLayerImport to QgsVectorLayerExporter
Since the majority of users of this class will be exporting an existing map layer to a data provider, the QgsVectorLayerImport name is misleading and suggests that this class is designed just to bring layers "into" QGIS. Explicitly naming the class "Exporter" should help API users discover this class. Also cleanup API and improve docs
1 parent 354b667 commit 384369c

34 files changed

+281
-231
lines changed

doc/api_break.dox

Lines changed: 8 additions & 3 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,19 @@ 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.
2191+
- importLayer was renamed to exportLayer
21902192
- The unused QProgressBar argument in the QgsVectorLayerImport was removed
2191-
- ErrUserCancelled (ImportError enum value) has been renamed to ErrUserCanceled <!--#spellok-->
2193+
- ImportError was renamed to ExportError
2194+
- The unused enum value ErrDriverNotFound was removed
2195+
- hasError() was renamed to errorCode()
2196+
- ErrUserCancelled (ExportError enum value) has been renamed to ErrUserCanceled <!--#spellok-->
21922197

21932198

21942199
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: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/************************************************************************
22
* This file has been generated automatically from *
33
* *
4-
* src/core/qgsvectorlayerimport.h *
4+
* src/core/qgsvectorlayerexporter.h *
55
* *
66
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
77
************************************************************************/
@@ -10,24 +10,29 @@
1010

1111

1212

13-
class QgsVectorLayerImport : QgsFeatureSink
13+
class QgsVectorLayerExporter : QgsFeatureSink
1414
{
1515
%Docstring
16-
A convenience class for writing vector files to disk.
17-
There are two possibilities how to use this class:
18-
1. static call to QgsVectorFileWriter.writeAsShapefile(...) which saves the whole vector layer
19-
2. create an instance of the class and issue calls to addFeature(...)
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
2026
%End
2127

2228
%TypeHeaderCode
23-
#include "qgsvectorlayerimport.h"
29+
#include "qgsvectorlayerexporter.h"
2430
%End
2531
public:
2632

27-
enum ImportError
33+
enum ExportError
2834
{
2935
NoError,
30-
ErrDriverNotFound,
3136
ErrCreateDataSource,
3237
ErrCreateLayer,
3338
ErrAttributeTypeUnsupported,
@@ -41,7 +46,7 @@ There are two possibilities how to use this class:
4146
ErrUserCanceled,
4247
};
4348

44-
static ImportError importLayer( QgsVectorLayer *layer,
49+
static ExportError exportLayer( QgsVectorLayer *layer,
4550
const QString &uri,
4651
const QString &providerKey,
4752
const QgsCoordinateReferenceSystem &destCRS,
@@ -64,18 +69,18 @@ There are two possibilities how to use this class:
6469
\param options optional provider dataset options
6570
\param progress optional progress dialog to show progress of export
6671
:return: NoError for a successful export, or encountered error
67-
:rtype: ImportError
72+
:rtype: ExportError
6873
%End
6974

70-
QgsVectorLayerImport( const QString &uri,
71-
const QString &provider,
72-
const QgsFields &fields,
73-
QgsWkbTypes::Type geometryType,
74-
const QgsCoordinateReferenceSystem &crs,
75-
bool overwrite = false,
76-
const QMap<QString, QVariant> *options = 0 );
75+
QgsVectorLayerExporter( const QString &uri,
76+
const QString &provider,
77+
const QgsFields &fields,
78+
QgsWkbTypes::Type geometryType,
79+
const QgsCoordinateReferenceSystem &crs,
80+
bool overwrite = false,
81+
const QMap<QString, QVariant> *options = 0 );
7782
%Docstring
78-
Constructor for QgsVectorLayerImport.
83+
Constructor for QgsVectorLayerExporter.
7984
\param uri URI for destination data source
8085
\param provider string key for destination data provider
8186
\param fields fields to include in created layer
@@ -87,20 +92,27 @@ There are two possibilities how to use this class:
8792
%End
8893

8994

90-
ImportError hasError();
95+
ExportError errorCode() const;
9196
%Docstring
92-
Checks whether there were any errors
93-
:rtype: ImportError
97+
Returns any encountered error code, or false if no error was encountered.
98+
.. seealso:: errorMessage()
99+
.. seealso:: errorCount()
100+
:rtype: ExportError
94101
%End
95102

96-
QString errorMessage();
103+
QString errorMessage() const;
97104
%Docstring
98-
Retrieves error message
105+
Returns any error message encountered during the export.
106+
.. seealso:: errorCount()
107+
.. seealso:: errorCode()
99108
:rtype: str
100109
%End
101110

102111
int errorCount() const;
103112
%Docstring
113+
Returns the number of error messages encountered during the export.
114+
.. seealso:: errorMessage()
115+
.. seealso:: errorCode()
104116
:rtype: int
105117
%End
106118

@@ -109,19 +121,19 @@ Retrieves error message
109121
virtual bool addFeature( QgsFeature &feature );
110122

111123

112-
~QgsVectorLayerImport();
124+
~QgsVectorLayerExporter();
113125
%Docstring
114-
Close the new created layer
126+
Finalizes the export and closes the new created layer.
115127
%End
116128

117129
private:
118-
QgsVectorLayerImport( const QgsVectorLayerImport &rh );
130+
QgsVectorLayerExporter( const QgsVectorLayerExporter &rh );
119131
};
120132

121133
/************************************************************************
122134
* This file has been generated automatically from *
123135
* *
124-
* src/core/qgsvectorlayerimport.h *
136+
* src/core/qgsvectorlayerexporter.h *
125137
* *
126138
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
127139
************************************************************************/

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

python/plugins/db_manager/db_plugins/oracle/TODO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
modify field dialog. #13089
2424

2525
* Import Table does not work because of a problem in
26-
QgsVectorLayerImport. After the creation of the table, QGIS tries to
26+
QgsVectorLayerExporter. After the creation of the table, QGIS tries to
2727
open the layer but, as there is no geometries in it, QGIS can't
2828
determinate the geometry type of the layer and refuses to open
2929
it. Then, no data importation can occur. Must dig into
30-
src/core/qgsvectorlayerimport.cpp and into the provider code.
30+
src/core/qgsvectorlayerexporter.cpp and into the provider code.
3131
See #13096 .
3232

3333
# Future work

python/plugins/db_manager/dlg_export_vector.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox, QApplication
2828
from qgis.PyQt.QtGui import QCursor
2929

30-
from qgis.core import QgsVectorFileWriter, QgsVectorDataProvider, QgsCoordinateReferenceSystem, QgsVectorLayerImport, QgsSettings
30+
from qgis.core import (QgsVectorFileWriter,
31+
QgsVectorDataProvider,
32+
QgsCoordinateReferenceSystem,
33+
QgsVectorLayerExporter,
34+
QgsSettings)
3135

3236
from .ui.ui_DlgExportVector import Ui_DbManagerDlgExportVector as Ui_Dialog
3337

@@ -175,8 +179,8 @@ def accept(self):
175179
self.inLayer.setCrs(inCrs)
176180

177181
# do the export!
178-
ret, errMsg = QgsVectorLayerImport.importLayer(self.inLayer, uri, providerName, outCrs, False,
179-
False, options)
182+
ret, errMsg = QgsVectorLayerExporter.exportLayer(self.inLayer, uri, providerName, outCrs, False,
183+
False, options)
180184
except Exception as e:
181185
ret = -1
182186
errMsg = str(e)

python/plugins/db_manager/dlg_import_vector.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
from qgis.PyQt.QtWidgets import QDialog, QFileDialog, QMessageBox, QApplication
2929
from qgis.PyQt.QtGui import QCursor
3030

31-
from qgis.core import QgsDataSourceUri, QgsVectorLayer, QgsMapLayer, QgsProviderRegistry, QgsCoordinateReferenceSystem, QgsVectorLayerImport, QgsProject, QgsSettings
31+
from qgis.core import (QgsDataSourceUri,
32+
QgsVectorLayer,
33+
QgsMapLayer,
34+
QgsProviderRegistry,
35+
QgsCoordinateReferenceSystem,
36+
QgsVectorLayerExporter,
37+
QgsProject,
38+
QgsSettings)
3239
from qgis.gui import QgsMessageViewer
3340

3441
from .ui.ui_DlgImportVector import Ui_DbManagerDlgImportVector as Ui_Dialog
@@ -353,7 +360,7 @@ def accept(self):
353360
onlySelected = self.chkSelectedFeatures.isChecked()
354361

355362
# do the import!
356-
ret, errMsg = QgsVectorLayerImport.importLayer(self.inLayer, uri, providerName, outCrs, onlySelected, False, options)
363+
ret, errMsg = QgsVectorLayerExporter.exportLayer(self.inLayer, uri, providerName, outCrs, onlySelected, False, options)
357364
except Exception as e:
358365
ret = -1
359366
errMsg = str(e)

python/plugins/processing/algs/qgis/ImportIntoPostGIS.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
__revision__ = '$Format:%H$'
2727

28-
from qgis.core import (QgsVectorLayerImport,
28+
from qgis.core import (QgsVectorLayerExporter,
2929
QgsSettings,
3030
QgsApplication,
3131
QgsProcessingUtils)
@@ -164,7 +164,7 @@ def processAlgorithm(self, context, feedback):
164164
if encoding:
165165
layer.setProviderEncoding(encoding)
166166

167-
(ret, errMsg) = QgsVectorLayerImport.importLayer(
167+
(ret, errMsg) = QgsVectorLayerExporter.exportLayer(
168168
layer,
169169
uri.uri(),
170170
providerName,

python/plugins/processing/algs/qgis/ImportIntoSpatialite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
__revision__ = '$Format:%H$'
2727

2828
from qgis.core import (QgsDataSourceUri,
29-
QgsVectorLayerImport,
29+
QgsVectorLayerExporter,
3030
QgsApplication,
3131
QgsProcessingUtils)
3232

@@ -134,7 +134,7 @@ def processAlgorithm(self, context, feedback):
134134
if encoding:
135135
layer.setProviderEncoding(encoding)
136136

137-
(ret, errMsg) = QgsVectorLayerImport.importLayer(
137+
(ret, errMsg) = QgsVectorLayerExporter.exportLayer(
138138
layer,
139139
uri.uri(),
140140
providerName,

src/core/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ SET(QGIS_CORE_SRCS
270270
qgsvectorlayereditpassthrough.cpp
271271
qgsvectorlayereditutils.cpp
272272
qgsvectorlayerfeatureiterator.cpp
273-
qgsvectorlayerimport.cpp
273+
qgsvectorlayerexporter.cpp
274274
qgsvectorlayerjoinbuffer.cpp
275275
qgsvectorlayerlabeling.cpp
276276
qgsvectorlayerlabelprovider.cpp
@@ -819,7 +819,7 @@ SET(QGIS_CORE_HDRS
819819
qgsvectorlayerdiagramprovider.h
820820
qgsvectorlayereditutils.h
821821
qgsvectorlayerfeatureiterator.h
822-
qgsvectorlayerimport.h
822+
qgsvectorlayerexporter.h
823823
qgsvectorlayerjoininfo.h
824824
qgsvectorlayerlabelprovider.h
825825
qgsvectorlayerrenderer.h

src/core/processing/qgsprocessingutils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "qgsproject.h"
2020
#include "qgssettings.h"
2121
#include "qgsprocessingcontext.h"
22-
#include "qgsvectorlayerimport.h"
22+
#include "qgsvectorlayerexporter.h"
2323
#include "qgsvectorfilewriter.h"
2424
#include "qgsmemoryproviderutils.h"
2525

@@ -367,8 +367,8 @@ QgsFeatureSink *QgsProcessingUtils::createFeatureSink( QString &destination, con
367367
{
368368
//create empty layer
369369
{
370-
QgsVectorLayerImport import( uri, providerKey, fields, geometryType, crs, false, &options );
371-
if ( import.hasError() )
370+
QgsVectorLayerExporter import( uri, providerKey, fields, geometryType, crs, false, &options );
371+
if ( import.errorCode() )
372372
return nullptr;
373373
}
374374

0 commit comments

Comments
 (0)