Skip to content
Permalink
Browse files

wcs capabilities cache, fix extent verification

  • Loading branch information
blazek committed Oct 3, 2012
1 parent 2b5f754 commit d2a54d525ce9f6e8e67094229bad258ef33f6595
@@ -2,6 +2,7 @@ class QgsSymbolLayerV2
{
%TypeHeaderCode
#include <qgssymbollayerv2.h>
#include <qgslinesymbollayerv2.h>
%End

%ConvertToSubClassCode
@@ -169,7 +169,7 @@ inline bool doubleNearSig( double a, double b, int significantDigits = 10 )
double br = frexp( b, &bexp );

return aexp == bexp &&
ceil( ar * pow( 10.0, significantDigits ) ) == ceil( br * pow( 10.0, significantDigits ) ) ;
qRound( ar * pow( 10.0, significantDigits ) ) == qRound( br * pow( 10.0, significantDigits ) ) ;
}

/** Wkt string that represents a geographic coord sys
@@ -153,3 +153,46 @@ void QgsNetworkAccessManager::abortRequest()

reply->abort();
}

QString QgsNetworkAccessManager::cacheLoadControlName( QNetworkRequest::CacheLoadControl theControl )
{
switch ( theControl )
{
case QNetworkRequest::AlwaysNetwork:
return "AlwaysNetwork";
break;
case QNetworkRequest::PreferNetwork:
return "PreferNetwork";
break;
case QNetworkRequest::PreferCache:
return "PreferCache";
break;
case QNetworkRequest::AlwaysCache:
return "AlwaysCache";
break;
default:
break;
}
return "PreferNetwork";
}

QNetworkRequest::CacheLoadControl QgsNetworkAccessManager::cacheLoadControlFromName( const QString &theName )
{
if ( theName == "AlwaysNetwork" )
{
return QNetworkRequest::AlwaysNetwork;
}
else if ( theName == "PreferNetwork" )
{
return QNetworkRequest::PreferNetwork;
}
else if ( theName == "PreferCache" )
{
return QNetworkRequest::PreferCache;
}
else if ( theName == "AlwaysCache" )
{
return QNetworkRequest::AlwaysCache;
}
return QNetworkRequest::PreferNetwork;
}
@@ -22,6 +22,7 @@
#include <QStringList>
#include <QNetworkAccessManager>
#include <QNetworkProxy>
#include <QNetworkRequest>

/*
* \class QgsNetworkAccessManager
@@ -72,6 +73,12 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
//! set fallback proxy and URL that shouldn't use it.
void setFallbackProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes );

//! Get name for QNetworkRequest::CacheLoadControl
static QString cacheLoadControlName( QNetworkRequest::CacheLoadControl theControl );

//! Get QNetworkRequest::CacheLoadControl from name
static QNetworkRequest::CacheLoadControl cacheLoadControlFromName( const QString &theName );

signals:
void requestAboutToBeCreated( QNetworkAccessManager::Operation, const QNetworkRequest &, QIODevice * );
void requestCreated( QNetworkReply * );
@@ -67,10 +67,13 @@

QgsWcsCapabilities::QgsWcsCapabilities( QgsDataSourceURI const &theUri ):
mUri( theUri ),
mCoverageCount( 0 )
mCoverageCount( 0 ),
mCacheLoadControl( QNetworkRequest::PreferNetwork )
{
QgsDebugMsg( "uri = " + mUri.encodedUri() );

parseUri();

retrieveServerCapabilities();
}

@@ -84,12 +87,29 @@ QgsWcsCapabilities::~QgsWcsCapabilities()
QgsDebugMsg( "deconstructing." );
}

void QgsWcsCapabilities::parseUri()
{
mCacheLoadControl = QNetworkRequest::PreferNetwork;

QString cache = mUri.param( "cache" );
QgsDebugMsg( "cache = " + cache );

if ( !cache.isEmpty() )
{
mCacheLoadControl = QgsNetworkAccessManager::cacheLoadControlFromName( cache );
}
QgsDebugMsg( QString( "mCacheLoadControl = %1" ).arg( mCacheLoadControl ) );
}

// TODO: return if successful
void QgsWcsCapabilities::setUri( QgsDataSourceURI const &theUri )
{
mUri = theUri;

clear();

parseUri();

retrieveServerCapabilities( );
}

@@ -116,12 +136,6 @@ bool QgsWcsCapabilities::supportedCoverages( QVector<QgsWcsCoverageSummary> &cov
{
QgsDebugMsg( "Entering." );

// Allow the provider to collect the capabilities first.
if ( !retrieveServerCapabilities() )
{
return false;
}

coverageSummary = mCoveragesSupported;

QgsDebugMsg( "Exiting." );
@@ -145,8 +159,9 @@ bool QgsWcsCapabilities::sendRequest( QString const & url )
mError = "";
QNetworkRequest request( url );
setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, mCacheLoadControl );
QgsDebugMsg( QString( "mCacheLoadControl = %1" ).arg( mCacheLoadControl ) );

QgsDebugMsg( QString( "getcapabilities: %1" ).arg( url ) );
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
@@ -181,6 +196,7 @@ bool QgsWcsCapabilities::sendRequest( QString const & url )

void QgsWcsCapabilities::clear()
{
QgsDebugMsg( "Entered" );
mCoverageCount = 0;
mCoveragesSupported.clear();
QgsWcsCapabilitiesProperty c;
@@ -216,6 +232,7 @@ QString QgsWcsCapabilities::getCapabilitiesUrl( ) const
bool QgsWcsCapabilities::retrieveServerCapabilities( )
{
clear();

QStringList versions;

QString preferredVersion = mUri.param( "version" );
@@ -365,6 +382,21 @@ void QgsWcsCapabilities::capabilitiesReplyFinished()
}
else
{
// Resend request if AlwaysCache
QNetworkRequest request = mCapabilitiesReply->request();
if ( request.attribute( QNetworkRequest::CacheLoadControlAttribute ).toInt() == QNetworkRequest::AlwaysCache )
{
QgsDebugMsg( "Resend request with PreferCache" );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );

mCapabilitiesReply->deleteLater();

mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) );
return;
}

mErrorFormat = "text/plain";
mError = tr( "Download of capabilities failed: %1" ).arg( mCapabilitiesReply->errorString() );
QgsMessageLog::logMessage( mError, tr( "WCS" ) );
@@ -27,12 +27,12 @@
#include <QStringList>
#include <QDomElement>
#include <QMap>
#include <QNetworkRequest>
#include <QVector>
#include <QUrl>

class QNetworkAccessManager;
class QNetworkReply;
class QNetworkRequest;

/** CoverageSummary structure */
struct QgsWcsCoverageSummary
@@ -216,6 +216,8 @@ class QgsWcsCapabilities : public QObject
void capabilitiesReplyProgress( qint64, qint64 );

