QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
qgssensorthingsconnection.cpp
Go to the documentation of this file.
1/***************************************************************************
2 QgsSensorThingsProviderConnection.cpp
3 ---------------------
4 Date : December 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
16#include <qgslogger.h>
18
19#include "qgsowsconnection.h"
20#include "qgsdatasourceuri.h"
22
24const QgsSettingsEntryString *QgsSensorThingsProviderConnection::settingsUrl = new QgsSettingsEntryString( QStringLiteral( "url" ), sTreeSensorThingsConnections, QString() ) ;
25const QgsSettingsEntryVariantMap *QgsSensorThingsProviderConnection::settingsHeaders = new QgsSettingsEntryVariantMap( QStringLiteral( "http-header" ), sTreeSensorThingsConnections ) ;
26const QgsSettingsEntryString *QgsSensorThingsProviderConnection::settingsUsername = new QgsSettingsEntryString( QStringLiteral( "username" ), sTreeSensorThingsConnections ) ;
27const QgsSettingsEntryString *QgsSensorThingsProviderConnection::settingsPassword = new QgsSettingsEntryString( QStringLiteral( "password" ), sTreeSensorThingsConnections ) ;
28const QgsSettingsEntryString *QgsSensorThingsProviderConnection::settingsAuthcfg = new QgsSettingsEntryString( QStringLiteral( "authcfg" ), sTreeSensorThingsConnections ) ;
30
31
32
35{
36 const QgsSensorThingsProviderConnection::Data connectionData = connection( name );
37 setUri( encodedUri( connectionData ) );
38}
39
40QgsSensorThingsProviderConnection::QgsSensorThingsProviderConnection( const QString &uri, const QVariantMap &configuration )
41 : QgsAbstractProviderConnection( uri, configuration )
42{
43}
44
45void QgsSensorThingsProviderConnection::store( const QString &name ) const
46{
48 addConnection( name, connectionData );
49}
50
51void QgsSensorThingsProviderConnection::remove( const QString &name ) const
52{
53 sTreeSensorThingsConnections->deleteItem( name );
54}
55
57{
58 return sTreeSensorThingsConnections->selectedItem();
59}
60
62{
63 sTreeSensorThingsConnections->setSelectedItem( name );
64}
65
66void QgsSensorThingsProviderConnection::addConnection( const QString &name, const Data &conn )
67{
68 settingsUrl->setValue( conn.url, name );
69 settingsAuthcfg->setValue( conn.authCfg, name );
70 settingsUsername->setValue( conn.username, name );
71 settingsPassword->setValue( conn.password, name );
72 settingsHeaders->setValue( conn.httpHeaders.headers(), name );
73}
74
76{
77 if ( !settingsUrl->exists( name ) )
79
81 conn.url = settingsUrl->value( name );
82 conn.authCfg = settingsAuthcfg->value( name );
83 conn.username = settingsUsername->value( name );
84 conn.password = settingsPassword->value( name );
85
86 if ( settingsHeaders->exists( name ) )
87 conn.httpHeaders = QgsHttpHeaders( settingsHeaders->value( name ) );
88
89 return conn;
90}
91
93{
94 return QgsSensorThingsProviderConnection::sTreeSensorThingsConnections->items();
95}
96
98{
100 if ( !data.url.isEmpty() )
101 uri.setParam( QStringLiteral( "url" ), data.url );
102 if ( !data.authCfg.isEmpty() )
103 uri.setAuthConfigId( data.authCfg );
104 if ( !data.username.isEmpty() )
105 uri.setUsername( data.username );
106 if ( !data.password.isEmpty() )
107 uri.setPassword( data.password );
108
109 uri.setHttpHeaders( data.httpHeaders );
110 return uri.encodedUri();
111}
112
114{
115 QgsDataSourceUri dsUri;
116 dsUri.setEncodedUri( uri );
117
119 conn.url = dsUri.param( QStringLiteral( "url" ) );
120 conn.authCfg = dsUri.authConfigId();
121 conn.username = dsUri.username();
122 conn.password = dsUri.password();
123 conn.httpHeaders = dsUri.httpHeaders();
124
125 return conn;
126}
127
129{
131
132 uri.setParam( QStringLiteral( "url" ), data.url );
133 if ( !data.authCfg.isEmpty() )
134 uri.setAuthConfigId( data.authCfg );
135 if ( !data.username.isEmpty() )
136 uri.setUsername( data.username );
137 if ( !data.password.isEmpty() )
138 uri.setPassword( data.password );
139
140 uri.setHttpHeaders( data.httpHeaders );
141
142 return uri.uri( false );
143}
144
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.
static QString selectedConnection()
Returns the name of the last used connection.
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 SensorThings vector data provider.
void remove(const QString &name) const final
Deletes the connection from the settings.
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 Data connection(const QString &name)
Returns connection details for the stored connection with the specified name.
PRIVATE QgsSensorThingsProviderConnection(const QString &name)
Constructor for QgsSensorThingsProviderConnection, using the stored settings with the specified conne...
static Data decodedUri(const QString &uri)
Returns a connection uri decoded to a data structure.
void store(const QString &name) const final
Stores the connection in the settings.
static void addConnection(const QString &name, const Data &connection)
Stores a new connection, under the specified connection name.
A string settings entry.
A string list settings entry.
Represents decoded data of a SensorThings connection.
QString authCfg
Authentication configuration id.