Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 6be9f14
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/app/qgisapp.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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 );
}
Expand Down

0 comments on commit 6be9f14

Please sign in to comment.