QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
qgstiledsceneconnection.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgstiledsceneconnection.cpp
3 ---------------------
4 begin : June 2023
5 copyright : (C) 2023 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
17
18#include "qgsdatasourceuri.h"
19#include "qgshttpheaders.h"
21
22
23#include <QFileInfo>
24
26
27
28const QgsSettingsEntryString *QgsTiledSceneProviderConnection::settingsProvider = new QgsSettingsEntryString( QStringLiteral( "provider" ), sTreeConnectionTiledScene );
29const QgsSettingsEntryString *QgsTiledSceneProviderConnection::settingsUrl = new QgsSettingsEntryString( QStringLiteral( "url" ), sTreeConnectionTiledScene );
30const QgsSettingsEntryString *QgsTiledSceneProviderConnection::settingsAuthcfg = new QgsSettingsEntryString( QStringLiteral( "authcfg" ), sTreeConnectionTiledScene );
31const QgsSettingsEntryString *QgsTiledSceneProviderConnection::settingsUsername = new QgsSettingsEntryString( QStringLiteral( "username" ), sTreeConnectionTiledScene );
32const QgsSettingsEntryString *QgsTiledSceneProviderConnection::settingsPassword = new QgsSettingsEntryString( QStringLiteral( "password" ), sTreeConnectionTiledScene );
33const QgsSettingsEntryVariantMap *QgsTiledSceneProviderConnection::settingsHeaders = new QgsSettingsEntryVariantMap( QStringLiteral( "http-header" ), sTreeConnectionTiledScene );
34
36
38{
40
41 if ( !data.url.isEmpty() )
42 uri.setParam( QStringLiteral( "url" ), data.url );
43 if ( !data.authCfg.isEmpty() )
44 uri.setAuthConfigId( data.authCfg );
45 if ( !data.username.isEmpty() )
46 uri.setUsername( data.username );
47 if ( !data.password.isEmpty() )
48 uri.setPassword( data.password );
49
50 uri.setHttpHeaders( data.httpHeaders );
51
52 return uri.encodedUri();
53}
54
56{
57 QgsDataSourceUri dsUri;
58 dsUri.setEncodedUri( uri );
59
61 conn.url = dsUri.param( QStringLiteral( "url" ) );
62 conn.authCfg = dsUri.authConfigId();
63 conn.username = dsUri.username();
64 conn.password = dsUri.password();
65 conn.httpHeaders = dsUri.httpHeaders();
66
67 return conn;
68}
69
71{
73
74 uri.setParam( QStringLiteral( "url" ), data.url );
75 if ( !data.authCfg.isEmpty() )
76 uri.setAuthConfigId( data.authCfg );
77 if ( !data.username.isEmpty() )
78 uri.setUsername( data.username );
79 if ( !data.password.isEmpty() )
80 uri.setPassword( data.password );
81
82 uri.setHttpHeaders( data.httpHeaders );
83
84 return uri.encodedUri();
85}
86
88{
89 return QgsTiledSceneProviderConnection::sTreeConnectionTiledScene->items();
90}
91
93{
94 if ( !settingsUrl->exists( name ) )
96
98 conn.provider = settingsProvider->value( name );
99 conn.url = settingsUrl->value( name );
100 conn.authCfg = settingsAuthcfg->value( name );
101 conn.username = settingsUsername->value( name );
102 conn.password = settingsPassword->value( name );
103
104 if ( settingsHeaders->exists( name ) )
105 conn.httpHeaders = QgsHttpHeaders( settingsHeaders->value( name ) );
106
107 return conn;
108}
109
110void QgsTiledSceneProviderConnection::addConnection( const QString &name, const Data &conn )
111{
112 settingsProvider->setValue( conn.provider, name );
113 settingsUrl->setValue( conn.url, name );
114 settingsAuthcfg->setValue( conn.authCfg, name );
115 settingsUsername->setValue( conn.username, name );
116 settingsPassword->setValue( conn.password, name );
117 settingsHeaders->setValue( conn.httpHeaders.headers(), name );
118}
119
121{
122 return sTreeConnectionTiledScene->selectedItem();
123}
124
126{
127 sTreeConnectionTiledScene->setSelectedItem( name );
128}
129
132{
133 const QgsTiledSceneProviderConnection::Data connectionData = connection( name );
134 mProvider = connectionData.provider;
135 setUri( encodedUri( connectionData ) );
136}
137
138QgsTiledSceneProviderConnection::QgsTiledSceneProviderConnection( const QString &uri, const QString &provider, const QVariantMap &configuration )
139 : QgsAbstractProviderConnection( uri, configuration )
140 , mProvider( provider )
141{
142}
143
144void QgsTiledSceneProviderConnection::store( const QString &name ) const
145{
147 connectionData.provider = mProvider;
148 addConnection( name, connectionData );
149}
150
151void QgsTiledSceneProviderConnection::remove( const QString &name ) const
152{
153 sTreeConnectionTiledScene->deleteItem( name );
154}
The QgsAbstractProviderConnection provides an interface for data provider connections.
void setUri(const QString &uri)
Sets the connection data source URI to uri.
QString uri() const
Returns the connection data source URI string representation.
Class for storing the component parts of a RDBMS data source URI (e.g.
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
QgsHttpHeaders httpHeaders() const
Returns http headers.
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.
This class implements simple http header management.
QVariantMap headers() const
Returns the headers as a variant map.
A string settings entry.
A string list settings entry.
virtual void remove(const QString &name) const override
Deletes the connection from the settings.
static QString selectedConnection()
Returns the name of the last used connection.
static Data decodedUri(const QString &uri)
Returns a connection uri decoded to a data structure.
virtual void store(const QString &name) const override
Stores the connection in the settings.
static Data connection(const QString &name)
Returns connection details for the stored connection with the specified name.
PRIVATE QgsTiledSceneProviderConnection(const QString &name)
Constructor for QgsTiledSceneProviderConnection, using the stored settings with the specified connect...
static void addConnection(const QString &name, const Data &connection)
Stores a new connection, under the specified connection name.
static void setSelectedConnection(const QString &name)
Stores the name of the last used connection.
static QStringList connectionList()
Returns a list of the stored connection names.
static QString encodedUri(const Data &data)
Returns connection data encoded as a string.
static QString encodedLayerUri(const Data &data)
Returns connection data encoded as a string containing a URI for a QgsTiledSceneLayer.
Represents decoded data of a tiled scene connection.
QString authCfg
Authentication configuration ID.