Skip to content

Commit

Permalink
[afs] Implemented decodeUri for AFS provider
Browse files Browse the repository at this point in the history
Allows retrieval of the web URL for an AFS layer
  • Loading branch information
nyalldawson committed Nov 7, 2018
1 parent 9489670 commit 4b32e7c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions python/core/auto_generated/qgsproviderregistry.sip.in
Expand Up @@ -96,12 +96,12 @@ Returns the provider capabilities

QVariantMap decodeUri( const QString &providerKey, const QString &uri );
%Docstring
Returns the components (e.g. file path, layer name) of a provider uri
Breaks a provider data source URI into its component paths (e.g. file path, layer name).

:param providerKey: identifier of the provider
:param uri: uri string

:return: map containing components
:return: map containing components. Standard components include "path", "layerName", "url".

.. note::

Expand Down
12 changes: 6 additions & 6 deletions src/core/qgsproviderregistry.h
Expand Up @@ -108,12 +108,12 @@ class CORE_EXPORT QgsProviderRegistry
int providerCapabilities( const QString &providerKey ) const;

/**
* Returns the components (e.g. file path, layer name) of a provider uri
\param providerKey identifier of the provider
\param uri uri string
\returns map containing components
\note this function may not be supported by all providers, an empty map will be returned in such case
\since QGIS 3.4
* Breaks a provider data source URI into its component paths (e.g. file path, layer name).
* \param providerKey identifier of the provider
* \param uri uri string
* \returns map containing components. Standard components include "path", "layerName", "url".
* \note this function may not be supported by all providers, an empty map will be returned in such case
* \since QGIS 3.4
*/
QVariantMap decodeUri( const QString &providerKey, const QString &uri );

Expand Down
9 changes: 9 additions & 0 deletions src/providers/arcgisrest/qgsafsproviderextern.cpp
Expand Up @@ -59,3 +59,12 @@ QGISEXTERN int dataCapabilities()
{
return QgsDataProvider::Net;
}

QGISEXTERN QVariantMap decodeUri( const QString &uri )
{
QgsDataSourceUri dsUri = QgsDataSourceUri( uri );

QVariantMap components;
components.insert( QStringLiteral( "url" ), dsUri.param( QStringLiteral( "url" ) ) );
return components;
}
11 changes: 10 additions & 1 deletion tests/src/python/test_provider_afs.py
Expand Up @@ -28,7 +28,8 @@
QgsApplication,
QgsSettings,
QgsRectangle,
QgsCategorizedSymbolRenderer
QgsCategorizedSymbolRenderer,
QgsProviderRegistry
)
from qgis.testing import (start_app,
unittest
Expand Down Expand Up @@ -417,6 +418,14 @@ def testGetFeaturesNoGeometry(self):
"""
pass

def testDecodeUri(self):
"""
Test decoding an AFS uri
"""
uri = self.vl.source()
parts = QgsProviderRegistry.instance().decodeUri(self.vl.dataProvider().name(), uri)
self.assertEqual(parts, {'url': 'http://' + self.basetestpath + '/fake_qgis_http_endpoint'})

def testObjectIdDifferentName(self):
""" Test that object id fields not named OBJECTID work correctly """

Expand Down

0 comments on commit 4b32e7c

Please sign in to comment.