diff --git a/python/core/qgsvectorlayerimport.sip b/python/core/qgsvectorlayerimport.sip index 0142549e42d..8ff090f1230 100644 --- a/python/core/qgsvectorlayerimport.sip +++ b/python/core/qgsvectorlayerimport.sip @@ -3,9 +3,6 @@ There are two possibilities how to use this class: 1. static call to QgsVectorFileWriter::writeAsShapefile(...) which saves the whole vector layer 2. create an instance of the class and issue calls to addFeature(...) - - Currently supports only writing to shapefiles, but shouldn't be a problem to add capability - to support other OGR-writable formats. */ class QgsVectorLayerImport { @@ -30,7 +27,8 @@ class QProgressDialog; ErrInvalidLayer, ErrInvalidProvider, ErrProviderUnsupportedFeature, - ErrConnectionFailed + ErrConnectionFailed, + ErrUserCancelled, /*!< User cancelled the import*/ }; /** Write contents of vector layer to a different datasource */ diff --git a/src/core/qgsvectorlayerimport.cpp b/src/core/qgsvectorlayerimport.cpp index ac4513e1efd..f053488d660 100644 --- a/src/core/qgsvectorlayerimport.cpp +++ b/src/core/qgsvectorlayerimport.cpp @@ -333,11 +333,14 @@ QgsVectorLayerImport::importLayer( QgsVectorLayer* layer, progress->setRange( 0, layer->featureCount() ); } + bool cancelled = false; + // write all features while ( fit.nextFeature( fet ) ) { if ( progress && progress->wasCanceled() ) { + cancelled = true; if ( errorMessage ) { *errorMessage += '\n' + QObject::tr( "Import was canceled at %1 of %2" ).arg( progress->value() ).arg( progress->maximum() ); @@ -436,5 +439,10 @@ QgsVectorLayerImport::importLayer( QgsVectorLayer* layer, } } - return errors == 0 ? NoError : ErrFeatureWriteFailed; + if ( cancelled ) + return ErrUserCancelled; + else if ( errors > 0 ) + return ErrFeatureWriteFailed; + + return NoError; } diff --git a/src/core/qgsvectorlayerimport.h b/src/core/qgsvectorlayerimport.h index 22d596ab2c7..88f73dd0724 100644 --- a/src/core/qgsvectorlayerimport.h +++ b/src/core/qgsvectorlayerimport.h @@ -29,9 +29,6 @@ class QProgressDialog; There are two possibilities how to use this class: 1. static call to QgsVectorFileWriter::writeAsShapefile(...) which saves the whole vector layer 2. create an instance of the class and issue calls to addFeature(...) - - Currently supports only writing to shapefiles, but shouldn't be a problem to add capability - to support other OGR-writable formats. */ class CORE_EXPORT QgsVectorLayerImport { @@ -50,7 +47,8 @@ class CORE_EXPORT QgsVectorLayerImport ErrInvalidLayer, ErrInvalidProvider, ErrProviderUnsupportedFeature, - ErrConnectionFailed + ErrConnectionFailed, + ErrUserCancelled, /*!< User cancelled the import*/ }; /** Write contents of vector layer to a different datasource */ diff --git a/src/providers/postgres/qgspostgresdataitems.cpp b/src/providers/postgres/qgspostgresdataitems.cpp index cfa96c1a49e..faf9db97ea0 100644 --- a/src/providers/postgres/qgspostgresdataitems.cpp +++ b/src/providers/postgres/qgspostgresdataitems.cpp @@ -207,6 +207,8 @@ bool QgsPGConnectionItem::handleDrop( const QMimeData * data, QString toSchema ) QStringList importResults; bool hasError = false; + bool cancelled = false; + QgsMimeDataUtils::UriList lst = QgsMimeDataUtils::decodeUriList( data ); Q_FOREACH ( const QgsMimeDataUtils::Uri& u, lst ) { @@ -235,6 +237,8 @@ bool QgsPGConnectionItem::handleDrop( const QMimeData * data, QString toSchema ) err = QgsVectorLayerImport::importLayer( srcLayer, uri.uri( false ), "postgres", &srcLayer->crs(), false, &importError, false, nullptr, progress ); if ( err == QgsVectorLayerImport::NoError ) importResults.append( tr( "%1: OK!" ).arg( u.name ) ); + else if ( err == QgsVectorLayerImport::ErrUserCancelled ) + cancelled = true; else { importResults.append( QString( "%1: %2" ).arg( u.name, importError ) ); @@ -254,7 +258,12 @@ bool QgsPGConnectionItem::handleDrop( const QMimeData * data, QString toSchema ) qApp->restoreOverrideCursor(); - if ( hasError ) + if ( cancelled ) + { + QMessageBox::information( nullptr, tr( "Import to PostGIS database" ), tr( "Import cancelled." ) ); + refresh(); + } + else if ( hasError ) { QgsMessageOutput *output = QgsMessageOutput::createMessageOutput(); output->setTitle( tr( "Import to PostGIS database" ) );