Skip to content
Permalink
Browse files

Better UX when loading remote layers in the main thread

"loading ..." message and busy cursor
  • Loading branch information
elpaso committed Jan 27, 2019
1 parent 65bf2ce commit 6be9f14f0f1dd1a7c09ffbeea48f625ea4d03982
Showing with 16 additions and 4 deletions.
  1. +16 −4 src/app/qgisapp.cpp
@@ -4667,13 +4667,25 @@ bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QStrin

QgsDebugMsgLevel( "completeBaseName: " + baseName, 2 );

// create the layer
const bool isVsiCurl { src.startsWith( QLatin1String( "/vsicurl", Qt::CaseInsensitive ) ) };
const auto scheme { QUrl( src ).scheme() };
const bool isRemoteUrl { scheme.startsWith( QStringLiteral( "http" ) ) || scheme == QStringLiteral( "ftp" ) };

// create the layer
QgsVectorLayer::LayerOptions options;
options.loadDefaultStyle = false;
if ( isVsiCurl || isRemoteUrl )
{
visibleMessageBar()->pushInfo( tr( "Remote layer" ), tr( "loading %1, please wait …" ).arg( src ) );
QApplication::setOverrideCursor( Qt::WaitCursor );
qApp->processEvents();
}
QgsVectorLayer *layer = new QgsVectorLayer( src, baseName, QStringLiteral( "ogr" ), options );
Q_CHECK_PTR( layer );

if ( isVsiCurl || isRemoteUrl )
{
QApplication::restoreOverrideCursor( );
}
if ( ! layer )
{
freezeCanvases( false );
@@ -4723,9 +4735,9 @@ bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QStrin
delete layer;
QString msg = tr( "%1 is not a valid or recognized data source." ).arg( src );
// If the failed layer was a vsicurl type, give the user a chance to try the normal download.
if ( src.startsWith( QLatin1String( "/vsicurl" ), Qt::CaseInsensitive ) &&
if ( isVsiCurl &&
QMessageBox::question( this, tr( "Invalid Data Source" ),
tr( "The \"protocol\" source type failed, do you want to try the \"file\" type?" ) ) == QMessageBox::Yes )
tr( "Download with \"Protocol\" source type has failed, do you want to try the \"File\" source type?" ) ) == QMessageBox::Yes )
{
return addVectorLayers( QStringList() << src.replace( QLatin1String( "/vsicurl/" ), " " ), enc, dataSourceType );
}

0 comments on commit 6be9f14

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