26 QString QgsVectorTileProviderConnection::encodedUri(
const QgsVectorTileProviderConnection::Data &conn )
30 const QFileInfo info( conn.url );
31 QString suffix = info.suffix().toLower();
32 if ( suffix.startsWith( QStringLiteral(
"mbtiles" ) ) )
34 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
38 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
41 uri.
setParam( QStringLiteral(
"url" ), conn.url );
42 if ( conn.zMin != -1 )
43 uri.
setParam( QStringLiteral(
"zmin" ), QString::number( conn.zMin ) );
44 if ( conn.zMax != -1 )
45 uri.
setParam( QStringLiteral(
"zmax" ), QString::number( conn.zMax ) );
46 if ( !conn.authCfg.isEmpty() )
48 if ( !conn.username.isEmpty() )
50 if ( !conn.password.isEmpty() )
52 if ( !conn.referer.isEmpty() )
53 uri.
setParam( QStringLiteral(
"referer" ), conn.referer );
54 if ( !conn.styleUrl.isEmpty() )
55 uri.
setParam( QStringLiteral(
"styleUrl" ), conn.styleUrl );
57 switch ( conn.serviceType )
62 case ArcgisVectorTileService:
63 uri.
setParam( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
70 QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::decodedUri(
const QString &uri )
75 QgsVectorTileProviderConnection::Data conn;
76 conn.url = dsUri.
param( QStringLiteral(
"url" ) );
77 conn.zMin = dsUri.
hasParam( QStringLiteral(
"zmin" ) ) ? dsUri.
param( QStringLiteral(
"zmin" ) ).toInt() : -1;
78 conn.zMax = dsUri.
hasParam( QStringLiteral(
"zmax" ) ) ? dsUri.
param( QStringLiteral(
"zmax" ) ).toInt() : -1;
82 conn.referer = dsUri.
param( QStringLiteral(
"referer" ) );
83 conn.styleUrl = dsUri.
param( QStringLiteral(
"styleUrl" ) );
85 if ( dsUri.
hasParam( QStringLiteral(
"serviceType" ) ) )
87 if ( dsUri.
param( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
88 conn.serviceType = ArcgisVectorTileService;
93 QString QgsVectorTileProviderConnection::encodedLayerUri(
const QgsVectorTileProviderConnection::Data &conn )
98 const QFileInfo info( conn.url );
99 QString suffix = info.suffix().toLower();
100 if ( suffix.startsWith( QStringLiteral(
"mbtiles" ) ) )
102 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"mbtiles" ) );
106 uri.
setParam( QStringLiteral(
"type" ), QStringLiteral(
"xyz" ) );
109 uri.
setParam( QStringLiteral(
"url" ), conn.url );
110 if ( conn.zMin != -1 )
111 uri.
setParam( QStringLiteral(
"zmin" ), QString::number( conn.zMin ) );
112 if ( conn.zMax != -1 )
113 uri.
setParam( QStringLiteral(
"zmax" ), QString::number( conn.zMax ) );
114 if ( !conn.authCfg.isEmpty() )
116 if ( !conn.username.isEmpty() )
118 if ( !conn.password.isEmpty() )
120 if ( !conn.referer.isEmpty() )
121 uri.
setParam( QStringLiteral(
"referer" ), conn.referer );
122 if ( !conn.styleUrl.isEmpty() )
123 uri.
setParam( QStringLiteral(
"styleUrl" ), conn.styleUrl );
125 switch ( conn.serviceType )
130 case ArcgisVectorTileService:
131 uri.
setParam( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
138 QStringList QgsVectorTileProviderConnection::connectionList()
141 settings.
beginGroup( QStringLiteral(
"qgis/connections-vector-tile" ) );
147 QgsVectorTileProviderConnection::Data QgsVectorTileProviderConnection::connection(
const QString &name )
150 settings.
beginGroup(
"qgis/connections-vector-tile/" + name );
152 if ( settings.
value(
"url" ).toString().isEmpty() )
153 return QgsVectorTileProviderConnection::Data();
155 QgsVectorTileProviderConnection::Data conn;
156 conn.url = settings.
value( QStringLiteral(
"url" ) ).toString();
157 conn.zMin = settings.
value( QStringLiteral(
"zmin" ), -1 ).toInt();
158 conn.zMax = settings.
value( QStringLiteral(
"zmax" ), -1 ).toInt();
159 conn.authCfg = settings.
value( QStringLiteral(
"authcfg" ) ).toString();
160 conn.username = settings.
value( QStringLiteral(
"username" ) ).toString();
161 conn.password = settings.
value( QStringLiteral(
"password" ) ).toString();
162 conn.referer = settings.
value( QStringLiteral(
"referer" ) ).toString();
163 conn.styleUrl = settings.
value( QStringLiteral(
"styleUrl" ) ).toString();
165 if ( settings.
contains( QStringLiteral(
"serviceType" ) ) )
167 if ( settings.
value( QStringLiteral(
"serviceType" ) ) == QLatin1String(
"arcgis" ) )
168 conn.serviceType = ArcgisVectorTileService;
174 void QgsVectorTileProviderConnection::deleteConnection(
const QString &name )
177 settings.
remove(
"qgis/connections-vector-tile/" + name );
180 void QgsVectorTileProviderConnection::addConnection(
const QString &name, QgsVectorTileProviderConnection::Data conn )
184 settings.
beginGroup(
"qgis/connections-vector-tile/" + name );
185 settings.
setValue( QStringLiteral(
"url" ), conn.url );
186 settings.
setValue( QStringLiteral(
"zmin" ), conn.zMin );
187 settings.
setValue( QStringLiteral(
"zmax" ), conn.zMax );
188 settings.
setValue( QStringLiteral(
"authcfg" ), conn.authCfg );
189 settings.
setValue( QStringLiteral(
"username" ), conn.username );
190 settings.
setValue( QStringLiteral(
"password" ), conn.password );
191 settings.
setValue( QStringLiteral(
"referer" ), conn.referer );
192 settings.
setValue( QStringLiteral(
"styleUrl" ), conn.styleUrl );
194 switch ( conn.serviceType )
199 case ArcgisVectorTileService:
200 settings.
setValue( QStringLiteral(
"serviceType" ), QStringLiteral(
"arcgis" ) );
205 QString QgsVectorTileProviderConnection::selectedConnection()
208 return settings.
value( QStringLiteral(
"qgis/connections-vector-tile/selected" ) ).toString();
211 void QgsVectorTileProviderConnection::setSelectedConnection(
const QString &name )
214 return settings.
setValue( QStringLiteral(
"qgis/connections-vector-tile/selected" ), name );
219 QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &name )
222 setUri( encodedUri( connection( name ) ) );
225 QgsVectorTileProviderConnection::QgsVectorTileProviderConnection(
const QString &uri,
const QVariantMap &configuration )
230 void QgsVectorTileProviderConnection::store(
const QString &name )
const
232 addConnection( name, decodedUri( uri() ) );
235 void QgsVectorTileProviderConnection::remove(
const QString &name )
const
237 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.