[afs] Implemented decodeUri for AFS provider

Allows retrieval of the web URL for an AFS layer
This commit is contained in:
Nyall Dawson 2018-11-07 13:37:07 +10:00
parent 94896703dc
commit 4b32e7cc78
4 changed files with 27 additions and 9 deletions

View File

@ -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::

View File

@ -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 );

View File

@ -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;
}

View File

@ -28,7 +28,8 @@ from qgis.core import (NULL,
QgsApplication,
QgsSettings,
QgsRectangle,
QgsCategorizedSymbolRenderer
QgsCategorizedSymbolRenderer,
QgsProviderRegistry
)
from qgis.testing import (start_app,
unittest
@ -417,6 +418,14 @@ class TestPyQgsAFSProvider(unittest.TestCase, ProviderTestCase):
"""
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 """