Skip to content
Permalink
Browse files

Fix delimitedtext in virtual layers

  • Loading branch information
github-actions committed Aug 20, 2020
1 parent b05aa10 commit f5bb681fab420b7f3e180385d94c8f4e4dde4e1c
Showing with 36 additions and 3 deletions.
  1. +36 −3 src/core/qgsvectorlayer.cpp
@@ -1947,8 +1947,20 @@ QString QgsVectorLayer::encodedSource( const QString &source, const QgsReadWrite
// syntax: provider:url_encoded_source_URI(:name(:encoding)?)?
theURIParts = value.split( ':' );
theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() );
theURIParts[1] = context.pathResolver().writePath( theURIParts[1] );
theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] );

if ( theURIParts[0] == QLatin1String( "delimitedtext" ) )
{
QUrl urlSource = QUrl( theURIParts[1] );
QUrl urlDest = QUrl::fromLocalFile( context.pathResolver().writePath( urlSource.toLocalFile() ) );
urlDest.setQuery( urlSource.query() );
theURIParts[1] = QUrl::toPercentEncoding( urlDest.toString(), QByteArray( "" ), QByteArray( ":" ) );
}
else
{
theURIParts[1] = context.pathResolver().writePath( theURIParts[1] );
theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] );
}

queryItems[i].second = theURIParts.join( QStringLiteral( ":" ) ) ;
}
}
@@ -2021,7 +2033,28 @@ QString QgsVectorLayer::decodedSource( const QString &source, const QString &pro
// syntax: provider:url_encoded_source_URI(:name(:encoding)?)?
theURIParts = value.split( ':' );
theURIParts[1] = QUrl::fromPercentEncoding( theURIParts[1].toUtf8() );
theURIParts[1] = context.pathResolver().readPath( theURIParts[1] );

if ( theURIParts[0] == QStringLiteral( "delimitedtext" ) )
{
QUrl urlSource = QUrl( theURIParts[1] );

if ( !theURIParts[1].startsWith( QLatin1String( "file:" ) ) )
{
QUrl file = QUrl::fromLocalFile( theURIParts[1].left( theURIParts[1].indexOf( '?' ) ) );
urlSource.setScheme( QStringLiteral( "file" ) );
urlSource.setPath( file.path() );
}

QUrl urlDest = QUrl::fromLocalFile( context.pathResolver().readPath( urlSource.toLocalFile() ) );
urlDest.setQuery( urlSource.query() );

theURIParts[1] = urlDest.toString();
}
else
{
theURIParts[1] = context.pathResolver().readPath( theURIParts[1] );
}

theURIParts[1] = QUrl::toPercentEncoding( theURIParts[1] );
queryItems[i].second = theURIParts.join( QStringLiteral( ":" ) ) ;
}

0 comments on commit f5bb681

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