24 QString QgsVectorTileProviderConnection::encodedUri(
const QgsVectorTileProviderConnection::Data &conn )
27 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
28 uri.
setParam( QStringLiteral(
"url" ), conn.url );
29 if ( conn.zMin != -1 )
30 uri.
setParam( QStringLiteral(
"zmin" ), QString::number( conn.zMin ) );
31 if ( conn.zMax != -1 )
32 uri.
setParam( QStringLiteral(
"zmax" ), QString::number( conn.zMax ) );
33 if ( !conn.authCfg.isEmpty() )
35 if ( !conn.username.isEmpty() )
37 if ( !conn.password.isEmpty() )
39 if ( !conn.referer.isEmpty() )
40 uri.
setParam( QStringLiteral(
"referer" ), conn.referer );
41 if ( !conn.styleUrl.isEmpty() )
42 uri.
setParam( QStringLiteral(
"styleUrl" ), conn.styleUrl );
44 switch ( conn.serviceType )
49 case ArcgisVectorTileService:
50 uri.
setParam( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
57 QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::decodedUri(
const QString &uri )
62 QgsVectorTileProviderConnection::Data conn;
63 conn.url = dsUri.
param( QStringLiteral(
"url" ) );
64 conn.zMin = dsUri.
hasParam( QStringLiteral(
"zmin" ) ) ? dsUri.
param( QStringLiteral(
"zmin" ) ).toInt() : -1;
65 conn.zMax = dsUri.
hasParam( QStringLiteral(
"zmax" ) ) ? dsUri.
param( QStringLiteral(
"zmax" ) ).toInt() : -1;
69 conn.referer = dsUri.
param( QStringLiteral(
"referer" ) );
70 conn.styleUrl = dsUri.
param( QStringLiteral(
"styleUrl" ) );
72 if ( dsUri.
hasParam( QStringLiteral(
"serviceType" ) ) )
74 if ( dsUri.
param( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
75 conn.serviceType = ArcgisVectorTileService;
80 QString QgsVectorTileProviderConnection::encodedLayerUri(
const QgsVectorTileProviderConnection::Data &conn )
84 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
85 uri.
setParam( QStringLiteral(
"url" ), conn.url );
86 if ( conn.zMin != -1 )
87 uri.
setParam( QStringLiteral(
"zmin" ), QString::number( conn.zMin ) );
88 if ( conn.zMax != -1 )
89 uri.
setParam( QStringLiteral(
"zmax" ), QString::number( conn.zMax ) );
90 if ( !conn.authCfg.isEmpty() )
92 if ( !conn.username.isEmpty() )
94 if ( !conn.password.isEmpty() )
96 if ( !conn.referer.isEmpty() )
97 uri.
setParam( QStringLiteral(
"referer" ), conn.referer );
98 if ( !conn.styleUrl.isEmpty() )
99 uri.
setParam( QStringLiteral(
"styleUrl" ), conn.styleUrl );
101 switch ( conn.serviceType )
106 case ArcgisVectorTileService:
107 uri.
setParam( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
114 QStringList QgsVectorTileProviderConnection::connectionList()
117 settings.
beginGroup( QStringLiteral(
"qgis/connections-vector-tile" ) );
123 QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::connection(
const QString &name )
126 settings.
beginGroup(
"qgis/connections-vector-tile/" + name );
128 if ( settings.
value(
"url" ).toString().isEmpty() )
129 return QgsVectorTileProviderConnection::Data();
131 QgsVectorTileProviderConnection::Data conn;
132 conn.url = settings.
value( QStringLiteral(
"url" ) ).toString();
133 conn.zMin = settings.
value( QStringLiteral(
"zmin" ), -1 ).toInt();
134 conn.zMax = settings.
value( QStringLiteral(
"zmax" ), -1 ).toInt();
135 conn.authCfg = settings.
value( QStringLiteral(
"authcfg" ) ).toString();
136 conn.username = settings.
value( QStringLiteral(
"username" ) ).toString();
137 conn.password = settings.
value( QStringLiteral(
"password" ) ).toString();
138 conn.referer = settings.
value( QStringLiteral(
"referer" ) ).toString();
139 conn.styleUrl = settings.
value( QStringLiteral(
"styleUrl" ) ).toString();
141 if ( settings.
contains( QStringLiteral(
"serviceType" ) ) )
143 if ( settings.
value( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
144 conn.serviceType = ArcgisVectorTileService;
150 void QgsVectorTileProviderConnection::deleteConnection(
const QString &name )
153 settings.
remove(
"qgis/connections-vector-tile/" + name );
156 void QgsVectorTileProviderConnection::addConnection(
const QString &name, QgsVectorTileProviderConnection::Data conn )
160 settings.
beginGroup(
"qgis/connections-vector-tile/" + name );
161 settings.
setValue( QStringLiteral(
"url" ), conn.url );
162 settings.
setValue( QStringLiteral(
"zmin" ), conn.zMin );
163 settings.
setValue( QStringLiteral(
"zmax" ), conn.zMax );
164 settings.
setValue( QStringLiteral(
"authcfg" ), conn.authCfg );
165 settings.
setValue( QStringLiteral(
"username" ), conn.username );
166 settings.
setValue( QStringLiteral(
"password" ), conn.password );
167 settings.
setValue( QStringLiteral(
"referer" ), conn.referer );
168 settings.
setValue( QStringLiteral(
"styleUrl" ), conn.styleUrl );
170 switch ( conn.serviceType )
175 case ArcgisVectorTileService:
176 settings.
setValue( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
181 QString QgsVectorTileProviderConnection::selectedConnection()
184 return settings.
value( QStringLiteral(
"qgis/connections-vector-tile/selected" ) ).toString();
187 void QgsVectorTileProviderConnection::setSelectedConnection(
const QString &name )
190 return settings.
setValue( QStringLiteral(
"qgis/connections-vector-tile/selected" ), name );
195 QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &name )
198 setUri( encodedUri( connection( name ) ) );
201 QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &uri,
const QVariantMap &configuration )
206 void QgsVectorTileProviderConnection::store(
const QString &name )
const
208 addConnection( name, decodedUri( uri() ) );
211 void QgsVectorTileProviderConnection::remove(
const QString &name )
const
213 deleteConnection( name );