Skip to content

Commit 1b7c794

Browse files
committed
WCS: quick and dirty way to get it working
1 parent 3687ac1 commit 1b7c794

File tree

2 files changed

+49
-35
lines changed

2 files changed

+49
-35
lines changed

src/providers/wcs/qgswcsprovider.cpp

+44-32
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121

2222
#include <typeinfo>
2323

24-
// time to wait for an answer without emitting dataChanged()
25-
#define WCS_THRESHOLD 200
26-
2724
#include "qgslogger.h"
2825
#include "qgswcsprovider.h"
2926
#include "qgscoordinatetransform.h"
@@ -108,6 +105,7 @@ QgsWcsProvider::QgsWcsProvider( QString const &uri )
108105
, mFixBox( false )
109106
, mFixRotate( false )
110107
, mCacheLoadControl( QNetworkRequest::PreferNetwork )
108+
, mNAM( 0 )
111109
{
112110
QgsDebugMsg( "constructing with uri '" + mHttpUri + "'." );
113111

@@ -467,6 +465,8 @@ QgsWcsProvider::~QgsWcsProvider()
467465
mCacheReply->deleteLater();
468466
mCacheReply = 0;
469467
}
468+
469+
delete mNAM;
470470
}
471471

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

@@ -791,26 +791,18 @@ void QgsWcsProvider::getCache( int bandNo, QgsRectangle const & viewExtent, int
791791
setAuthorization( request );
792792
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
793793
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, mCacheLoadControl );
794-
mCacheReply = QgsNetworkAccessManager::instance()->get( request );
795-
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
796-
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
797-
798-
emit statusChanged( tr( "Getting map via WCS." ) );
799-
800-
mWaiting = true;
801794

802-
QTime t;
803-
t.start();
795+
mCacheReply = nam()->get( request );
796+
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ), Qt::DirectConnection );
797+
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );
804798

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

808-
while ( mCacheReply && ( !bkLayerCaching || t.elapsed() < WCS_THRESHOLD ) )
809-
{
810-
QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents, WCS_THRESHOLD );
811-
}
812-
mWaiting = false;
801+
QEventLoop loop;
802+
connect( mCacheReply, SIGNAL( finished() ), &loop, SLOT( quit() ) );
803+
loop.exec();
813804

805+
Q_ASSERT( mCacheReply == 0 );
814806
}
815807

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

852844
QgsDebugMsg( QString( "redirected getmap: %1" ).arg( redirect.toString() ) );
853-
mCacheReply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( redirect.toUrl() ) );
854-
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
855-
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
845+
mCacheReply = nam()->get( QNetworkRequest( redirect.toUrl() ) );
846+
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ), Qt::DirectConnection );
847+
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );
848+
849+
QEventLoop loop;
850+
connect( mCacheReply, SIGNAL( finished() ), &loop, SLOT( quit() ) );
851+
loop.exec();
852+
856853
return;
857854
}
858855

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

10441041
mCacheReply->deleteLater();
10451042
mCacheReply = 0;
1046-
1047-
if ( !mWaiting )
1048-
{
1049-
QgsDebugMsg( "emit dataChanged()" );
1050-
emit dataChanged();
1051-
}
10521043
}
10531044
else
10541045
{
@@ -1061,9 +1052,14 @@ void QgsWcsProvider::cacheReplyFinished()
10611052

10621053
mCacheReply->deleteLater();
10631054

1064-
mCacheReply = QgsNetworkAccessManager::instance()->get( request );
1065-
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
1066-
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) );
1055+
mCacheReply = nam()->get( request );
1056+
connect( mCacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ), Qt::DirectConnection );
1057+
connect( mCacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ), Qt::DirectConnection );
1058+
1059+
QEventLoop loop;
1060+
connect( mCacheReply, SIGNAL( finished() ), &loop, SLOT( quit() ) );
1061+
loop.exec();
1062+
10671063
return;
10681064
}
10691065

@@ -1872,3 +1868,19 @@ QGISEXTERN bool isProvider()
18721868
{
18731869
return true;
18741870
}
1871+
1872+
#include <QThread>
1873+
QgsNetworkAccessManager *QgsWcsProvider::nam()
1874+
{
1875+
if ( mNAM && mNAM->thread() != QThread::currentThread() )
1876+
{
1877+
// TODO: check that no network connections are handled by the NAM?
1878+
mNAM->deleteLater();
1879+
mNAM = 0;
1880+
}
1881+
1882+
if ( !mNAM )
1883+
mNAM = new QgsNetworkAccessManager();
1884+
1885+
return mNAM;
1886+
}

src/providers/wcs/qgswcsprovider.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <QUrl>
3939

4040
class QgsCoordinateTransform;
41+
class QgsNetworkAccessManager;
4142
class QNetworkAccessManager;
4243
class QNetworkReply;
4344
class QNetworkRequest;
@@ -372,9 +373,6 @@ class QgsWcsProvider : public QgsRasterDataProvider, QgsGdalProviderBase
372373
//QMap<int, int> mLayerParents;
373374
//QMap<int, QStringList> mLayerParentNames;
374375

375-
//! flag set while provider is fetching tiles synchronously
376-
bool mWaiting;
377-
378376
//! Errors counter
379377
int mErrors;
380378

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

401399
QNetworkRequest::CacheLoadControl mCacheLoadControl;
400+
401+
QgsNetworkAccessManager* mNAM;
402+
403+
QgsNetworkAccessManager* nam();
402404
};
403405

404406

0 commit comments

Comments
 (0)