Skip to content

Commit

Permalink
wcs cache option
Browse files Browse the repository at this point in the history
  • Loading branch information
blazek committed Sep 27, 2012
1 parent 45ebedf commit 31776b9
Show file tree
Hide file tree
Showing 9 changed files with 259 additions and 162 deletions.
11 changes: 11 additions & 0 deletions src/gui/qgsowssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsowssourceselect.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

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

class QgisApp;
class QgsDataProvider;
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/providers/wcs/URI
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
44 changes: 41 additions & 3 deletions src/providers/wcs/qgswcsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "'." );

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 ) ) );
Expand Down Expand Up @@ -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 );
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 )
{
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wcs/qgswcsprovider.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
// Fix for rasters rotated by GeoServer
bool mFixRotate;

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


Expand Down
22 changes: 22 additions & 0 deletions src/providers/wcs/qgswcssourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
}

Expand Down
Loading

0 comments on commit 31776b9

Please sign in to comment.