Skip to content

Commit

Permalink
Remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 12, 2017
1 parent 42869bb commit 51922fc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 87 deletions.
19 changes: 17 additions & 2 deletions src/core/qgsowsconnection.cpp
Expand Up @@ -45,8 +45,6 @@ QgsOwsConnection::QgsOwsConnection( const QString &service, const QString &connN
QString key = "qgis/connections-" + mService.toLower() + '/' + mConnName;
QString credentialsKey = "qgis/" + mService + '/' + mConnName;

QStringList connStringParts;

mConnectionInfo = settings.value( key + "/url" ).toString();
mUri.setParam( QStringLiteral( "url" ), settings.value( key + "/url" ).toString() );

Expand All @@ -67,10 +65,19 @@ QgsOwsConnection::QgsOwsConnection( const QString &service, const QString &connN
}
mConnectionInfo.append( ",authcfg=" + authcfg );

QString referer = settings.value( key + "/referer" ).toString();
if ( !referer.isEmpty() )
{
mUri.setParam( QStringLiteral( "referer" ), referer );
}

bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();
bool invertAxisOrientation = settings.value( key + "/invertAxisOrientation", false ).toBool();
bool smoothPixmapTransform = settings.value( key + "/smoothPixmapTransform", false ).toBool();
QString dpiMode = settings.value( key + "/dpiMode", "all" ).toString();

if ( ignoreGetMap )
{
mUri.setParam( QStringLiteral( "IgnoreGetMapUrl" ), QStringLiteral( "1" ) );
Expand All @@ -87,6 +94,14 @@ QgsOwsConnection::QgsOwsConnection( const QString &service, const QString &connN
{
mUri.setParam( QStringLiteral( "InvertAxisOrientation" ), QStringLiteral( "1" ) );
}
if ( smoothPixmapTransform )
{
mUri.setParam( QStringLiteral( "SmoothPixmapTransform" ), QStringLiteral( "1" ) );
}
if ( !dpiMode.isEmpty() )
{
mUri.setParam( QStringLiteral( "dpiMode" ), dpiMode );
}

QgsDebugMsg( QString( "encoded uri: '%1'." ).arg( QString( mUri.encodedUri() ) ) );
}
Expand Down
1 change: 0 additions & 1 deletion src/providers/wms/CMakeLists.txt
Expand Up @@ -12,7 +12,6 @@ SET (WMS_SRCS
SET (WMS_MOC_HDRS
qgswmscapabilities.h
qgswmsprovider.h
qgswmsconnection.h
qgswmsdataitems.h
)

Expand Down
78 changes: 2 additions & 76 deletions src/providers/wms/qgswmsconnection.cpp
Expand Up @@ -26,92 +26,18 @@
#include "qgswmsconnection.h"
#include "qgsnetworkaccessmanager.h"
#include "qgssettings.h"
#include "qgsowsconnection.h"

QgsWMSConnection::QgsWMSConnection( const QString &connName )
: mConnName( connName )
: QgsOwsConnection( QStringLiteral( "WMS" ), connName )
{
QgsDebugMsg( "theConnName = " + connName );

QgsSettings settings;

QString key = "qgis/connections-wms/" + mConnName;
QString credentialsKey = "qgis/WMS/" + mConnName;

QStringList connStringParts;

mUri.setParam( QStringLiteral( "url" ), settings.value( key + "/url" ).toString() );

// Check for credentials and prepend to the connection info
QString username = settings.value( credentialsKey + "/username" ).toString();
QString password = settings.value( credentialsKey + "/password" ).toString();
if ( !username.isEmpty() )
{
mUri.setParam( QStringLiteral( "username" ), username );
mUri.setParam( QStringLiteral( "password" ), password );
}

QString authcfg = settings.value( credentialsKey + "/authcfg" ).toString();
if ( !authcfg.isEmpty() )
{
mUri.setParam( QStringLiteral( "authcfg" ), authcfg );
}

QString referer = settings.value( key + "/referer" ).toString();
if ( !referer.isEmpty() )
{
mUri.setParam( QStringLiteral( "referer" ), referer );
}

bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();
bool invertAxisOrientation = settings.value( key + "/invertAxisOrientation", false ).toBool();
bool smoothPixmapTransform = settings.value( key + "/smoothPixmapTransform", false ).toBool();
QString dpiMode = settings.value( key + "/dpiMode", "all" ).toString();

if ( ignoreGetMap )
{
mUri.setParam( QStringLiteral( "IgnoreGetMapUrl" ), QStringLiteral( "1" ) );
}

if ( ignoreGetFeatureInfo )
{
mUri.setParam( QStringLiteral( "IgnoreGetFeatureInfoUrl" ), QStringLiteral( "1" ) );
}

if ( ignoreAxisOrientation )
{
mUri.setParam( QStringLiteral( "IgnoreAxisOrientation" ), QStringLiteral( "1" ) );
}

if ( invertAxisOrientation )
{
mUri.setParam( QStringLiteral( "InvertAxisOrientation" ), QStringLiteral( "1" ) );
}

if ( smoothPixmapTransform )
{
mUri.setParam( QStringLiteral( "SmoothPixmapTransform" ), QStringLiteral( "1" ) );
}

if ( !dpiMode.isEmpty() )
{
mUri.setParam( QStringLiteral( "dpiMode" ), dpiMode );
}

QgsDebugMsg( QString( "encodedUri: '%1'." ).arg( QString( mUri.encodedUri() ) ) );
}

QgsWMSConnection::~QgsWMSConnection()
{

}

QgsDataSourceUri QgsWMSConnection::uri()
{
return mUri;
}

QStringList QgsWMSConnection::connectionList()
{
QgsSettings settings;
Expand Down
10 changes: 2 additions & 8 deletions src/providers/wms/qgswmsconnection.h
Expand Up @@ -18,16 +18,14 @@
#ifndef QGSWMSCONNECTION_H
#define QGSWMSCONNECTION_H

#include "qgsdatasourceuri.h"

#include "qgsowsconnection.h"
#include <QStringList>

/*!
* \brief Connections management
*/
class QgsWMSConnection : public QObject
class QgsWMSConnection : public QgsOwsConnection
{
Q_OBJECT

public:
//! Constructor
Expand All @@ -42,10 +40,6 @@ class QgsWMSConnection : public QObject
static QString selectedConnection();
static void setSelectedConnection( const QString &name );

public:
QString mConnName;
QgsDataSourceUri uri();
QgsDataSourceUri mUri;
};

#endif // QGSWMSCONNECTION_H

0 comments on commit 51922fc

Please sign in to comment.