Skip to content
Permalink
Browse files
Potential fix for trac-ticket #8.
* Propagate proxy information from the Server Selection dialog to the WMS provider (used by the QgsRasterLayer).

Possible bonus feature:

* Proxy information is saved and restored from the project file.

I cannot test this locally, so would appreciate somebody else giving it a go.



git-svn-id: http://svn.osgeo.org/qgis/trunk@5716 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
morb_au committed Aug 21, 2006
1 parent d04ea69 commit 18d2744935692239830d26226733ec57eb0ed703
Showing with 128 additions and 8 deletions.
  1. +22 −0 src/core/qgsrasterdataprovider.h
  2. +25 −0 src/providers/wms/qgswmsprovider.cpp
  3. +20 −0 src/providers/wms/qgswmsprovider.h
  4. +49 −4 src/raster/qgsrasterlayer.cpp
  5. +12 −4 src/raster/qgsrasterlayer.h
@@ -61,6 +61,28 @@ class QgsRasterDataProvider : public QgsDataProvider

virtual ~QgsRasterDataProvider() {};


/**
* Gets the HTTP proxy host used for this connection
*/
virtual QString proxyHost() const = 0;

/**
* Gets the HTTP proxy port used for this connection
*/
virtual int proxyPort() const = 0;

/**
* Gets the HTTP proxy user name used for this connection
*/
virtual QString proxyUser() const = 0;

/**
* Gets the HTTP proxy user password used for this connection
*/
virtual QString proxyPass() const = 0;


/**
*
* Sets a proxy for the URL given in the constructor
@@ -146,6 +146,31 @@ QgsWmsProvider::~QgsWmsProvider()

}


QString QgsWmsProvider::proxyHost() const
{
return mHttpProxyHost;
}


int QgsWmsProvider::proxyPort() const
{
return mHttpProxyPort;
}


QString QgsWmsProvider::proxyUser() const
{
return mHttpProxyUser;
}


QString QgsWmsProvider::proxyPass() const
{
return mHttpProxyPass;
}


bool QgsWmsProvider::setProxy(QString const & host,
int port,
QString const & user,
@@ -356,6 +356,26 @@ class QgsWmsProvider : public QgsRasterDataProvider
//! Destructor
virtual ~QgsWmsProvider();

/**
* Gets the HTTP proxy host used for this connection
*/
virtual QString proxyHost() const;

/**
* Gets the HTTP proxy port used for this connection
*/
virtual int proxyPort() const;

/**
* Gets the HTTP proxy user name used for this connection
*/
virtual QString proxyUser() const;

/**
* Gets the HTTP proxy user password used for this connection
*/
virtual QString proxyPass() const;

