26#include "moc_qgsvectortileprovidermetadata.cpp"
28using namespace Qt::StringLiterals;
32#define PROVIDER_KEY u"vectortile"_s
33#define PROVIDER_DESCRIPTION u"Vector tile provider"_s
35QgsVectorTileProviderMetadata::QgsVectorTileProviderMetadata()
39QIcon QgsVectorTileProviderMetadata::icon()
const
44QList<QgsDataItemProvider *> QgsVectorTileProviderMetadata::dataItemProviders()
const
46 QList< QgsDataItemProvider * > providers;
47 providers <<
new QgsVectorTileDataItemProvider;
51QMap<QString, QgsAbstractProviderConnection *> QgsVectorTileProviderMetadata::connections(
bool cached )
53 return connectionsProtected<QgsVectorTileProviderConnection, QgsVectorTileProviderConnection>( cached );
58 return new QgsVectorTileProviderConnection( name );
61void QgsVectorTileProviderMetadata::deleteConnection(
const QString &name )
63 deleteConnectionProtected<QgsVectorTileProviderConnection>( name );
68 saveConnectionProtected( connection, name );
76QVariantMap QgsVectorTileProviderMetadata::decodeUri(
const QString &uri )
const
81 QVariantMap uriComponents;
82 uriComponents.insert( u
"type"_s, dsUri.
param( u
"type"_s ) );
83 if ( dsUri.
hasParam( u
"serviceType"_s ) )
84 uriComponents.insert( u
"serviceType"_s, dsUri.
param( u
"serviceType"_s ) );
86 if ( uriComponents[u
"type"_s] ==
"mbtiles"_L1 || ( uriComponents[u
"type"_s] ==
"xyz"_L1 && !dsUri.
param( u
"url"_s ).startsWith(
"http"_L1 ) ) )
88 uriComponents.insert( u
"path"_s, dsUri.
param( u
"url"_s ) );
92 uriComponents.insert( u
"url"_s, dsUri.
param( u
"url"_s ) );
96 uriComponents.insert( u
"zmin"_s, dsUri.
param( u
"zmin"_s ) );
98 uriComponents.insert( u
"zmax"_s, dsUri.
param( u
"zmax"_s ) );
102 if ( dsUri.
hasParam( u
"styleUrl"_s ) )
103 uriComponents.insert( u
"styleUrl"_s, dsUri.
param( u
"styleUrl"_s ) );
106 if ( !authcfg.isEmpty() )
107 uriComponents.insert( u
"authcfg"_s, authcfg );
109 return uriComponents;
112QString QgsVectorTileProviderMetadata::encodeUri(
const QVariantMap &parts )
const
115 dsUri.
setParam( u
"type"_s, parts.value( u
"type"_s ).toString() );
116 if ( parts.contains( u
"serviceType"_s ) )
117 dsUri.
setParam( u
"serviceType"_s, parts[u
"serviceType"_s].toString() );
118 dsUri.
setParam( u
"url"_s, parts.value( parts.contains( u
"path"_s ) ? u
"path"_s : u
"url"_s ).toString() );
120 if ( parts.contains( u
"zmin"_s ) )
121 dsUri.
setParam( u
"zmin"_s, parts[u
"zmin"_s].toString() );
122 if ( parts.contains( u
"zmax"_s ) )
123 dsUri.
setParam( u
"zmax"_s, parts[u
"zmax"_s].toString() );
127 if ( parts.contains( u
"styleUrl"_s ) )
128 dsUri.
setParam( u
"styleUrl"_s, parts[u
"styleUrl"_s].toString() );
130 if ( parts.contains( u
"authcfg"_s ) )
136QString QgsVectorTileProviderMetadata::absoluteToRelativeUri(
const QString &uri,
const QgsReadWriteContext &context )
const
141 const QString sourceType = dsUri.
param( u
"type"_s );
142 QString sourcePath = dsUri.
param( u
"url"_s );
143 if ( sourceType ==
"xyz"_L1 )
145 const QUrl sourceUrl( sourcePath );
146 if ( sourceUrl.isLocalFile() )
151 dsUri.
setParam( u
"url"_s, QUrl::fromLocalFile( relSrcUrl ).toString( QUrl::DecodeReserved ) );
155 else if ( sourceType ==
"mbtiles"_L1 )
159 dsUri.
setParam( u
"url"_s, sourcePath );
166QString QgsVectorTileProviderMetadata::relativeToAbsoluteUri(
const QString &uri,
const QgsReadWriteContext &context )
const
171 const QString sourceType = dsUri.
param( u
"type"_s );
172 QString sourcePath = dsUri.
param( u
"url"_s );
173 if ( sourceType ==
"xyz"_L1 )
175 const QUrl sourceUrl( sourcePath );
176 if ( sourceUrl.isLocalFile() )
180 dsUri.
setParam( u
"url"_s, QUrl::fromLocalFile( absSrcUrl ).toString( QUrl::DecodeReserved ) );
184 else if ( sourceType ==
"mbtiles"_L1 )
188 dsUri.
setParam( u
"url"_s, sourcePath );
195QList<Qgis::LayerType> QgsVectorTileProviderMetadata::supportedLayerTypes()
const
@ VectorTile
Vector tile layer. Added in QGIS 3.14.
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.
Stores the component parts of a 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.
int removeParam(const QString &key)
Removes a generic parameter by key.
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.
QString writePath(const QString &filename) const
Prepare a filename to save it to the project file.
QString readPath(const QString &filename) const
Turn filename read from the project file to an absolute path.
A container for the context for various read/write operations on objects.
const QgsPathResolver & pathResolver() const
Returns path resolver for conversion between relative and absolute paths.