Skip to content

Commit 4b32e7c

Browse files
committedNov 7, 2018
[afs] Implemented decodeUri for AFS provider
Allows retrieval of the web URL for an AFS layer
1 parent 9489670 commit 4b32e7c

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed
 

‎python/core/auto_generated/qgsproviderregistry.sip.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ Returns the provider capabilities
9696

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

101101
:param providerKey: identifier of the provider
102102
:param uri: uri string
103103

104-
:return: map containing components
104+
:return: map containing components. Standard components include "path", "layerName", "url".
105105

106106
.. note::
107107

‎src/core/qgsproviderregistry.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ class CORE_EXPORT QgsProviderRegistry
108108
int providerCapabilities( const QString &providerKey ) const;
109109

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

‎src/providers/arcgisrest/qgsafsproviderextern.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,12 @@ QGISEXTERN int dataCapabilities()
5959
{
6060
return QgsDataProvider::Net;
6161
}
62+
63+
QGISEXTERN QVariantMap decodeUri( const QString &uri )
64+
{
65+
QgsDataSourceUri dsUri = QgsDataSourceUri( uri );
66+
67+
QVariantMap components;
68+
components.insert( QStringLiteral( "url" ), dsUri.param( QStringLiteral( "url" ) ) );
69+
return components;
70+
}

‎tests/src/python/test_provider_afs.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
QgsApplication,
2929
QgsSettings,
3030
QgsRectangle,
31-
QgsCategorizedSymbolRenderer
31+
QgsCategorizedSymbolRenderer,
32+
QgsProviderRegistry
3233
)
3334
from qgis.testing import (start_app,
3435
unittest
@@ -417,6 +418,14 @@ def testGetFeaturesNoGeometry(self):
417418
"""
418419
pass
419420

421+
def testDecodeUri(self):
422+
"""
423+
Test decoding an AFS uri
424+
"""
425+
uri = self.vl.source()
426+
parts = QgsProviderRegistry.instance().decodeUri(self.vl.dataProvider().name(), uri)
427+
self.assertEqual(parts, {'url': 'http://' + self.basetestpath + '/fake_qgis_http_endpoint'})
428+
420429
def testObjectIdDifferentName(self):
421430
""" Test that object id fields not named OBJECTID work correctly """
422431

0 commit comments

Comments
 (0)
Please sign in to comment.