QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgsapplication.h"
21 
23 
24 #define PROVIDER_KEY QStringLiteral( "vectortile" )
25 #define PROVIDER_DESCRIPTION QStringLiteral( "Vector tile provider" )
26 
27 QgsVectorTileProviderMetadata::QgsVectorTileProviderMetadata()
28  : QgsProviderMetadata( PROVIDER_KEY, PROVIDER_DESCRIPTION )
29 {
30 }
31 
32 QIcon QgsVectorTileProviderMetadata::icon() const
33 {
34  return QgsApplication::getThemeIcon( QStringLiteral( "mIconVectorTileLayer.svg" ) );
35 }
36 
37 QList<QgsDataItemProvider *> QgsVectorTileProviderMetadata::dataItemProviders() const
38 {
39  QList< QgsDataItemProvider * > providers;
40  providers << new QgsVectorTileDataItemProvider;
41  return providers;
42 }
43 
44 QMap<QString, QgsAbstractProviderConnection *> QgsVectorTileProviderMetadata::connections( bool cached )
45 {
46  return connectionsProtected<QgsVectorTileProviderConnection, QgsVectorTileProviderConnection>( cached );
47 }
48 
49 QgsAbstractProviderConnection *QgsVectorTileProviderMetadata::createConnection( const QString &name )
50 {
51  return new QgsVectorTileProviderConnection( name );
52 }
53 
54 void QgsVectorTileProviderMetadata::deleteConnection( const QString &name )
55 {
56  deleteConnectionProtected<QgsVectorTileProviderConnection>( name );
57 }
58 
59 void QgsVectorTileProviderMetadata::saveConnection( const QgsAbstractProviderConnection *connection, const QString &name )
60 {
61  saveConnectionProtected( connection, name );
62 }
63 
64 QgsProviderMetadata::ProviderCapabilities QgsVectorTileProviderMetadata::providerCapabilities() const
65 {
66  return FileBasedUris;
67 }
68 
69 QVariantMap QgsVectorTileProviderMetadata::decodeUri( const QString &uri ) const
70 {
71  QgsDataSourceUri dsUri;
72  dsUri.setEncodedUri( uri );
73 
74  QVariantMap uriComponents;
75  uriComponents.insert( QStringLiteral( "type" ), dsUri.param( QStringLiteral( "type" ) ) );
76  if ( dsUri.hasParam( QStringLiteral( "serviceType" ) ) )
77  uriComponents.insert( QStringLiteral( "serviceType" ), dsUri.param( QStringLiteral( "serviceType" ) ) );
78 
79  if ( uriComponents[ QStringLiteral( "type" ) ] == QLatin1String( "mbtiles" ) ||
80  ( uriComponents[ QStringLiteral( "type" ) ] == QLatin1String( "xyz" ) &&
81  !dsUri.param( QStringLiteral( "url" ) ).startsWith( QLatin1String( "http" ) ) ) )
82  {
83  uriComponents.insert( QStringLiteral( "path" ), dsUri.param( QStringLiteral( "url" ) ) );
84  }
85  else
86  {
87  uriComponents.insert( QStringLiteral( "url" ), dsUri.param( QStringLiteral( "url" ) ) );
88  }
89 
90  if ( dsUri.hasParam( QStringLiteral( "zmin" ) ) )
91  uriComponents.insert( QStringLiteral( "zmin" ), dsUri.param( QStringLiteral( "zmin" ) ) );
92  if ( dsUri.hasParam( QStringLiteral( "zmax" ) ) )
93  uriComponents.insert( QStringLiteral( "zmax" ), dsUri.param( QStringLiteral( "zmax" ) ) );
94 
95  dsUri.httpHeaders().updateMap( uriComponents );
96 
97  if ( dsUri.hasParam( QStringLiteral( "styleUrl" ) ) )
98  uriComponents.insert( QStringLiteral( "styleUrl" ), dsUri.param( QStringLiteral( "styleUrl" ) ) );
99 
100  const QString authcfg = dsUri.authConfigId();
101  if ( !authcfg.isEmpty() )
102  uriComponents.insert( QStringLiteral( "authcfg" ), authcfg );
103 
104  return uriComponents;
105 }
106 
107 QString QgsVectorTileProviderMetadata::encodeUri( const QVariantMap &parts ) const
108 {
109  QgsDataSourceUri dsUri;
110  dsUri.setParam( QStringLiteral( "type" ), parts.value( QStringLiteral( "type" ) ).toString() );
111  if ( parts.contains( QStringLiteral( "serviceType" ) ) )
112  dsUri.setParam( QStringLiteral( "serviceType" ), parts[ QStringLiteral( "serviceType" ) ].toString() );
113  dsUri.setParam( QStringLiteral( "url" ), parts.value( parts.contains( QStringLiteral( "path" ) ) ? QStringLiteral( "path" ) : QStringLiteral( "url" ) ).toString() );
114 
115  if ( parts.contains( QStringLiteral( "zmin" ) ) )
116  dsUri.setParam( QStringLiteral( "zmin" ), parts[ QStringLiteral( "zmin" ) ].toString() );
117  if ( parts.contains( QStringLiteral( "zmax" ) ) )
118  dsUri.setParam( QStringLiteral( "zmax" ), parts[ QStringLiteral( "zmax" ) ].toString() );
119 
120  dsUri.httpHeaders().setFromMap( parts );
121 
122  if ( parts.contains( QStringLiteral( "styleUrl" ) ) )
123  dsUri.setParam( QStringLiteral( "styleUrl" ), parts[ QStringLiteral( "styleUrl" ) ].toString() );
124 
125  if ( parts.contains( QStringLiteral( "authcfg" ) ) )
126  dsUri.setAuthConfigId( parts[ QStringLiteral( "authcfg" ) ].toString() );
127 
128  return dsUri.encodedUri();
129 }
130 
131 QList<QgsMapLayerType> QgsVectorTileProviderMetadata::supportedLayerTypes() const
132 {
134 }
135 
QgsDataSourceUri
Class for storing the component parts of a RDBMS data source URI (e.g. a Postgres data source).
Definition: qgsdatasourceuri.h:37
qgsapplication.h
QgsDataSourceUri::param
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
Definition: qgsdatasourceuri.cpp:834
QgsHttpHeaders::updateMap
bool updateMap(QVariantMap &map) const
Updates a map by adding all the HTTP headers.
Definition: qgshttpheaders.cpp:107
QgsDataSourceUri::setAuthConfigId
void setAuthConfigId(const QString &authcfg)
Sets the authentication configuration ID for the URI.
Definition: qgsdatasourceuri.cpp:727
QgsDataSourceUri::setParam
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
Definition: qgsdatasourceuri.cpp:789
qgsvectortileconnection.h
QgsProviderMetadata
Holds data provider key, description, and associated shared library file or function pointer informat...
Definition: qgsprovidermetadata.h:177
QgsHttpHeaders::setFromMap
void setFromMap(const QVariantMap &map)
Loads headers from the map.
Definition: qgshttpheaders.cpp:190
QgsDataSourceUri::hasParam
bool hasParam(const QString &key) const
Returns true if a parameter with the specified key exists.
Definition: qgsdatasourceuri.cpp:860
qgsvectortileprovidermetadata.h
qgsvectortiledataitems.h
QgsDataSourceUri::encodedUri
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
Definition: qgsdatasourceuri.cpp:614
QgsDataSourceUri::setEncodedUri
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
Definition: qgsdatasourceuri.cpp:636
QgsMapLayerType::VectorTileLayer
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.
QgsApplication::getThemeIcon
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
Definition: qgsapplication.cpp:693
QgsAbstractProviderConnection
The QgsAbstractProviderConnection provides an interface for data provider connections.
Definition: qgsabstractproviderconnection.h:44
QgsDataSourceUri::authConfigId
QString authConfigId() const
Returns any associated authentication configuration ID stored in the URI.
Definition: qgsdatasourceuri.cpp:255
QgsDataSourceUri::httpHeaders
QgsHttpHeaders httpHeaders() const
Returns http headers.
Definition: qgsdatasourceuri.h:345