mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-13 00:03:09 -04:00
Don't report a postgis import was successful when the user cancels
it mid-way through
This commit is contained in:
parent
89815646fb
commit
7fb9b68cfe
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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" ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user