Skip to content

Commit

Permalink
Merge pull request #38395 from qgis-bot/backport-38348-to-release-3_10
Browse files Browse the repository at this point in the history
[Backport release-3_10] Fix delimitedtext in virtual layers
  • Loading branch information
m-kuhn committed Sep 12, 2020
2 parents 1c72a69 + fa16bdd commit 4a6532c
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1924,8 +1924,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( ":" ) ) ;
}
}
Expand Down Expand Up @@ -1998,7 +2010,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( ":" ) ) ;
}
Expand Down

0 comments on commit 4a6532c

Please sign in to comment.