20 #include "qgssettings.h"
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()
116 QgsSettings settings;
117 settings.beginGroup( QStringLiteral(
"qgis/connections-vector-tile" ) );
118 QStringList connList = settings.childGroups();
123 QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::connection(
const QString &name )
125 QgsSettings settings;
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 )
152 QgsSettings settings;
153 settings.remove(
"qgis/connections-vector-tile/" + name );
156 void QgsVectorTileProviderConnection::addConnection(
const QString &name, QgsVectorTileProviderConnection::Data conn )
158 QgsSettings settings;
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()
183 QgsSettings settings;
184 return settings.value( QStringLiteral(
"qgis/connections-vector-tile/selected" ) ).toString();
187 void QgsVectorTileProviderConnection::setSelectedConnection(
const QString &name )
189 QgsSettings settings;
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 );
The QgsAbstractProviderConnection provides an interface for data provider connections.
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.
void setUsername(const QString &username)
Sets the username for the URI.
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
QString username() const
Returns the username stored in the URI.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
QString password() const
Returns the password stored in the URI.
QString authConfigId() const
Returns any associated authentication configuration ID stored in the URI.
void setPassword(const QString &password)
Sets the password for the URI.