25using namespace Qt::StringLiterals;
40QString QgsVectorTileProviderConnection::encodedUri(
const QgsVectorTileProviderConnection::Data &conn )
44 const QFileInfo info( conn.url );
45 QString suffix = info.suffix().toLower();
46 if ( suffix.startsWith(
"mbtiles"_L1 ) )
48 uri.
setParam( u
"type"_s, u
"mbtiles"_s );
56 if ( conn.zMin != -1 )
57 uri.
setParam( u
"zmin"_s, QString::number( conn.zMin ) );
58 if ( conn.zMax != -1 )
59 uri.
setParam( u
"zmax"_s, QString::number( conn.zMax ) );
60 if ( !conn.authCfg.isEmpty() )
62 if ( !conn.username.isEmpty() )
64 if ( !conn.password.isEmpty() )
66 if ( !conn.styleUrl.isEmpty() )
67 uri.
setParam( u
"styleUrl"_s, conn.styleUrl );
71 switch ( conn.serviceType )
76 case ArcgisVectorTileService:
77 uri.
setParam( u
"serviceType"_s, u
"arcgis"_s );
84QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::decodedUri(
const QString &uri )
89 QgsVectorTileProviderConnection::Data conn;
90 conn.url = dsUri.
param( u
"url"_s );
91 conn.zMin = dsUri.
hasParam( u
"zmin"_s ) ? dsUri.
param( u
"zmin"_s ).toInt() : -1;
92 conn.zMax = dsUri.
hasParam( u
"zmax"_s ) ? dsUri.
param( u
"zmax"_s ).toInt() : -1;
96 conn.styleUrl = dsUri.
param( u
"styleUrl"_s );
100 if ( dsUri.
hasParam( u
"serviceType"_s ) )
102 if ( dsUri.
param( u
"serviceType"_s ) ==
"arcgis"_L1 )
103 conn.serviceType = ArcgisVectorTileService;
108QString QgsVectorTileProviderConnection::encodedLayerUri(
const QgsVectorTileProviderConnection::Data &conn )
113 const QFileInfo info( conn.url );
114 QString suffix = info.suffix().toLower();
115 if ( suffix.startsWith(
"mbtiles"_L1 ) )
117 uri.
setParam( u
"type"_s, u
"mbtiles"_s );
121 uri.
setParam( u
"type"_s, u
"xyz"_s );
125 if ( conn.zMin != -1 )
126 uri.
setParam( u
"zmin"_s, QString::number( conn.zMin ) );
127 if ( conn.zMax != -1 )
128 uri.
setParam( u
"zmax"_s, QString::number( conn.zMax ) );
129 if ( !conn.authCfg.isEmpty() )
131 if ( !conn.username.isEmpty() )
133 if ( !conn.password.isEmpty() )
135 if ( !conn.styleUrl.isEmpty() )
136 uri.
setParam( u
"styleUrl"_s, conn.styleUrl );
140 switch ( conn.serviceType )
145 case ArcgisVectorTileService:
146 uri.
setParam( u
"serviceType"_s, u
"arcgis"_s );
153QStringList QgsVectorTileProviderConnection::connectionList()
155 return QgsVectorTileProviderConnection::sTreeConnectionVectorTile->items();
158QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::connection(
const QString &name )
160 if ( !settingsUrl->exists( name ) && !settingsStyleUrl->exists( name ) )
161 return QgsVectorTileProviderConnection::Data();
163 QgsVectorTileProviderConnection::Data conn;
164 conn.url = settingsUrl->value( name );
165 conn.zMin = settingsZmin->value( name );
166 conn.zMax = settingsZmax->value( name );
167 conn.authCfg = settingsAuthcfg->value( name );
168 conn.username = settingsUsername->value( name );
169 conn.password = settingsPassword->value( name );
170 conn.styleUrl = settingsStyleUrl->value( name );
172 if ( settingsHeaders->exists( name ) )
173 conn.httpHeaders =
QgsHttpHeaders( settingsHeaders->value( name ) );
175 if ( settingsServiceType->exists( name ) && settingsServiceType->value( name ) ==
"arcgis"_L1 )
176 conn.serviceType = ArcgisVectorTileService;
181void QgsVectorTileProviderConnection::deleteConnection(
const QString &name )
183 sTreeConnectionVectorTile->deleteItem( name );
186void QgsVectorTileProviderConnection::addConnection(
const QString &name, QgsVectorTileProviderConnection::Data conn )
188 settingsUrl->setValue( conn.url, name );
189 settingsZmin->setValue( conn.zMin, name );
190 settingsZmax->setValue( conn.zMax, name );
191 settingsAuthcfg->setValue( conn.authCfg, name );
192 settingsUsername->setValue( conn.username, name );
193 settingsPassword->setValue( conn.password, name );
194 settingsStyleUrl->setValue( conn.styleUrl, name );
196 settingsHeaders->setValue( conn.httpHeaders.headers(), name );
198 switch ( conn.serviceType )
203 case ArcgisVectorTileService:
204 settingsServiceType->setValue( u
"arcgis"_s, name );
209QString QgsVectorTileProviderConnection::selectedConnection()
211 return sTreeConnectionVectorTile->selectedItem();
214void QgsVectorTileProviderConnection::setSelectedConnection(
const QString &name )
216 sTreeConnectionVectorTile->setSelectedItem( name );
220QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &name )
223 setUri( encodedUri( connection( name ) ) );
226QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &uri,
const QVariantMap &configuration )
231void QgsVectorTileProviderConnection::store(
const QString &name )
const
233 addConnection( name, decodedUri( uri() ) );
236void QgsVectorTileProviderConnection::remove(
const QString &name )
const
238 deleteConnection( name );
An interface for data provider connections.
Stores the component parts of a 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.