QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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  QgsSettings settings;
29 
30 // settings.Section
31  QString key = settingsKey();
32  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  QString username = settings.value( credentialsKey + QStringLiteral( "/username" ), QString() ).toString();
38  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  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 
84 QString QgsGeoNodeConnection::settingsKey() const
85 {
86  return QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/" ) + mConnName;
87 }
88 
89 
90 //
91 // QgsGeoNodeConnectionUtils
92 //
93 
94 
96 {
97  QgsSettings settings;
98  // Add Section manually
99  settings.beginGroup( QStringLiteral( "qgis/connections-geonode" ) );
100  return settings.childGroups();
101 }
102 
104 {
105  QgsOwsConnection::deleteConnection( QStringLiteral( "GEONODE" ), name );
106 }
107 
109 {
110  return sPathGeoNodeConnection;
111 }
112 
114 {
115  return sPathGeoNodeConnectionDetails;
116 }
QgsDataSourceUri
Class for storing the component parts of a RDBMS data source URI (e.g.
Definition: qgsdatasourceuri.h:36
QgsGeoNodeConnectionUtils::deleteConnection
static void deleteConnection(const QString &name)
Deletes the GeoNode connection with matching name.
Definition: qgsgeonodeconnection.cpp:103
QgsSettings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
Definition: qgssettings.cpp:174
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsGeoNodeConnection::setConnectionName
void setConnectionName(const QString &connectionName)
Sets the name of the connection.
Definition: qgsgeonodeconnection.cpp:64
qgsowsconnection.h
QgsGeoNodeConnectionUtils::pathGeoNodeConnection
static QString pathGeoNodeConnection()
Returns the base path for settings related to GeoNode connections.
Definition: qgsgeonodeconnection.cpp:108
QgsSettings
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
QgsGeoNodeConnection::addWfsConnectionSettings
QgsDataSourceUri & addWfsConnectionSettings(QgsDataSourceUri &uri) const
Adds uri parameters relating to the settings for a WFS layer on the connection to a QgsDataSourceUri ...
Definition: qgsgeonodeconnection.cpp:79
QgsOwsConnection::addWfsConnectionSettings
static QgsDataSourceUri & addWfsConnectionSettings(QgsDataSourceUri &uri, const QString &settingsKey)
Adds uri parameters relating to the settings for a WFS connection to a QgsDataSourceUri uri.
Definition: qgsowsconnection.cpp:143
QgsGeoNodeConnectionUtils::connectionList
static QStringList connectionList()
Returns a list of all known GeoNode connection names.
Definition: qgsgeonodeconnection.cpp:95
QgsGeoNodeConnection::setUri
void setUri(const QgsDataSourceUri &uri)
Sets the uri for the GeoNode connection.
Definition: qgsgeonodeconnection.cpp:69
QgsDataSourceUri::setUsername
void setUsername(const QString &username)
Sets the username for the URI.
Definition: qgsdatasourceuri.cpp:264
qgsdatasourceuri.h
QgsOwsConnection::deleteConnection
static void deleteConnection(const QString &service, const QString &name)
Deletes the connection for the specified service with the specified name.
Definition: qgsowsconnection.cpp:196
QgsDataSourceUri::setAuthConfigId
void setAuthConfigId(const QString &authcfg)
Sets the authentication configuration ID for the URI.
Definition: qgsdatasourceuri.cpp:716
QgsGeoNodeConnectionUtils::pathGeoNodeConnectionDetails
static QString pathGeoNodeConnectionDetails()
Returns the base path for settings related to GeoNode connection details.
Definition: qgsgeonodeconnection.cpp:113
QgsOwsConnection::addWmsWcsConnectionSettings
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.
Definition: qgsowsconnection.cpp:108
QgsDataSourceUri::setParam
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
Definition: qgsdatasourceuri.cpp:778
qgsgeonodeconnection.h
QgsGeoNodeConnection::uri
QgsDataSourceUri uri() const
Returns the URI for the GeoNode connection.
Definition: qgsgeonodeconnection.cpp:54
QgsDataSourceUri::encodedUri
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
Definition: qgsdatasourceuri.cpp:610
QgsSettings::beginGroup
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
Definition: qgssettings.cpp:87
qgssettings.h
QgsGeoNodeConnection::connectionName
QString connectionName() const
Returns the name of the connection.
Definition: qgsgeonodeconnection.cpp:59
qgslogger.h
QgsGeoNodeConnection::QgsGeoNodeConnection
QgsGeoNodeConnection(const QString &name)
Constructor for a QgsGeoNodeConnection with the specified name.
Definition: qgsgeonodeconnection.cpp:25
QgsGeoNodeConnection::addWmsConnectionSettings
QgsDataSourceUri & addWmsConnectionSettings(QgsDataSourceUri &uri) const
Adds uri parameters relating to the settings for a WMS layer on the connection to a QgsDataSourceUri ...
Definition: qgsgeonodeconnection.cpp:74
QgsDataSourceUri::setPassword
void setPassword(const QString &password)
Sets the password for the URI.
Definition: qgsdatasourceuri.cpp:289
QgsSettings::childGroups
QStringList childGroups() const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
Definition: qgssettings.cpp:144