Skip to content

Commit 6be9f14

Browse files
committedJan 27, 2019
Better UX when loading remote layers in the main thread
"loading ..." message and busy cursor
1 parent 65bf2ce commit 6be9f14

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4667,13 +4667,25 @@ bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QStrin
46674667

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

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

4674+
// create the layer
46724675
QgsVectorLayer::LayerOptions options;
46734676
options.loadDefaultStyle = false;
4677+
if ( isVsiCurl || isRemoteUrl )
4678+
{
4679+
visibleMessageBar()->pushInfo( tr( "Remote layer" ), tr( "loading %1, please wait …" ).arg( src ) );
4680+
QApplication::setOverrideCursor( Qt::WaitCursor );
4681+
qApp->processEvents();
4682+
}
46744683
QgsVectorLayer *layer = new QgsVectorLayer( src, baseName, QStringLiteral( "ogr" ), options );
46754684
Q_CHECK_PTR( layer );
4676-
4685+
if ( isVsiCurl || isRemoteUrl )
4686+
{
4687+
QApplication::restoreOverrideCursor( );
4688+
}
46774689
if ( ! layer )
46784690
{
46794691
freezeCanvases( false );
@@ -4723,9 +4735,9 @@ bool QgisApp::addVectorLayers( const QStringList &layerQStringList, const QStrin
47234735
delete layer;
47244736
QString msg = tr( "%1 is not a valid or recognized data source." ).arg( src );
47254737
// If the failed layer was a vsicurl type, give the user a chance to try the normal download.
4726-
if ( src.startsWith( QLatin1String( "/vsicurl" ), Qt::CaseInsensitive ) &&
4738+
if ( isVsiCurl &&
47274739
QMessageBox::question( this, tr( "Invalid Data Source" ),
4728-
tr( "The \"protocol\" source type failed, do you want to try the \"file\" type?" ) ) == QMessageBox::Yes )
4740+
tr( "Download with \"Protocol\" source type has failed, do you want to try the \"File\" source type?" ) ) == QMessageBox::Yes )
47294741
{
47304742
return addVectorLayers( QStringList() << src.replace( QLatin1String( "/vsicurl/" ), " " ), enc, dataSourceType );
47314743
}

0 commit comments

Comments
 (0)
Please sign in to comment.