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()
40QIcon QgsVectorTileProviderMetadata::icon()
const
45QList<QgsDataItemProvider *> QgsVectorTileProviderMetadata::dataItemProviders()
const
47 QList< QgsDataItemProvider * > providers;
48 providers <<
new QgsVectorTileDataItemProvider;
52QMap<QString, QgsAbstractProviderConnection *> QgsVectorTileProviderMetadata::connections(
bool cached )
54 return connectionsProtected<QgsVectorTileProviderConnection, QgsVectorTileProviderConnection>( cached );
59 return new QgsVectorTileProviderConnection( name );
62void QgsVectorTileProviderMetadata::deleteConnection(
const QString &name )
64 deleteConnectionProtected<QgsVectorTileProviderConnection>( name );
69 saveConnectionProtected( connection, name );
77QVariantMap QgsVectorTileProviderMetadata::decodeUri(
const QString &uri )
const
82 QVariantMap uriComponents;
83 uriComponents.insert( u
"type"_s, dsUri.
param( u
"type"_s ) );
84 if ( dsUri.
hasParam( u
"serviceType"_s ) )
85 uriComponents.insert( u
"serviceType"_s, dsUri.
param( u
"serviceType"_s ) );
87 if ( uriComponents[ u
"type"_s ] ==
"mbtiles"_L1 ||
88 ( uriComponents[ u
"type"_s ] ==
"xyz"_L1 &&
89 !dsUri.
param( u
"url"_s ).startsWith(
"http"_L1 ) ) )
91 uriComponents.insert( u
"path"_s, dsUri.
param( u
"url"_s ) );
95 uriComponents.insert( u
"url"_s, dsUri.
param( u
"url"_s ) );
99 uriComponents.insert( u
"zmin"_s, dsUri.
param( u
"zmin"_s ) );
101 uriComponents.insert( u
"zmax"_s, dsUri.
param( u
"zmax"_s ) );
105 if ( dsUri.
hasParam( u
"styleUrl"_s ) )
106 uriComponents.insert( u
"styleUrl"_s, dsUri.
param( u
"styleUrl"_s ) );
109 if ( !authcfg.isEmpty() )
110 uriComponents.insert( u
"authcfg"_s, authcfg );
112 return uriComponents;
115QString QgsVectorTileProviderMetadata::encodeUri(
const QVariantMap &parts )
const
118 dsUri.
setParam( u
"type"_s, parts.value( u
"type"_s ).toString() );
119 if ( parts.contains( u
"serviceType"_s ) )
120 dsUri.
setParam( u
"serviceType"_s, parts[ u
"serviceType"_s ].toString() );
121 dsUri.
setParam( u
"url"_s, parts.value( parts.contains( u
"path"_s ) ? u
"path"_s : u
"url"_s ).toString() );
123 if ( parts.contains( u
"zmin"_s ) )
124 dsUri.
setParam( u
"zmin"_s, parts[ u
"zmin"_s ].toString() );
125 if ( parts.contains( u
"zmax"_s ) )
126 dsUri.
setParam( u
"zmax"_s, parts[ u
"zmax"_s ].toString() );
130 if ( parts.contains( u
"styleUrl"_s ) )
131 dsUri.
setParam( u
"styleUrl"_s, parts[ u
"styleUrl"_s ].toString() );
133 if ( parts.contains( u
"authcfg"_s ) )
139QString QgsVectorTileProviderMetadata::absoluteToRelativeUri(
const QString &uri,
const QgsReadWriteContext &context )
const
144 const QString sourceType = dsUri.
param( u
"type"_s );
145 QString sourcePath = dsUri.
param( u
"url"_s );
146 if ( sourceType ==
"xyz"_L1 )
148 const QUrl sourceUrl( sourcePath );
149 if ( sourceUrl.isLocalFile() )
154 dsUri.
setParam( u
"url"_s, QUrl::fromLocalFile( relSrcUrl ).toString( QUrl::DecodeReserved ) );
158 else if ( sourceType ==
"mbtiles"_L1 )
162 dsUri.
setParam( u
"url"_s, sourcePath );
169QString QgsVectorTileProviderMetadata::relativeToAbsoluteUri(
const QString &uri,
const QgsReadWriteContext &context )
const
174 const QString sourceType = dsUri.
param( u
"type"_s );
175 QString sourcePath = dsUri.
param( u
"url"_s );
176 if ( sourceType ==
"xyz"_L1 )
178 const QUrl sourceUrl( sourcePath );
179 if ( sourceUrl.isLocalFile() )
183 dsUri.
setParam( u
"url"_s, QUrl::fromLocalFile( absSrcUrl ).toString( QUrl::DecodeReserved ) );
187 else if ( sourceType ==
"mbtiles"_L1 )
191 dsUri.
setParam( u
"url"_s, sourcePath );
198QList<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.