Skip to content
Permalink
Browse files

Show progress bars when importing to mssql/spatialite sources

(previously progress was only shown when importing to postgis)
  • Loading branch information
nyalldawson committed Jan 31, 2016
1 parent 7fb9b68 commit 8dafa6335fc6c235decdf971d8447595e96ac9ce
Showing with 37 additions and 4 deletions.
  1. +18 −2 src/providers/mssql/qgsmssqldataitems.cpp
  2. +19 −2 src/providers/spatialite/qgsspatialitedataitems.cpp
@@ -31,6 +31,7 @@
#include <QMessageBox>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlError>
#include <QProgressDialog>

// ---------------------------------------------------------------------------
QgsMssqlConnectionItem::QgsMssqlConnectionItem( QgsDataItem* parent, QString name, QString path )
@@ -350,8 +351,15 @@ bool QgsMssqlConnectionItem::handleDrop( const QMimeData* data, const QString& t
// TODO: probably should show a GUI with settings etc
qApp->setOverrideCursor( Qt::WaitCursor );

QProgressDialog *progress = new QProgressDialog( tr( "Copying features..." ), tr( "Abort" ), 0, 0, nullptr );
progress->setWindowTitle( tr( "Import layer" ) );
progress->setWindowModality( Qt::WindowModal );
progress->show();

QStringList importResults;
bool hasError = false;
bool cancelled = false;

QgsMimeDataUtils::UriList lst = QgsMimeDataUtils::decodeUriList( data );
Q_FOREACH ( const QgsMimeDataUtils::Uri& u, lst )
{
@@ -383,9 +391,11 @@ bool QgsMssqlConnectionItem::handleDrop( const QMimeData* data, const QString& t

QgsVectorLayerImport::ImportError err;
QString importError;
err = QgsVectorLayerImport::importLayer( srcLayer, uri, "mssql", &srcLayer->crs(), false, &importError );
err = QgsVectorLayerImport::importLayer( srcLayer, uri, "mssql", &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 ) );
@@ -401,9 +411,15 @@ bool QgsMssqlConnectionItem::handleDrop( const QMimeData* data, const QString& t
delete srcLayer;
}

delete progress;
qApp->restoreOverrideCursor();

if ( hasError )
if ( cancelled )
{
QMessageBox::information( nullptr, tr( "Import to MSSQL database" ), tr( "Import cancelled." ) );
refresh();
}
else if ( hasError )
{
QMessageBox::warning( nullptr, tr( "Import to MSSQL database" ), tr( "Failed to import some layers!\n\n" ) + importResults.join( "\n" ) );
}
@@ -26,6 +26,7 @@
#include <QAction>
#include <QMessageBox>
#include <QSettings>
#include <QProgressDialog>

QGISEXTERN bool deleteLayer( const QString& dbPath, const QString& tableName, QString& errCause );

@@ -204,8 +205,15 @@ bool QgsSLConnectionItem::handleDrop( const QMimeData * data, Qt::DropAction )

qApp->setOverrideCursor( Qt::WaitCursor );

QProgressDialog *progress = new QProgressDialog( tr( "Copying features..." ), tr( "Abort" ), 0, 0, nullptr );
progress->setWindowTitle( tr( "Import layer" ) );
progress->setWindowModality( Qt::WindowModal );
progress->show();

QStringList importResults;
bool hasError = false;
bool cancelled = false;

QgsMimeDataUtils::UriList lst = QgsMimeDataUtils::decodeUriList( data );
Q_FOREACH ( const QgsMimeDataUtils::Uri& u, lst )
{
@@ -225,9 +233,11 @@ bool QgsSLConnectionItem::handleDrop( const QMimeData * data, Qt::DropAction )
QgsDebugMsg( "URI " + destUri.uri() );
QgsVectorLayerImport::ImportError err;
QString importError;
err = QgsVectorLayerImport::importLayer( srcLayer, destUri.uri(), "spatialite", &srcLayer->crs(), false, &importError );
err = QgsVectorLayerImport::importLayer( srcLayer, destUri.uri(), "spatialite", &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 ) );
@@ -243,9 +253,16 @@ bool QgsSLConnectionItem::handleDrop( const QMimeData * data, Qt::DropAction )
delete srcLayer;
}

delete progress;

qApp->restoreOverrideCursor();

if ( hasError )
if ( cancelled )
{
QMessageBox::information( nullptr, tr( "Import to SpatiaLite database" ), tr( "Import cancelled." ) );
refresh();
}
else if ( hasError )
{
QgsMessageOutput *output = QgsMessageOutput::createMessageOutput();
output->setTitle( tr( "Import to SpatiaLite database" ) );

0 comments on commit 8dafa63

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