Skip to content
Permalink
Browse files

WCS: quick and dirty way to get it working

  • Loading branch information
wonder-sk committed Jan 9, 2014
1 parent 3687ac1 commit 1b7c79432c5d2b136abbcfe2162640f907817772
Showing with 49 additions and 35 deletions.
  1. +44 −32 src/providers/wcs/qgswcsprovider.cpp
  2. +5 −3 src/providers/wcs/qgswcsprovider.h
@@ -21,9 +21,6 @@

#include <typeinfo>

// time to wait for an answer without emitting dataChanged()
#define WCS_THRESHOLD 200

#include "qgslogger.h"
#include "qgswcsprovider.h"
#include "qgscoordinatetransform.h"
@@ -108,6 +105,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
, mFixBox( false )
, mFixRotate( false )
, mCacheLoadControl( QNetworkRequest::PreferNetwork )
, mNAM( 0 )
{
QgsDebugMsg( "constructing with uri '" + mHttpUri + "'." );

@@ -467,6 +465,8 @@ QgsWcsProvider::~QgsWcsProvider()
mCacheReply->deleteLater();
mCacheReply = 0;
}

delete mNAM;
}

QgsRasterInterface * QgsWcsProvider::clone() const
@@ -538,7 +538,7 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
if ( mCacheReply )
{
mCacheReply->abort();
delete mCacheReply;
mCacheReply->deleteLater();
mCacheReply = 0;
}

@@ -791,26 +791,18 @@ void QgsWcsProvider::getCache( int bandNo, QgsRectangle const & viewExtent, int
setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
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 ) ) );

emit statusChanged( tr( "Getting map via WCS." ) );

mWaiting = true;

QTime t;
t.start();
mCacheReply = nam()->get( request );
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ), Qt::DirectConnection );
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );

QSettings s;
bool bkLayerCaching = s.value( "/qgis/enable_render_caching", false ).toBool();
emit statusChanged( tr( "Getting map via WCS." ) );

while ( mCacheReply && ( !bkLayerCaching || t.elapsed() < WCS_THRESHOLD ) )
{
QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents, WCS_THRESHOLD );
}
mWaiting = false;
QEventLoop loop;
connect( mCacheReply, SIGNAL( finished() ), &loop, SLOT( quit() ) );
loop.exec();

Q_ASSERT( mCacheReply == 0 );
}

// For stats only, maybe change QgsRasterDataProvider::bandStatistics() to
@@ -850,9 +842,14 @@ void QgsWcsProvider::cacheReplyFinished()
mCacheReply->deleteLater();

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 ) ) );
mCacheReply = nam()->get( QNetworkRequest( redirect.toUrl() ) );
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ), Qt::DirectConnection );
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );

QEventLoop loop;
connect( mCacheReply, SIGNAL( finished() ), &loop, SLOT( quit() ) );
loop.exec();

return;
}

@@ -1043,12 +1040,6 @@ void QgsWcsProvider::cacheReplyFinished()

mCacheReply->deleteLater();
mCacheReply = 0;

if ( !mWaiting )
{
QgsDebugMsg( "emit dataChanged()" );
emit dataChanged();
}
}
else
{
@@ -1061,9 +1052,14 @@ void QgsWcsProvider::cacheReplyFinished()

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 ) ) );
mCacheReply = nam()->get( request );
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ), Qt::DirectConnection );
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );

QEventLoop loop;
connect( mCacheReply, SIGNAL( finished() ), &loop, SLOT( quit() ) );
loop.exec();

return;
}

@@ -1872,3 +1868,19 @@ QGISEXTERN bool isProvider()
{
return true;
}

#include <QThread>
QgsNetworkAccessManager *QgsWcsProvider::nam()
{
if ( mNAM && mNAM->thread() != QThread::currentThread() )
{
// TODO: check that no network connections are handled by the NAM?
mNAM->deleteLater();
mNAM = 0;
}

if ( !mNAM )
mNAM = new QgsNetworkAccessManager();

return mNAM;
}
@@ -38,6 +38,7 @@
#include <QUrl>

class QgsCoordinateTransform;
class QgsNetworkAccessManager;
class QNetworkAccessManager;
class QNetworkReply;
class QNetworkRequest;
@@ -372,9 +373,6 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
//QMap<int, int> mLayerParents;
//QMap<int, QStringList> mLayerParentNames;

//! flag set while provider is fetching tiles synchronously
bool mWaiting;

//! Errors counter
int mErrors;

@@ -399,6 +397,10 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
bool mFixRotate;

QNetworkRequest::CacheLoadControl mCacheLoadControl;

QgsNetworkAccessManager* mNAM;

QgsNetworkAccessManager* nam();
};


0 comments on commit 1b7c794

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