private:
void parseUri();

//! Get coverage summary for identifier
QgsWcsCoverageSummary * coverageSummary( QString const & theIdentifier, QgsWcsCoverageSummary* parent = 0 );

@@ -326,6 +328,9 @@ class QgsWcsCapabilities : public QObject

//! Password for basic http authentication
QString mPassword;

//! Cache load control
QNetworkRequest::CacheLoadControl mCacheLoadControl;
};


@@ -91,7 +91,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
, mPassword( QString::null )
, mFixBox( false )
, mFixRotate( false )
, mCacheLoadControl( QNetworkRequest::PreferCache )
, mCacheLoadControl( QNetworkRequest::PreferNetwork )
{
QgsDebugMsg( "constructing with uri '" + mHttpUri + "'." );

@@ -407,22 +407,7 @@ bool QgsWcsProvider::parseUri( QString uriString )
QString cache = uri.param( "cache" );
if ( !cache.isEmpty() )
{
if ( cache.compare( "AlwaysCache", Qt::CaseInsensitive ) == 0 )
{
mCacheLoadControl = QNetworkRequest::AlwaysCache;
}
else if ( cache.compare( "PreferCache", Qt::CaseInsensitive ) == 0 )
{
mCacheLoadControl = QNetworkRequest::PreferCache;
}
else if ( cache.compare( "PreferNetwork", Qt::CaseInsensitive ) == 0 )
{
mCacheLoadControl = QNetworkRequest::PreferNetwork;
}
else if ( cache.compare( "AlwaysNetwork", Qt::CaseInsensitive ) == 0 )
{
mCacheLoadControl = QNetworkRequest::AlwaysNetwork;
}
mCacheLoadControl = QgsNetworkAccessManager::cacheLoadControlFromName( cache );
}
QgsDebugMsg( QString( "mCacheLoadControl = %1" ).arg( mCacheLoadControl ) ) ;

@@ -19,6 +19,7 @@
#include "qgis.h"
#include "qgslogger.h"

#include "qgsnetworkaccessmanager.h"
#include "qgswcsprovider.h"
#include "qgswcssourceselect.h"
#include "qgswcscapabilities.h"
@@ -61,7 +62,12 @@ void QgsWCSSourceSelect::populateLayerList( )

mLayersTreeWidget->clear();

mCapabilities.setUri( mUri );

QgsDataSourceURI uri = mUri;
QString cache = QgsNetworkAccessManager::cacheLoadControlName( selectedCacheLoadControl() );
uri.setParam( "cache", cache );

mCapabilities.setUri( uri );

if ( !mCapabilities.lastError().isEmpty() )
{
@@ -152,24 +158,7 @@ void QgsWCSSourceSelect::addClicked( )

QString cache;
QgsDebugMsg( QString( "selectedCacheLoadControl = %1" ).arg( selectedCacheLoadControl() ) );
switch ( selectedCacheLoadControl() )
{
case QNetworkRequest::AlwaysCache:
cache = "AlwaysCache";
break;
case QNetworkRequest::PreferCache:
cache = "PreferCache";
break;
case QNetworkRequest::PreferNetwork:
cache = "PreferNetwork";
break;
case QNetworkRequest::AlwaysNetwork:
cache = "AlwaysNetwork";
break;
default:
cache = "PreferCache";
break;
}
cache = QgsNetworkAccessManager::cacheLoadControlName( selectedCacheLoadControl() );
uri.setParam( "cache", cache );

emit addRasterLayer( uri.encodedUri(), identifier, "wcs" );

0 comments on commit d2a54d5

Please sign in to comment.
You can’t perform that action at this time.