Skip to content
Permalink
Browse files

wcs cache option

  • Loading branch information
blazek committed Sep 27, 2012
1 parent 45ebedf commit 31776b956951ca477105f4ecfec8e69dabbd99ec
@@ -77,6 +77,11 @@ QgsOWSSourceSelect::QgsOWSSourceSelect( QString service, QWidget * parent, Qt::W
mTileHeightLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );
mFeatureCountLineEdit->setValidator( new QIntValidator( 0, 9999, this ) );

mCacheComboBox->addItem( tr( "Always cache" ), QNetworkRequest::AlwaysCache );
mCacheComboBox->addItem( tr( "Prefer cache" ), QNetworkRequest::PreferCache );
mCacheComboBox->addItem( tr( "Prefer network" ), QNetworkRequest::PreferNetwork );
mCacheComboBox->addItem( tr( "Always network" ), QNetworkRequest::AlwaysNetwork );

mImageFormatGroup = new QButtonGroup;

if ( !mManagerMode )
@@ -538,6 +543,12 @@ QString QgsOWSSourceSelect::selectedFormat()
}
}

QNetworkRequest::CacheLoadControl QgsOWSSourceSelect::selectedCacheLoadControl()
{
int cache = mCacheComboBox->itemData( mCacheComboBox->currentIndex() ).toInt();
return static_cast<QNetworkRequest::CacheLoadControl>( cache );
}

QString QgsOWSSourceSelect::selectedCRS()
{
return mSelectedCRS;
@@ -28,6 +28,7 @@

#include <QStringList>
#include <QPushButton>
#include <QNetworkRequest>

class QgisApp;
class QgsDataProvider;
@@ -210,6 +211,9 @@ class GUI_EXPORT QgsOWSSourceSelect : public QDialog, public Ui::QgsOWSSourceSel
//! Returns currently selected time
QString selectedTime();

//! Returns currently selected cache load control
QNetworkRequest::CacheLoadControl selectedCacheLoadControl();

QList<QTreeWidgetItem*> mCurrentSelection;
QTableWidgetItem* mCurrentTileset;

@@ -27,6 +27,8 @@ Parameters:

* IgnoreAxisOrientation (optional,hack) : If specified (set to 1), do not invert axis orientation according to WCS standard for geographic CRS.

* cache (optional) : cache load control, as described in QNetworkRequest::CacheLoadControl, but request is resend as PreferCache if faild with AlwaysCache. Allowed values: AlwaysCache, PreferCache, PreferNetwork, AlwaysNetwork. Default is AlwaysCache.


Python console example, adds new layer to map canvas:

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

@@ -404,6 +403,28 @@ bool QgsWcsProvider::parseUri( QString uriString )
setCoverageCrs( uri.param( "crs" ) );
}

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;
}
}
QgsDebugMsg( QString( "mCacheLoadControl = %1" ).arg( mCacheLoadControl ) ) ;

return true;
}

@@ -738,7 +759,7 @@ void QgsWcsProvider::getCache( int bandNo, QgsRectangle const & viewExtent, int
QNetworkRequest request( url );
setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, mGetCoverageCacheLoadControl );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, mCacheLoadControl );
mCacheReply = QgsNetworkAccessManager::instance()->get( request );
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
@@ -789,6 +810,7 @@ void QgsWcsProvider::readBlock( int theBandNo, int xBlock, int yBlock, void *blo

void QgsWcsProvider::cacheReplyFinished()
{
QgsDebugMsg( QString( "mCacheReply->error() = %1" ).arg( mCacheReply->error() ) );
if ( mCacheReply->error() == QNetworkReply::NoError )
{
QVariant redirect = mCacheReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
@@ -799,6 +821,7 @@ void QgsWcsProvider::cacheReplyFinished()
QgsDebugMsg( QString( "redirected getmap: %1" ).arg( redirect.toString() ) );
mCacheReply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( redirect.toUrl() ) );
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
return;
}

@@ -1064,6 +1087,21 @@ void QgsWcsProvider::cacheReplyFinished()
}
else
{
// Resend request if AlwaysCache
QNetworkRequest request = mCacheReply->request();
if ( request.attribute( QNetworkRequest::CacheLoadControlAttribute ).toInt() == QNetworkRequest::AlwaysCache )
{
QgsDebugMsg( "Resend request with PreferCache" );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );

mCacheReply->deleteLater();

mCacheReply = QgsNetworkAccessManager::instance()->get( request );
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
return;
}

mErrors++;
if ( mErrors < 100 )
{
@@ -422,7 +422,7 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
// Fix for rasters rotated by GeoServer
bool mFixRotate;

QNetworkRequest::CacheLoadControl mGetCoverageCacheLoadControl;
QNetworkRequest::CacheLoadControl mCacheLoadControl;
};


@@ -150,6 +150,28 @@ void QgsWCSSourceSelect::addClicked( )
uri.setParam( "time", selectedTime() );
}

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;
}
uri.setParam( "cache", cache );

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

0 comments on commit 31776b9

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