QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
qgsgeonodeconnection.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeonodeconnection.cpp
3  ---------------------
4  begin : Feb 2017
5  copyright : (C) 2017 by Muhammad Yarjuna Rohmat, Ismail Sunni
6  email : rohmat at kartoza dot com, ismail at kartoza 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 "qgssettings.h"
17 #include "qgsgeonodeconnection.h"
18 #include "qgslogger.h"
19 #include "qgsdatasourceuri.h"
20 #include "qgsowsconnection.h"
21 
22 const QString QgsGeoNodeConnectionUtils::sPathGeoNodeConnection = QStringLiteral( "qgis/connections-geonode" );
23 const QString QgsGeoNodeConnectionUtils::sPathGeoNodeConnectionDetails = QStringLiteral( "qgis/GeoNode" );
24 
26  : mConnName( name )
27 {
28  const QgsSettings settings;
29 
30 // settings.Section
31  const QString key = settingsKey();
32  const QString credentialsKey = QgsGeoNodeConnectionUtils::pathGeoNodeConnectionDetails() + QStringLiteral( "/" ) + mConnName;
33 
34  mUri.setParam( QStringLiteral( "url" ), settings.value( key + QStringLiteral( "/url" ), QString() ).toString() );
35 
36  // Check for credentials and prepend to the connection info
37  const QString username = settings.value( credentialsKey + QStringLiteral( "/username" ), QString() ).toString();
38  const QString password = settings.value( credentialsKey + QStringLiteral( "/password" ), QString() ).toString();
39  if ( !username.isEmpty() )
40  {
41  mUri.setUsername( username );
42  mUri.setPassword( password );
43  }
44 
45  const QString authcfg = settings.value( credentialsKey + QStringLiteral( "/authcfg" ), QString() ).toString();
46  if ( !authcfg.isEmpty() )
47  {
48  mUri.setAuthConfigId( authcfg );
49  }
50 
51  QgsDebugMsgLevel( QStringLiteral( "encodedUri: '%1'." ).arg( QString( mUri.encodedUri() ) ), 4 );
52 }
53 
55 {
56  return mUri;
57 }
58 
60 {
61  return mConnName;
62 }
63 
64 void QgsGeoNodeConnection::setConnectionName( const QString &connName )
65 {
66  mConnName = connName;
67 }
68 
70 {
71  mUri = uri;
72 }
73 
75 {
76  return QgsOwsConnection::addWmsWcsConnectionSettings( uri, settingsKey() + QStringLiteral( "/wms" ) );
77 }
78 
80 {
81  return QgsOwsConnection::addWfsConnectionSettings( uri, settingsKey() + QStringLiteral( "/wfs" ) );
82 }
83 
85 {
86  return QgsOwsConnection::addWmsWcsConnectionSettings( uri, settingsKey() + QStringLiteral( "/wcs" ) );
87 }
88 
89 QString QgsGeoNodeConnection::settingsKey() const
90 {
91  return QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/" ) + mConnName;
92 }
93 
94 
95 //
96 // QgsGeoNodeConnectionUtils
97 //
98 
99 
101 {
102  QgsSettings settings;
103  // Add Section manually
104  settings.beginGroup( QStringLiteral( "qgis/connections-geonode" ) );
105  return settings.childGroups();
106 }
107 
109 {
110  QgsOwsConnection::deleteConnection( QStringLiteral( "GEONODE" ), name );
111 }
112 
114 {
115  return sPathGeoNodeConnection;
116 }
117 
119 {
120  return sPathGeoNodeConnectionDetails;
121 }
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.
void setAuthConfigId(const QString &authcfg)
Sets the authentication configuration ID for the URI.
void setUsername(const QString &username)
Sets the username for the URI.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
void setPassword(const QString &password)
Sets the password for the URI.
static QString pathGeoNodeConnectionDetails()
Returns the base path for settings related to GeoNode connection details.
static void deleteConnection(const QString &name)
Deletes the GeoNode connection with matching name.
static QString pathGeoNodeConnection()
Returns the base path for settings related to GeoNode connections.
static QStringList connectionList()
Returns a list of all known GeoNode connection names.
void setUri(const QgsDataSourceUri &uri)
Sets the uri for the GeoNode connection.
QgsDataSourceUri & addWmsConnectionSettings(QgsDataSourceUri &uri) const
Adds uri parameters relating to the settings for a WMS layer on the connection to a QgsDataSourceUri ...
void setConnectionName(const QString &connectionName)
Sets the name of the connection.
QgsDataSourceUri & addWcsConnectionSettings(QgsDataSourceUri &uri) const
Adds uri parameters relating to the settings for a WCS layer on the connection to a QgsDataSourceUri ...
QString connectionName() const
Returns the name of the connection.
QgsDataSourceUri & addWfsConnectionSettings(QgsDataSourceUri &uri) const
Adds uri parameters relating to the settings for a WFS layer on the connection to a QgsDataSourceUri ...
QgsDataSourceUri uri() const
Returns the URI for the GeoNode connection.
QgsGeoNodeConnection(const QString &name)
Constructor for a QgsGeoNodeConnection with the specified name.
static QgsDataSourceUri & addWmsWcsConnectionSettings(QgsDataSourceUri &uri, const QString &settingsKey)
Adds uri parameters relating to the settings for a WMS or WCS connection to a QgsDataSourceUri uri.
static void deleteConnection(const QString &service, const QString &name)
Deletes the connection for the specified service with the specified name.
static QgsDataSourceUri & addWfsConnectionSettings(QgsDataSourceUri &uri, const QString &settingsKey)
Adds uri parameters relating to the settings for a WFS connection to a QgsDataSourceUri uri.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
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.
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
Definition: qgssettings.cpp:89
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39