38QString QgsVectorTileProviderConnection::encodedUri(
const QgsVectorTileProviderConnection::Data &conn )
42 const QFileInfo info( conn.url );
43 QString suffix = info.suffix().toLower();
44 if ( suffix.startsWith( QLatin1String(
"mbtiles" ) ) )
46 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
50 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
53 uri.
setParam( QStringLiteral(
"url" ), conn.url );
54 if ( conn.zMin != -1 )
55 uri.
setParam( QStringLiteral(
"zmin" ), QString::number( conn.zMin ) );
56 if ( conn.zMax != -1 )
57 uri.
setParam( QStringLiteral(
"zmax" ), QString::number( conn.zMax ) );
58 if ( !conn.authCfg.isEmpty() )
60 if ( !conn.username.isEmpty() )
62 if ( !conn.password.isEmpty() )
64 if ( !conn.styleUrl.isEmpty() )
65 uri.
setParam( QStringLiteral(
"styleUrl" ), conn.styleUrl );
69 switch ( conn.serviceType )
74 case ArcgisVectorTileService:
75 uri.
setParam( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
82QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::decodedUri(
const QString &uri )
87 QgsVectorTileProviderConnection::Data conn;
88 conn.url = dsUri.
param( QStringLiteral(
"url" ) );
89 conn.zMin = dsUri.
hasParam( QStringLiteral(
"zmin" ) ) ? dsUri.
param( QStringLiteral(
"zmin" ) ).toInt() : -1;
90 conn.zMax = dsUri.
hasParam( QStringLiteral(
"zmax" ) ) ? dsUri.
param( QStringLiteral(
"zmax" ) ).toInt() : -1;
94 conn.styleUrl = dsUri.
param( QStringLiteral(
"styleUrl" ) );
98 if ( dsUri.
hasParam( QStringLiteral(
"serviceType" ) ) )
100 if ( dsUri.
param( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
101 conn.serviceType = ArcgisVectorTileService;
106QString QgsVectorTileProviderConnection::encodedLayerUri(
const QgsVectorTileProviderConnection::Data &conn )
111 const QFileInfo info( conn.url );
112 QString suffix = info.suffix().toLower();
113 if ( suffix.startsWith( QLatin1String(
"mbtiles" ) ) )
115 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
119 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
122 uri.
setParam( QStringLiteral(
"url" ), conn.url );
123 if ( conn.zMin != -1 )
124 uri.
setParam( QStringLiteral(
"zmin" ), QString::number( conn.zMin ) );
125 if ( conn.zMax != -1 )
126 uri.
setParam( QStringLiteral(
"zmax" ), QString::number( conn.zMax ) );
127 if ( !conn.authCfg.isEmpty() )
129 if ( !conn.username.isEmpty() )
131 if ( !conn.password.isEmpty() )
133 if ( !conn.styleUrl.isEmpty() )
134 uri.
setParam( QStringLiteral(
"styleUrl" ), conn.styleUrl );
138 switch ( conn.serviceType )
143 case ArcgisVectorTileService:
144 uri.
setParam( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
151QStringList QgsVectorTileProviderConnection::connectionList()
153 return QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
156QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::connection(
const QString &name )
158 if ( !settingsUrl->exists( name ) )
159 return QgsVectorTileProviderConnection::Data();
161 QgsVectorTileProviderConnection::Data conn;
162 conn.url = settingsUrl->value( name );
163 conn.zMin = settingsZmin->value( name );
164 conn.zMax = settingsZmax->value( name );
165 conn.authCfg = settingsAuthcfg->value( name );
166 conn.username = settingsUsername->value( name );
167 conn.password = settingsPassword->value( name );
168 conn.styleUrl = settingsStyleUrl->value( name );
170 if ( settingsHeaders->exists( name ) )
171 conn.httpHeaders =
QgsHttpHeaders( settingsHeaders->value( name ) );
173 if ( settingsServiceType->exists( name ) && settingsServiceType->value( name ) == QLatin1String(
"arcgis" ) )
174 conn.serviceType = ArcgisVectorTileService;
179void QgsVectorTileProviderConnection::deleteConnection(
const QString &name )
181 sTreeConnectionVectorTile->deleteItem( name );
184void QgsVectorTileProviderConnection::addConnection(
const QString &name, QgsVectorTileProviderConnection::Data conn )
186 settingsUrl->setValue( conn.url, name );
187 settingsZmin->setValue( conn.zMin, name );
188 settingsZmax->setValue( conn.zMax, name );
189 settingsAuthcfg->setValue( conn.authCfg, name );
190 settingsUsername->setValue( conn.username, name );
191 settingsPassword->setValue( conn.password, name );
192 settingsStyleUrl->setValue( conn.styleUrl, name );
194 settingsHeaders->setValue( conn.httpHeaders.headers(), name );
196 switch ( conn.serviceType )
201 case ArcgisVectorTileService:
202 settingsServiceType->setValue( QStringLiteral(
"arcgis" ), name );
207QString QgsVectorTileProviderConnection::selectedConnection()
209 return sTreeConnectionVectorTile->selectedItem();
212void QgsVectorTileProviderConnection::setSelectedConnection(
const QString &name )
214 sTreeConnectionVectorTile->setSelectedItem( name );
218QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &name )
221 setUri( encodedUri( connection( name ) ) );
224QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &uri,
const QVariantMap &configuration )
229void QgsVectorTileProviderConnection::store(
const QString &name )
const
231 addConnection( name, decodedUri( uri() ) );
234void QgsVectorTileProviderConnection::remove(
const QString &name )
const
236 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.
QgsHttpHeaders httpHeaders() const
Returns http headers.
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 setHttpHeaders(const QgsHttpHeaders &headers)
Sets headers to headers.
void setPassword(const QString &password)
Sets the password for the URI.
An integer settings entry.
A string list settings entry.