QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsvectortileprovidermetadata.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsvectortileprovidermetadata.cpp
3  --------------------------------------
4  Date : March 2020
5  Copyright : (C) 2020 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
17 
19 #include "qgsvectortiledataitems.h"
20 
22 
23 #define PROVIDER_KEY QStringLiteral( "vectortile" )
24 #define PROVIDER_DESCRIPTION QStringLiteral( "Vector tile provider" )
25 
26 QgsVectorTileProviderMetadata::QgsVectorTileProviderMetadata()
27  : QgsProviderMetadata( PROVIDER_KEY, PROVIDER_DESCRIPTION )
28 {
29 }
30 
31 QList<QgsDataItemProvider *> QgsVectorTileProviderMetadata::dataItemProviders() const
32 {
33  QList< QgsDataItemProvider * > providers;
34  providers << new QgsVectorTileDataItemProvider;
35  return providers;
36 }
37 
38 QMap<QString, QgsAbstractProviderConnection *> QgsVectorTileProviderMetadata::connections( bool cached )
39 {
40  return connectionsProtected<QgsVectorTileProviderConnection, QgsVectorTileProviderConnection>( cached );
41 }
42 
43 QgsAbstractProviderConnection *QgsVectorTileProviderMetadata::createConnection( const QString &name )
44 {
45  return new QgsVectorTileProviderConnection( name );
46 }
47 
48 void QgsVectorTileProviderMetadata::deleteConnection( const QString &name )
49 {
50  deleteConnectionProtected<QgsVectorTileProviderConnection>( name );
51 }
52 
53 void QgsVectorTileProviderMetadata::saveConnection( const QgsAbstractProviderConnection *connection, const QString &name )
54 {
55  saveConnectionProtected( connection, name );
56 }
57 
58 QgsProviderMetadata::ProviderCapabilities QgsVectorTileProviderMetadata::providerCapabilities() const
59 {
60  return FileBasedUris;
61 }
62 
63 QVariantMap QgsVectorTileProviderMetadata::decodeUri( const QString &uri ) const
64 {
65  QgsDataSourceUri dsUri;
66  dsUri.setEncodedUri( uri );
67 
68  QVariantMap uriComponents;
69  uriComponents.insert( QStringLiteral( "type" ), dsUri.param( QStringLiteral( "type" ) ) );
70  if ( dsUri.hasParam( QStringLiteral( "serviceType" ) ) )
71  uriComponents.insert( QStringLiteral( "serviceType" ), dsUri.param( QStringLiteral( "serviceType" ) ) );
72 
73  if ( uriComponents[ QStringLiteral( "type" ) ] == QLatin1String( "mbtiles" ) ||
74  ( uriComponents[ QStringLiteral( "type" ) ] == QLatin1String( "xyz" ) &&
75  !dsUri.param( QStringLiteral( "url" ) ).startsWith( QLatin1String( "http" ) ) ) )
76  {
77  uriComponents.insert( QStringLiteral( "path" ), dsUri.param( QStringLiteral( "url" ) ) );
78  }
79  else
80  {
81  uriComponents.insert( QStringLiteral( "url" ), dsUri.param( QStringLiteral( "url" ) ) );
82  }
83 
84  if ( dsUri.hasParam( QStringLiteral( "zmin" ) ) )
85  uriComponents.insert( QStringLiteral( "zmin" ), dsUri.param( QStringLiteral( "zmin" ) ) );
86  if ( dsUri.hasParam( QStringLiteral( "zmax" ) ) )
87  uriComponents.insert( QStringLiteral( "zmax" ), dsUri.param( QStringLiteral( "zmax" ) ) );
88 
89  if ( dsUri.hasParam( QStringLiteral( "referer" ) ) )
90  uriComponents.insert( QStringLiteral( "referer" ), dsUri.param( QStringLiteral( "referer" ) ) );
91  if ( dsUri.hasParam( QStringLiteral( "styleUrl" ) ) )
92  uriComponents.insert( QStringLiteral( "styleUrl" ), dsUri.param( QStringLiteral( "styleUrl" ) ) );
93 
94  const QString authcfg = dsUri.authConfigId();
95  if ( !authcfg.isEmpty() )
96  uriComponents.insert( QStringLiteral( "authcfg" ), authcfg );
97 
98  return uriComponents;
99 }
100 
101 QString QgsVectorTileProviderMetadata::encodeUri( const QVariantMap &parts ) const
102 {
103  QgsDataSourceUri dsUri;
104  dsUri.setParam( QStringLiteral( "type" ), parts.value( QStringLiteral( "type" ) ).toString() );
105  if ( parts.contains( QStringLiteral( "serviceType" ) ) )
106  dsUri.setParam( QStringLiteral( "serviceType" ), parts[ QStringLiteral( "serviceType" ) ].toString() );
107  dsUri.setParam( QStringLiteral( "url" ), parts.value( parts.contains( QStringLiteral( "path" ) ) ? QStringLiteral( "path" ) : QStringLiteral( "url" ) ).toString() );
108 
109  if ( parts.contains( QStringLiteral( "zmin" ) ) )
110  dsUri.setParam( QStringLiteral( "zmin" ), parts[ QStringLiteral( "zmin" ) ].toString() );
111  if ( parts.contains( QStringLiteral( "zmax" ) ) )
112  dsUri.setParam( QStringLiteral( "zmax" ), parts[ QStringLiteral( "zmax" ) ].toString() );
113 
114  if ( parts.contains( QStringLiteral( "referer" ) ) )
115  dsUri.setParam( QStringLiteral( "referer" ), parts[ QStringLiteral( "referer" ) ].toString() );
116  if ( parts.contains( QStringLiteral( "styleUrl" ) ) )
117  dsUri.setParam( QStringLiteral( "styleUrl" ), parts[ QStringLiteral( "styleUrl" ) ].toString() );
118 
119  if ( parts.contains( QStringLiteral( "authcfg" ) ) )
120  dsUri.setAuthConfigId( parts[ QStringLiteral( "authcfg" ) ].toString() );
121 
122  return dsUri.encodedUri();
123 }
124 
The QgsAbstractProviderConnection provides an interface for data provider connections.
Class for storing the component parts of a RDBMS data source URI (e.g.
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
bool hasParam(const QString &key) const
Returns true if a parameter with the specified key exists.
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
void setAuthConfigId(const QString &authcfg)
Sets the authentication configuration ID for the URI.
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
QString authConfigId() const
Returns any associated authentication configuration ID stored in the URI.
Holds data provider key, description, and associated shared library file or function pointer informat...