QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgsowsconnection.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsowsconnection.cpp - selector for WMS servers, etc.
3  -------------------
4  begin : 3 April 2005
5  copyright :
6  original : (C) 2005 by Brendan Morley email : morb at ozemail dot com dot au
7  wms search : (C) 2009 Mathias Walker <mwa at sourcepole.ch>, Sourcepole AG
8  wms-c support : (C) 2010 Juergen E. Fischer < jef at norbit dot de >, norBIT GmbH
9  generalized : (C) 2012 Radim Blazek, based on qgswmsconnection.cpp
10 
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #include "qgis.h" // GEO_EPSG_CRS_ID
23 #include "qgsdatasourceuri.h"
24 #include "qgslogger.h"
25 #include "qgsproject.h"
26 #include "qgsproviderregistry.h"
27 #include "qgsowsconnection.h"
28 
29 #include <QInputDialog>
30 #include <QMessageBox>
31 #include <QPicture>
32 #include <QSettings>
33 #include <QUrl>
34 
35 #include <QNetworkRequest>
36 #include <QNetworkReply>
37 
38 QgsOWSConnection::QgsOWSConnection( const QString & theService, const QString & theConnName )
39  : mConnName( theConnName )
40  , mService( theService )
41 {
42  QgsDebugMsg( "theConnName = " + theConnName );
43 
44  QSettings settings;
45 
46  QString key = "/Qgis/connections-" + mService.toLower() + '/' + mConnName;
47  QString credentialsKey = "/Qgis/" + mService + '/' + mConnName;
48 
49  QStringList connStringParts;
50 
51  mConnectionInfo = settings.value( key + "/url" ).toString();
52  mUri.setParam( "url", settings.value( key + "/url" ).toString() );
53 
54  // Check for credentials and prepend to the connection info
55  QString username = settings.value( credentialsKey + "/username" ).toString();
56  QString password = settings.value( credentialsKey + "/password" ).toString();
57  if ( !username.isEmpty() )
58  {
59  // check for a password, if none prompt to get it
60  mUri.setParam( "username", username );
61  mUri.setParam( "password", password );
62  }
63 
64  QString authcfg = settings.value( credentialsKey + "/authcfg" ).toString();
65  if ( !authcfg.isEmpty() )
66  {
67  mUri.setParam( "authcfg", authcfg );
68  }
69  mConnectionInfo.append( ",authcfg=" + authcfg );
70 
71  bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
72  bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
73  bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();
74  bool invertAxisOrientation = settings.value( key + "/invertAxisOrientation", false ).toBool();
75  if ( ignoreGetMap )
76  {
77  mUri.setParam( "IgnoreGetMapUrl", "1" );
78  }
79  if ( ignoreGetFeatureInfo )
80  {
81  mUri.setParam( "IgnoreGetFeatureInfoUrl", "1" );
82  }
83  if ( ignoreAxisOrientation )
84  {
85  mUri.setParam( "IgnoreAxisOrientation", "1" );
86  }
87  if ( invertAxisOrientation )
88  {
89  mUri.setParam( "InvertAxisOrientation", "1" );
90  }
91 
92  QgsDebugMsg( QString( "encoded uri: '%1'." ).arg( QString( mUri.encodedUri() ) ) );
93 }
94 
96 {
97 
98 }
99 
101 {
102  return mConnectionInfo;
103 }
104 
106 {
107  return mUri;
108 }
109 
111 {
112  QSettings settings;
113  settings.beginGroup( "/Qgis/connections-" + theService.toLower() );
114  return settings.childGroups();
115 }
116 
118 {
119  QSettings settings;
120  return settings.value( "/Qgis/connections-" + theService.toLower() + "/selected" ).toString();
121 }
122 
123 void QgsOWSConnection::setSelectedConnection( const QString & theService, const QString & name )
124 {
125  QSettings settings;
126  settings.setValue( "/Qgis/connections-" + theService.toLower() + "/selected", name );
127 }
128 
129 void QgsOWSConnection::deleteConnection( const QString & theService, const QString & name )
130 {
131  QSettings settings;
132  settings.remove( "/Qgis/connections-" + theService.toLower() + '/' + name );
133  settings.remove( "/Qgis/" + theService + '/' + name );
134 }
QString & append(QChar ch)
static QString selectedConnection(const QString &theService)
Retreives the selected connection for the specified service.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
static QStringList connectionList(const QString &theService)
Returns the list of connections for the specified service.
QgsOWSConnection(const QString &theService, const QString &theConnName)
Constructor.
static void setSelectedConnection(const QString &theService, const QString &name)
Marks the specified connection for the specified service as selected.
void setValue(const QString &key, const QVariant &value)
const char * name() const
static void deleteConnection(const QString &theService, const QString &name)
Deletes the connection for the specified service with the specified name.
void setParam(const QString &key, const QString &value)
Set generic param (generic mode)
bool isEmpty() const
QStringList childGroups() const
Q_DECL_DEPRECATED QString connectionInfo()
QString toLower() const
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
void remove(const QString &key)
QByteArray encodedUri() const
return complete encoded uri (generic mode)
QVariant value(const QString &key, const QVariant &defaultValue) const
bool toBool() const
~QgsOWSConnection()
Destructor.
QString toString() const
QgsDataSourceURI mUri
void beginGroup(const QString &prefix)
QgsDataSourceURI uri() const
Returns the connection uri.