Skip to content
Permalink
Browse files

Don't report a postgis import was successful when the user cancels

it mid-way through
  • Loading branch information
nyalldawson committed Jan 31, 2016
1 parent 8981564 commit 7fb9b68cfe8d6aaf797f136d75a2372eb4746d47
@@ -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" ) );

0 comments on commit 7fb9b68

Please sign in to comment.
You can’t perform that action at this time.