QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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
20#include "qgsapplication.h"
21
23
24#define PROVIDER_KEY QStringLiteral( "vectortile" )
25#define PROVIDER_DESCRIPTION QStringLiteral( "Vector tile provider" )
26
27QgsVectorTileProviderMetadata::QgsVectorTileProviderMetadata()
28 : QgsProviderMetadata( PROVIDER_KEY, PROVIDER_DESCRIPTION )
29{
30}
31
32QIcon QgsVectorTileProviderMetadata::icon() const
33{
34 return QgsApplication::getThemeIcon( QStringLiteral( "mIconVectorTileLayer.svg" ) );
35}
36
37QList<QgsDataItemProvider *> QgsVectorTileProviderMetadata::dataItemProviders() const
38{
39 QList< QgsDataItemProvider * > providers;
40 providers << new QgsVectorTileDataItemProvider;
41 return providers;
42}
43
44QMap<QString, QgsAbstractProviderConnection *> QgsVectorTileProviderMetadata::connections( bool cached )
45{
46 return connectionsProtected<QgsVectorTileProviderConnection, QgsVectorTileProviderConnection>( cached );
47}
48
49QgsAbstractProviderConnection *QgsVectorTileProviderMetadata::createConnection( const QString &name )
50{
51 return new QgsVectorTileProviderConnection( name );
52}
53
54void QgsVectorTileProviderMetadata::deleteConnection( const QString &name )
55{
56 deleteConnectionProtected<QgsVectorTileProviderConnection>( name );
57}
58
59void QgsVectorTileProviderMetadata::saveConnection( const QgsAbstractProviderConnection *connection, const QString &name )
60{
61 saveConnectionProtected( connection, name );
62}
63
64QgsProviderMetadata::ProviderCapabilities QgsVectorTileProviderMetadata::providerCapabilities() const
65{
66 return FileBasedUris;
67}
68
69QVariantMap 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
107QString 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
131QList<QgsMapLayerType> QgsVectorTileProviderMetadata::supportedLayerTypes() const
132{
134}
135
The QgsAbstractProviderConnection provides an interface for data provider connections.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
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.
QgsHttpHeaders httpHeaders() const
Returns http headers.
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.
bool updateMap(QVariantMap &map) const
Updates a map by adding all the HTTP headers.
void setFromMap(const QVariantMap &map)
Loads headers from the map.
Holds data provider key, description, and associated shared library file or function pointer informat...
@ VectorTileLayer
Vector tile layer. Added in QGIS 3.14.