/**
*
* Sets an HTTP proxy for the URL given in the constructor
@@ -4533,7 +4533,14 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
QString crs = QString("EPSG:%1")
.arg(mCoordinateTransform->sourceSRS().epsg());

setDataProvider( mProviderKey, layers, styles, format, crs );
// Collect proxy information
QString proxyHost = rpNode.namedItem("wmsProxyHost").toElement().text();
int proxyPort = rpNode.namedItem("wmsProxyPort").toElement().text().toInt();
QString proxyUser = rpNode.namedItem("wmsProxyUser").toElement().text();
QString proxyPass = rpNode.namedItem("wmsProxyPass").toElement().text();

setDataProvider( mProviderKey, layers, styles, format, crs,
proxyHost, proxyPort, proxyUser, proxyPass );
}
else
{
@@ -4668,6 +4675,34 @@ bool QgsRasterLayer::readXML_( QDomNode & layer_node )
document.createTextNode(dataProvider->imageEncoding());
formatElement.appendChild(formatText);
rasterPropertiesElement.appendChild(formatElement);

// <rasterproperties><wmsProxyHost>
QDomElement proxyHostElement = document.createElement("wmsProxyHost");
QDomText proxyHostText =
document.createTextNode(dataProvider->proxyHost());
proxyHostElement.appendChild(proxyHostText);
rasterPropertiesElement.appendChild(proxyHostElement);

// <rasterproperties><wmsProxyPort>
QDomElement proxyPortElement = document.createElement("wmsProxyPort");
QDomText proxyPortText =
document.createTextNode( QString::number(dataProvider->proxyPort()) );
proxyPortElement.appendChild(proxyPortText);
rasterPropertiesElement.appendChild(proxyPortElement);

// <rasterproperties><wmsProxyUser>
QDomElement proxyUserElement = document.createElement("wmsProxyUser");
QDomText proxyUserText =
document.createTextNode(dataProvider->proxyUser());
proxyUserElement.appendChild(proxyUserText);
rasterPropertiesElement.appendChild(proxyUserElement);

// <rasterproperties><wmsProxyPass>
QDomElement proxyPassElement = document.createElement("wmsProxyPass");
QDomText proxyPassText =
document.createTextNode(dataProvider->proxyPass());
proxyPassElement.appendChild(proxyPassText);
rasterPropertiesElement.appendChild(proxyPassElement);
}

// <showDebugOverlayFlag>
@@ -4903,7 +4938,11 @@ QgsRasterLayer::QgsRasterLayer(int dummy,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs )
QString const & crs,
QString const & proxyHost,
int proxyPort,
QString const & proxyUser,
QString const & proxyPass )
: QgsMapLayer(RASTER, baseName, rasterLayerPath),
rasterXDimInt( std::numeric_limits<int>::max() ),
rasterYDimInt( std::numeric_limits<int>::max() ),
@@ -4933,7 +4972,8 @@ QgsRasterLayer::QgsRasterLayer(int dummy,
// if we're given a provider type, try to create and bind one to this layer
if ( ! providerKey.isEmpty() )
{
setDataProvider( providerKey, layers, styles, format, crs );
setDataProvider( providerKey, layers, styles, format, crs,
proxyHost, proxyPort, proxyUser, proxyPass );
}

// Default for the popup menu
@@ -4972,7 +5012,11 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs )
QString const & crs,
QString const & proxyHost,
int proxyPort,
QString const & proxyUser,
QString const & proxyPass )
{
// XXX should I check for and possibly delete any pre-existing providers?
// XXX How often will that scenario occur?
@@ -5039,6 +5083,7 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
dataProvider->addLayers(layers, styles);
dataProvider->setImageEncoding(format);
dataProvider->setImageCrs(crs);
dataProvider->setProxy(proxyHost, proxyPort, proxyUser, proxyPass);

// get the extent
QgsRect *mbr = dataProvider->extent();
@@ -18,8 +18,8 @@

/** \file qgsrasterlayer.h
* \brief This class provides qgis with the ability to render raster datasets
* onto the mapcanvas..
*
* onto the mapcanvas
*
* The qgsrasterlayer class makes use of gdal for data io, and thus supports
* any gdal supported format. The constructor attemtps to infer what type of
* file (RASTER_LAYER_TYPE) is being opened - not in terms of the file format (tif, ascii grid etc.)
@@ -1061,13 +1061,21 @@ public slots:
QStringList const & layers = QStringList(),
QStringList const & styles = QStringList(),
QString const & format = QString(),
QString const & crs = QString());
QString const & crs = QString(),
QString const & proxyHost = QString(),
int proxyPort = 80,
QString const & proxyUser = QString(),
QString const & proxyPass = QString());

void setDataProvider( QString const & provider,
QStringList const & layers,
QStringList const & styles,
QString const & format,
QString const & crs );
QString const & crs,
QString const & proxyHost,
int proxyPort,
QString const & proxyUser,
QString const & proxyPass );

//! Does this layer use a provider for setting/retrieving data?
bool usesProvider();

0 comments on commit 18d2744

Please sign in to comment.