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.referer.isEmpty() )
54 uri.
setParam( QStringLiteral(
"referer" ), conn.referer );
55 if ( !conn.styleUrl.isEmpty() )
56 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.referer = dsUri.
param( QStringLiteral(
"referer" ) );
84 conn.styleUrl = dsUri.
param( QStringLiteral(
"styleUrl" ) );
86 if ( dsUri.
hasParam( QStringLiteral(
"serviceType" ) ) )
88 if ( dsUri.
param( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
89 conn.serviceType = ArcgisVectorTileService;
94 QString QgsVectorTileProviderConnection::encodedLayerUri(
const QgsVectorTileProviderConnection::Data &conn )
99 const QFileInfo info( conn.url );
100 QString suffix = info.suffix().toLower();
101 if ( suffix.startsWith( QLatin1String(
"mbtiles" ) ) )
103 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
107 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
110 uri.
setParam( QStringLiteral(
"url" ), conn.url );
111 if ( conn.zMin != -1 )
112 uri.
setParam( QStringLiteral(
"zmin" ), QString::number( conn.zMin ) );
113 if ( conn.zMax != -1 )
114 uri.
setParam( QStringLiteral(
"zmax" ), QString::number( conn.zMax ) );
115 if ( !conn.authCfg.isEmpty() )
117 if ( !conn.username.isEmpty() )
119 if ( !conn.password.isEmpty() )
121 if ( !conn.referer.isEmpty() )
122 uri.
setParam( QStringLiteral(
"referer" ), conn.referer );
123 if ( !conn.styleUrl.isEmpty() )
124 uri.
setParam( QStringLiteral(
"styleUrl" ), conn.styleUrl );
126 switch ( conn.serviceType )
131 case ArcgisVectorTileService:
132 uri.
setParam( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
139 QStringList QgsVectorTileProviderConnection::connectionList()
142 settings.
beginGroup( QStringLiteral(
"qgis/connections-vector-tile" ) );
148 QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::connection(
const QString &name )
151 settings.
beginGroup(
"qgis/connections-vector-tile/" + name );
153 if ( settings.
value(
"url" ).toString().isEmpty() )
154 return QgsVectorTileProviderConnection::Data();
156 QgsVectorTileProviderConnection::Data conn;
157 conn.url = settings.
value( QStringLiteral(
"url" ) ).toString();
158 conn.zMin = settings.
value( QStringLiteral(
"zmin" ), -1 ).toInt();
159 conn.zMax = settings.
value( QStringLiteral(
"zmax" ), -1 ).toInt();
160 conn.authCfg = settings.
value( QStringLiteral(
"authcfg" ) ).toString();
161 conn.username = settings.
value( QStringLiteral(
"username" ) ).toString();
162 conn.password = settings.
value( QStringLiteral(
"password" ) ).toString();
163 conn.referer =
QgsHttpHeaders( settings )[ QStringLiteral(
"referer" ) ].toString();
164 conn.styleUrl = settings.
value( QStringLiteral(
"styleUrl" ) ).toString();
166 if ( settings.
contains( QStringLiteral(
"serviceType" ) ) )
168 if ( settings.
value( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
169 conn.serviceType = ArcgisVectorTileService;
175 void QgsVectorTileProviderConnection::deleteConnection(
const QString &name )
178 settings.
remove(
"qgis/connections-vector-tile/" + name );
181 void QgsVectorTileProviderConnection::addConnection(
const QString &name, QgsVectorTileProviderConnection::Data conn )
185 settings.
beginGroup(
"qgis/connections-vector-tile/" + name );
186 settings.
setValue( QStringLiteral(
"url" ), conn.url );
187 settings.
setValue( QStringLiteral(
"zmin" ), conn.zMin );
188 settings.
setValue( QStringLiteral(
"zmax" ), conn.zMax );
189 settings.
setValue( QStringLiteral(
"authcfg" ), conn.authCfg );
190 settings.
setValue( QStringLiteral(
"username" ), conn.username );
191 settings.
setValue( QStringLiteral(
"password" ), conn.password );
193 settings.
setValue( QStringLiteral(
"styleUrl" ), conn.styleUrl );
195 switch ( conn.serviceType )
200 case ArcgisVectorTileService:
201 settings.
setValue( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
206 QString QgsVectorTileProviderConnection::selectedConnection()
209 return settings.
value( QStringLiteral(
"qgis/connections-vector-tile/selected" ) ).toString();
212 void QgsVectorTileProviderConnection::setSelectedConnection(
const QString &name )
215 return settings.
setValue( QStringLiteral(
"qgis/connections-vector-tile/selected" ), name );
220 QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &name )
223 setUri( encodedUri( connection( name ) ) );
226 QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &uri,
const QVariantMap &configuration )
231 void QgsVectorTileProviderConnection::store(
const QString &name )
const
233 addConnection( name, decodedUri( uri() ) );
236 void QgsVectorTileProviderConnection::remove(
const QString &name )
const
238 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.
This class is a composition of two QSettings instances:
QStringList childGroups() const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
bool contains(const QString &key, QgsSettings::Section section=QgsSettings::NoSection) const
Returns true if there exists a setting called key; returns false otherwise.
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.