27 QString QgsVectorTileProviderConnection::encodedUri(
const QgsVectorTileProviderConnection::Data &conn )
31 const QFileInfo info( conn.url );
32 QString suffix = info.suffix().toLower();
33 if ( suffix.startsWith( QLatin1String(
"mbtiles" ) ) )
35 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
39 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
42 uri.
setParam( QStringLiteral(
"url" ), conn.url );
43 if ( conn.zMin != -1 )
44 uri.
setParam( QStringLiteral(
"zmin" ), QString::number( conn.zMin ) );
45 if ( conn.zMax != -1 )
46 uri.
setParam( QStringLiteral(
"zmax" ), QString::number( conn.zMax ) );
47 if ( !conn.authCfg.isEmpty() )
49 if ( !conn.username.isEmpty() )
51 if ( !conn.password.isEmpty() )
53 if ( !conn.styleUrl.isEmpty() )
54 uri.
setParam( QStringLiteral(
"styleUrl" ), conn.styleUrl );
58 switch ( conn.serviceType )
63 case ArcgisVectorTileService:
64 uri.
setParam( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
71 QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::decodedUri(
const QString &uri )
76 QgsVectorTileProviderConnection::Data conn;
77 conn.url = dsUri.
param( QStringLiteral(
"url" ) );
78 conn.zMin = dsUri.
hasParam( QStringLiteral(
"zmin" ) ) ? dsUri.
param( QStringLiteral(
"zmin" ) ).toInt() : -1;
79 conn.zMax = dsUri.
hasParam( QStringLiteral(
"zmax" ) ) ? dsUri.
param( QStringLiteral(
"zmax" ) ).toInt() : -1;
83 conn.styleUrl = dsUri.
param( QStringLiteral(
"styleUrl" ) );
87 if ( dsUri.
hasParam( QStringLiteral(
"serviceType" ) ) )
89 if ( dsUri.
param( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
90 conn.serviceType = ArcgisVectorTileService;
95 QString QgsVectorTileProviderConnection::encodedLayerUri(
const QgsVectorTileProviderConnection::Data &conn )
100 const QFileInfo info( conn.url );
101 QString suffix = info.suffix().toLower();
102 if ( suffix.startsWith( QLatin1String(
"mbtiles" ) ) )
104 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
108 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
111 uri.
setParam( QStringLiteral(
"url" ), conn.url );
112 if ( conn.zMin != -1 )
113 uri.
setParam( QStringLiteral(
"zmin" ), QString::number( conn.zMin ) );
114 if ( conn.zMax != -1 )
115 uri.
setParam( QStringLiteral(
"zmax" ), QString::number( conn.zMax ) );
116 if ( !conn.authCfg.isEmpty() )
118 if ( !conn.username.isEmpty() )
120 if ( !conn.password.isEmpty() )
122 if ( !conn.styleUrl.isEmpty() )
123 uri.
setParam( QStringLiteral(
"styleUrl" ), conn.styleUrl );
127 switch ( conn.serviceType )
132 case ArcgisVectorTileService:
133 uri.
setParam( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
140 QStringList QgsVectorTileProviderConnection::connectionList()
143 settings.
beginGroup( QStringLiteral(
"qgis/connections-vector-tile" ) );
149 QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::connection(
const QString &name )
152 settings.
beginGroup(
"qgis/connections-vector-tile/" + name );
154 if ( settings.
value(
"url" ).toString().isEmpty() )
155 return QgsVectorTileProviderConnection::Data();
157 QgsVectorTileProviderConnection::Data conn;
158 conn.url = settings.
value( QStringLiteral(
"url" ) ).toString();
159 conn.zMin = settings.
value( QStringLiteral(
"zmin" ), -1 ).toInt();
160 conn.zMax = settings.
value( QStringLiteral(
"zmax" ), -1 ).toInt();
161 conn.authCfg = settings.
value( QStringLiteral(
"authcfg" ) ).toString();
162 conn.username = settings.
value( QStringLiteral(
"username" ) ).toString();
163 conn.password = settings.
value( QStringLiteral(
"password" ) ).toString();
164 conn.styleUrl = settings.
value( QStringLiteral(
"styleUrl" ) ).toString();
168 if ( settings.
contains( QStringLiteral(
"serviceType" ) ) )
170 if ( settings.
value( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
171 conn.serviceType = ArcgisVectorTileService;
177 void QgsVectorTileProviderConnection::deleteConnection(
const QString &name )
180 settings.
remove(
"qgis/connections-vector-tile/" + name );
183 void QgsVectorTileProviderConnection::addConnection(
const QString &name, QgsVectorTileProviderConnection::Data conn )
187 settings.
beginGroup(
"qgis/connections-vector-tile/" + name );
188 settings.
setValue( QStringLiteral(
"url" ), conn.url );
189 settings.
setValue( QStringLiteral(
"zmin" ), conn.zMin );
190 settings.
setValue( QStringLiteral(
"zmax" ), conn.zMax );
191 settings.
setValue( QStringLiteral(
"authcfg" ), conn.authCfg );
192 settings.
setValue( QStringLiteral(
"username" ), conn.username );
193 settings.
setValue( QStringLiteral(
"password" ), conn.password );
194 settings.
setValue( QStringLiteral(
"styleUrl" ), conn.styleUrl );
196 conn.httpHeaders.updateSettings( settings );
198 switch ( conn.serviceType )
203 case ArcgisVectorTileService:
204 settings.
setValue( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
209 QString QgsVectorTileProviderConnection::selectedConnection()
212 return settings.
value( QStringLiteral(
"qgis/connections-vector-tile/selected" ) ).toString();
215 void QgsVectorTileProviderConnection::setSelectedConnection(
const QString &name )
218 return settings.
setValue( QStringLiteral(
"qgis/connections-vector-tile/selected" ), name );
223 QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &name )
226 setUri( encodedUri( connection( name ) ) );
229 QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &uri,
const QVariantMap &configuration )
234 void QgsVectorTileProviderConnection::store(
const QString &name )
const
236 addConnection( name, decodedUri( uri() ) );
239 void QgsVectorTileProviderConnection::remove(
const QString &name )
const
241 deleteConnection( name );