Skip to content

Commit

Permalink
[wms] When decoding uri strings, insure local files are mapped to a '…
Browse files Browse the repository at this point in the history
…path' key
  • Loading branch information
nirvn committed Dec 20, 2020
1 parent 7719668 commit 869e989
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -4644,7 +4644,22 @@ QVariantMap QgsWmsProviderMetadata::decodeUri( const QString &uri ) const
QVariantMap decoded;
for ( const auto &item : constItems )
{
decoded[ item.first ] = item.second;
if ( item.first == QStringLiteral( "url" ) )
{
const QUrl url( item.second );
if ( url.isLocalFile() )
{
decoded[ QStringLiteral( "path" ) ] = url.toLocalFile();
}
else
{
decoded[ item.first ] = item.second;
}
}
else
{
decoded[ item.first ] = item.second;
}
}
return decoded;
}
Expand All @@ -4655,7 +4670,14 @@ QString QgsWmsProviderMetadata::encodeUri( const QVariantMap &parts ) const
QList<QPair<QString, QString> > items;
for ( auto it = parts.constBegin(); it != parts.constEnd(); ++it )
{
items.push_back( {it.key(), it.value().toString() } );
if ( it.key() == QStringLiteral( "path" ) )
{
items.push_back( { QStringLiteral( "url" ), QUrl::fromLocalFile( it.value().toString() ).toString() } );
}
else
{
items.push_back( { it.key(), it.value().toString() } );
}
}
query.setQueryItems( items );
return query.toString();
Expand Down
11 changes: 11 additions & 0 deletions tests/src/providers/testqgswmsprovider.cpp
Expand Up @@ -167,6 +167,17 @@ class TestQgsWmsProvider: public QObject

}

void providerUriLocalFile()
{
QString uriString = QStringLiteral( "url=file:///my/local/tiles.mbtiles&type=mbtiles" );
QVariantMap parts = QgsProviderRegistry::instance()->decodeUri( QStringLiteral( "wms" ), uriString );
QVariantMap expectedParts { { QString( "type" ), QVariant( "mbtiles" ) },
{ QString( "path" ), QVariant( "/my/local/tiles.mbtiles" ) } };
QCOMPARE( parts, expectedParts );

QString encodedUri = QgsProviderRegistry::instance()->encodeUri( QStringLiteral( "wms" ), parts );
QCOMPARE( encodedUri, uriString );
}

bool imageCheck( const QString &testType, QgsMapLayer *layer, const QgsRectangle &extent )
{
Expand Down

0 comments on commit 869e989

Please sign in to comment.