diff --git a/python/core/core.sip b/python/core/core.sip index dfae90b4441..002aa792320 100644 --- a/python/core/core.sip +++ b/python/core/core.sip @@ -79,4 +79,6 @@ %Include qgsvectorlayer.sip %Include qgsvectoroverlay.sip +%Include qgsnetworkaccessmanager.sip + %Include symbology-ng-core.sip diff --git a/python/core/qgsnetworkaccessmanager.sip b/python/core/qgsnetworkaccessmanager.sip new file mode 100644 index 00000000000..d464f47580e --- /dev/null +++ b/python/core/qgsnetworkaccessmanager.sip @@ -0,0 +1,51 @@ +/* + * \class QgsNetworkAccessManager + * \brief network access manager for QGIS + * \ingroup core + * \since 1.5 + * + * This class implements the QGIS network access manager. It's a singleton + * that can be used across QGIS. + * + * Plugins can insert proxy factories and thereby redirect requests to + * individual proxies. + * + * If no proxy factories are there or none returns a proxy for an URL a + * fallback proxy can be set. There's also a exclude list that defines URLs + * that the fallback proxy should not be used for, then no proxy will be used. + * + */ + +class QgsNetworkAccessManager : QNetworkAccessManager +{ +%TypeHeaderCode +#include +%End + //! returns a point to the single instance + // and creates that instance on the first call. + static QgsNetworkAccessManager *instance(); + + //! destructor + ~QgsNetworkAccessManager(); + + //! insert a factory into the proxy factories list + void insertProxyFactory(QNetworkProxyFactory *factory /TransferTo/); + + //! remove a factory from the proxy factories list + void removeProxyFactory(QNetworkProxyFactory *factory /TransferBack/); + + //! retrieve proxy factory list + void setDiskCache( QString directory, qint64 size ); + + //! retrieve fall back proxy (for urls that no factory returned proxies for) + const QList proxyFactories() const; + + //! retrieve exclude list (urls shouldn't use the fallback proxy) + const QStringList &excludeList() const; + + //! retrieve fall back proxy (for urls that no factory returned proxies for) + const QNetworkProxy &fallbackProxy() const; + + //! set fallback proxy and URL that shouldn't use it. + void setFallbackProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes ); +}; diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 0df28516f8a..96036d5d440 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -75,7 +75,6 @@ SET(QGIS_APP_SRCS qgsuniquevaluedialog.cpp qgsvectorlayerproperties.cpp qgsquerybuilder.cpp - qgsnetworkproxyfactory.cpp qgsmanageconnectionsdialog.cpp diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index 70cb00bf967..b25d9a267ca 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -67,7 +67,8 @@ #include #include -#include +#include + #include #include #include @@ -154,7 +155,6 @@ #include "qgsattributetabledialog.h" #include "qgsvectorfilewriter.h" #include "qgscredentialdialog.h" -#include "qgsnetworkproxyfactory.h" #include "qgstilescalewidget.h" #ifdef HAVE_QWT @@ -360,11 +360,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, QWidget * parent, : QMainWindow( parent, fl ) , mSplash( splash ) , mPythonUtils( NULL ) - , mNAM( NULL ) , mpTileScaleWidget( NULL ) -#if QT_VERSION >= 0x40500 - , mProxyFactory( NULL ) -#endif #ifdef HAVE_QWT , mpGpsWidget( NULL ) #endif @@ -6523,26 +6519,15 @@ void QgisApp::showLayerProperties( QgsMapLayer *ml ) void QgisApp::namSetup() { - if ( mNAM ) - return; - - mNAM = new QNetworkAccessManager( this ); + QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance(); namUpdate(); - connect( mNAM, SIGNAL( authenticationRequired( QNetworkReply *, QAuthenticator * ) ), + connect( nam, SIGNAL( authenticationRequired( QNetworkReply *, QAuthenticator * ) ), this, SLOT( namAuthenticationRequired( QNetworkReply *, QAuthenticator * ) ) ); - connect( mNAM, SIGNAL( proxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ), + connect( nam, SIGNAL( proxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ), this, SLOT( namProxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ) ); - - QCoreApplication::instance()->setProperty( "qgisNetworkAccessManager", qVariantFromValue( mNAM ) ); -} - -QNetworkAccessManager *QgisApp::nam() -{ - namSetup(); - return mNAM; } void QgisApp::namAuthenticationRequired( QNetworkReply *reply, QAuthenticator *auth ) @@ -6627,15 +6612,11 @@ void QgisApp::namUpdate() } #if QT_VERSION >= 0x40500 - if ( !mProxyFactory ) - { - mProxyFactory = new QgsNetworkProxyFactory(); - mNAM->setProxyFactory( mProxyFactory ); - } + QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance(); - mProxyFactory->setProxyAndExcludes( proxy, excludes ); + nam->setFallbackProxyAndExcludes( proxy, excludes ); - QNetworkDiskCache *cache = qobject_cast( nam()->cache() ); + QNetworkDiskCache *cache = qobject_cast( nam->cache() ); if ( !cache ) cache = new QNetworkDiskCache( this ); @@ -6648,9 +6629,9 @@ void QgisApp::namUpdate() QgsDebugMsg( QString( "cacheDirectory: %1" ).arg( cache->cacheDirectory() ) ); QgsDebugMsg( QString( "maximumCacheSize: %1" ).arg( cache->maximumCacheSize() ) ); - if ( mNAM->cache() != cache ) - mNAM->setCache( cache ); + if ( nam->cache() != cache ) + nam->setCache( cache ); #else - mNAM->setProxy( proxy ); + QgsNetworkAccessManager::instance()->setProxy( proxy ); #endif } diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index cf41deb423b..c41c71be64d 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -62,7 +62,6 @@ class QgsVectorLayer; class QgsTileScaleWidget; class QDomDocument; -class QNetworkAccessManager; class QNetworkReply; class QNetworkProxy; class QAuthenticator; @@ -80,10 +79,6 @@ class QgsGPSInformationWidget; #include "qgsfeature.h" #include "qgspoint.h" -#if QT_VERSION >= 0x40500 -class QgsNetworkProxyFactory; -#endif - /*! \class QgisApp * \brief Main window for the Qgis application */ @@ -174,9 +169,6 @@ class QgisApp : public QMainWindow //! update proxy settings void namUpdate(); - //! retrieve network manager - QNetworkAccessManager *nam(); - //! Helper to get a theme icon. It will fall back to the //default theme if the active theme does not have the required //icon. @@ -1095,15 +1087,9 @@ class QgisApp : public QMainWindow QgsUndoWidget* mUndoWidget; - QNetworkAccessManager *mNAM; - //! Persistent tile scale slider QgsTileScaleWidget * mpTileScaleWidget; -#if QT_VERSION >= 0x40500 - QgsNetworkProxyFactory *mProxyFactory; -#endif - int mLastComposerId; #ifdef HAVE_QWT diff --git a/src/app/qgsnetworkproxyfactory.cpp b/src/app/qgsnetworkproxyfactory.cpp deleted file mode 100644 index 4679667c067..00000000000 --- a/src/app/qgsnetworkproxyfactory.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - qgsnetworkproxyfactory.cpp - description - ------------------- - begin : Sat Mar 20 2010 - copyright : (C) 2010 by Juergen E. Fischer - email : jef at norbit dot de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ -/* $Id$ */ - -#include - -#if QT_VERSION >= 0x40500 - -#include -#include - -#include "qgsnetworkproxyfactory.h" -#include "qgslogger.h" - -QgsNetworkProxyFactory::QgsNetworkProxyFactory() -{ -} - -void QgsNetworkProxyFactory::setProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes ) -{ - mProxy = proxy; - mExcludedURLs = excludes; -} - -QgsNetworkProxyFactory::~QgsNetworkProxyFactory() -{ -} - -QList QgsNetworkProxyFactory::queryProxy( const QNetworkProxyQuery &query ) -{ - if( query.queryType() != QNetworkProxyQuery::UrlRequest ) - return QList() << mProxy; - - QString url = query.url().toString(); - - foreach( QString exclude, mExcludedURLs ) - { - if ( url.startsWith( exclude ) ) - { - QgsDebugMsg( QString("using default proxy for %1 [exclude %2]").arg( url ).arg( exclude ) ); - return QList() << QNetworkProxy(); - } - } - - QgsDebugMsg( QString("using user proxy for %1").arg( url ) ); - return QList() << mProxy; -} - -#endif // QT_VERSION >= 0x40500 diff --git a/src/app/qgsnetworkproxyfactory.h b/src/app/qgsnetworkproxyfactory.h deleted file mode 100644 index d20f878b78b..00000000000 --- a/src/app/qgsnetworkproxyfactory.h +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - qgsabout.h - description - ------------------- - begin : Sat, 20 Mar 2010 - copyright : (C) 2010 by Juergen E. Fischer - email : jef at norbit dot de - ***************************************************************************/ - -/*************************************************************************** - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - ***************************************************************************/ -/* $Id:$ */ -#ifndef QGSNETWORKPROXYFACTORY_H -#define QGSNETWORKPROXYFACTORY_H - -#if QT_VERSION >= 0x40500 - -#include -#include - -class QgsNetworkProxyFactory : public QNetworkProxyFactory -{ - public: - QgsNetworkProxyFactory(); - virtual ~QgsNetworkProxyFactory(); - virtual QList queryProxy( const QNetworkProxyQuery & query = QNetworkProxyQuery() ); - - void setProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes ); - - private: - QStringList mExcludedURLs; - QNetworkProxy mProxy; -}; - -#endif // QT_VERSION >= 0x40500 - -#endif diff --git a/src/app/qgsoptions.cpp b/src/app/qgsoptions.cpp index f2865259eb8..5c4b88dd704 100644 --- a/src/app/qgsoptions.cpp +++ b/src/app/qgsoptions.cpp @@ -23,12 +23,12 @@ #include "qgsgenericprojectionselector.h" #include "qgscoordinatereferencesystem.h" #include "qgstolerance.h" +#include "qgsnetworkaccessmanager.h" #include #include #include #include -#include #if QT_VERSION >= 0x40500 #include @@ -121,7 +121,7 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) : #if QT_VERSION >= 0x40500 // cache settings - QNetworkDiskCache *cache = qobject_cast( QgisApp::instance()->nam()->cache() ); + QNetworkDiskCache *cache = qobject_cast( QgsNetworkAccessManager::instance()->cache() ); if ( cache ) { mCacheDirectory->setText( cache->cacheDirectory() ); @@ -873,6 +873,6 @@ void QgsOptions::on_mBrowseCacheDirectory_clicked() void QgsOptions::on_mClearCache_clicked() { #if QT_VERSION >= 0x40500 - QgisApp::instance()->nam()->cache()->clear(); + QgsNetworkAccessManager::instance()->cache()->clear(); #endif } diff --git a/src/app/qgswmssourceselect.cpp b/src/app/qgswmssourceselect.cpp index ae797d86eb2..0b124741c03 100644 --- a/src/app/qgswmssourceselect.cpp +++ b/src/app/qgswmssourceselect.cpp @@ -33,7 +33,7 @@ #include "qgsproject.h" #include "qgsproviderregistry.h" #include "qgswmssourceselect.h" -#include +#include "qgsnetworkaccessmanager.h" #include #include @@ -47,7 +47,6 @@ #include #include -#include #include #include @@ -1051,7 +1050,7 @@ void QgsWMSSourceSelect::on_btnSearch_clicked() QUrl url( mySearchUrl.arg( leSearchTerm->text() ) ); QgsDebugMsg( url.toString() ); - QNetworkReply *r = QgisApp::instance()->nam()->get( QNetworkRequest( url ) ); + QNetworkReply *r = QgsNetworkAccessManager::instance()->get( QNetworkRequest( url ) ); connect( r, SIGNAL( finished() ), SLOT( searchFinished() ) ); } diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 51b7069505b..9d8bee5b903 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -88,6 +88,8 @@ SET(QGIS_CORE_SRCS qgsvectorlayerundocommand.cpp qgsvectoroverlay.cpp + qgsnetworkaccessmanager.cpp + composer/qgscomposerarrow.cpp composer/qgscomposeritem.cpp composer/qgscomposeritemgroup.cpp @@ -232,6 +234,7 @@ SET(QGIS_CORE_MOC_HDRS qgsrunprocess.h qgsvectorlayer.h qgsrasterdataprovider.h + qgsnetworkaccessmanager.h composer/qgscomposerlegend.h composer/qgscomposermap.h diff --git a/src/core/qgsnetworkaccessmanager.cpp b/src/core/qgsnetworkaccessmanager.cpp new file mode 100644 index 00000000000..8a30e6162b4 --- /dev/null +++ b/src/core/qgsnetworkaccessmanager.cpp @@ -0,0 +1,117 @@ +/*************************************************************************** + qgsnetworkaccessmanager.cpp + This class implements a QNetworkManager with the ability to chain in + own proxy factories. + + ------------------- + begin : 2010-05-08 + copyright : (C) 2010 by Juergen E. Fischer + email : jef at norbit dot de + +***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/* $Id$ */ + +#include +#include + +#include + +class QgsNetworkProxyFactory : public QNetworkProxyFactory +{ + public: + QgsNetworkProxyFactory() {} + virtual ~QgsNetworkProxyFactory() {} + + virtual QList queryProxy( const QNetworkProxyQuery & query = QNetworkProxyQuery() ) + { + QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance(); + + // iterate proxies factories and take first non empty list + foreach( QNetworkProxyFactory *f, nam->proxyFactories() ) + { + QList proxies = f->queryProxy( query ); + if ( proxies.size() > 0 ) + return proxies; + } + + // no proxies from the proxy factor list check for excludes + if ( query.queryType() != QNetworkProxyQuery::UrlRequest ) + return QList() << nam->fallbackProxy(); + + QString url = query.url().toString(); + + foreach( QString exclude, nam->excludeList() ) + { + if ( url.startsWith( exclude ) ) + { + QgsDebugMsg( QString( "using default proxy for %1 [exclude %2]" ).arg( url ).arg( exclude ) ); + return QList() << QNetworkProxy(); + } + } + + QgsDebugMsg( QString( "using user proxy for %1" ).arg( url ) ); + return QList() << nam->fallbackProxy(); + } +}; + +QgsNetworkAccessManager *QgsNetworkAccessManager::smNAM = 0; + +QgsNetworkAccessManager *QgsNetworkAccessManager::instance() +{ + if ( smNAM ) + return smNAM; + + smNAM = new QgsNetworkAccessManager(); + + return smNAM; +} + +QgsNetworkAccessManager::QgsNetworkAccessManager( QObject *parent ) + : QNetworkAccessManager( parent ) +{ + setProxyFactory( new QgsNetworkProxyFactory() ); +} + +QgsNetworkAccessManager::~QgsNetworkAccessManager() +{ +} + +void QgsNetworkAccessManager::insertProxyFactory( QNetworkProxyFactory *factory ) +{ + mProxyFactories.insert( 0, factory ); +} + +void QgsNetworkAccessManager::removeProxyFactory( QNetworkProxyFactory *factory ) +{ + mProxyFactories.removeAll( factory ); +} + +const QList QgsNetworkAccessManager::proxyFactories() const +{ + return mProxyFactories; +} + +const QStringList &QgsNetworkAccessManager::excludeList() const +{ + return mExcludedURLs; +} + +const QNetworkProxy &QgsNetworkAccessManager::fallbackProxy() const +{ + return mFallbackProxy; +} + +void QgsNetworkAccessManager::setFallbackProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes ) +{ + mFallbackProxy = proxy; + mExcludedURLs = excludes; +} diff --git a/src/core/qgsnetworkaccessmanager.h b/src/core/qgsnetworkaccessmanager.h new file mode 100644 index 00000000000..65a847e0313 --- /dev/null +++ b/src/core/qgsnetworkaccessmanager.h @@ -0,0 +1,83 @@ +/*************************************************************************** + qgsnetworkaccessmanager.h - description + ------------------- + begin : 2010-05-08 + copyright : (C) 2010 by Juergen E. Fischer + email : jef at norbit dot de + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ +/* $Id$ */ + +#ifndef QGSNETWORKACCESSMANAGER_H +#define QGSNETWORKACCESSMANAGER_H + +#include +#include +#include +#include + +/* + * \class QgsNetworkAccessManager + * \brief network access manager for QGIS + * \ingroup core + * \since 1.5 + * + * This class implements the QGIS network access manager. It's a singleton + * that can be use across QGIS. + * + * Plugins can insert proxy factories and thereby redirect requests to + * individual proxies. + * + * If no proxy factories are there or none returns a proxy for an URL a + * fallback proxy can be set. There's also a exclude list that defines URLs + * that the fallback proxy should not be used for, then no proxy will be used. + * + */ +class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager +{ + Q_OBJECT + + public: + //! returns a point to the single instance + // and creates that instance on the first call. + static QgsNetworkAccessManager *instance(); + + //! destructor + ~QgsNetworkAccessManager(); + + //! insert a factory into the proxy factories list + void insertProxyFactory( QNetworkProxyFactory *factory ); + + //! remove a factory from the proxy factories list + void removeProxyFactory( QNetworkProxyFactory *factory ); + + //! retrieve proxy factory list + const QList proxyFactories() const; + + //! retrieve fall back proxy (for urls that no factory returned proxies for) + const QNetworkProxy &fallbackProxy() const; + + //! retrieve exclude list (urls shouldn't use the fallback proxy) + const QStringList &excludeList() const; + + //! set fallback proxy and URL that shouldn't use it. + void setFallbackProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes ); + + private: + QgsNetworkAccessManager( QObject *parent = 0 ); + QList mProxyFactories; + QNetworkProxy mFallbackProxy; + QStringList mExcludedURLs; + + static QgsNetworkAccessManager *smNAM; +}; + +#endif // QGSNETWORKACCESSMANAGER_H diff --git a/src/providers/wms/qgswmsprovider.cpp b/src/providers/wms/qgswmsprovider.cpp index 645e579721a..d41cc858713 100644 --- a/src/providers/wms/qgswmsprovider.cpp +++ b/src/providers/wms/qgswmsprovider.cpp @@ -31,8 +31,8 @@ #include "qgscoordinatetransform.h" #include "qgsrectangle.h" #include "qgscoordinatereferencesystem.h" +#include "qgsnetworkaccessmanager.h" -#include #include #include #include @@ -83,50 +83,6 @@ QgsWmsProvider::QgsWmsProvider( QString const &uri ) , mCacheMisses( 0 ) , mErrors( 0 ) { - if ( !smNAM ) - { - QList propertyNames = QCoreApplication::instance()->dynamicPropertyNames(); - foreach( QByteArray name, propertyNames ) - { - QgsDebugMsg( QString( "property name: %1" ).arg( QString::fromUtf8( name ) ) ); - } - - if ( propertyNames.contains( "qgisNetworkAccessManager" ) ) - { - smNAM = qobject_cast( QCoreApplication::instance()->property( "qgisNetworkAccessManager" ).value() ); - - if ( smNAM ) - { - QNetworkProxy proxy = smNAM->proxy(); -#if QT_VERSION >= 0x40500 - QgsDebugMsg( QString( "proxy host:%1:%2 type:%3 user:%4 password:%5 capabilities:%6" ) - .arg( proxy.hostName() ).arg( proxy.port() ) - .arg( proxy.type() ) - .arg( proxy.user() ).arg( proxy.password() ) - .arg( proxy.capabilities() ) - ); -#else - QgsDebugMsg( QString( "proxy host:%1:%2 type:%3 user:%4 password:%5" ) - .arg( proxy.hostName() ).arg( proxy.port() ) - .arg( proxy.type() ) - .arg( proxy.user() ).arg( proxy.password() ) - ); -#endif - } - } - -#if QT_VERSION >= 0x40500 - if ( !smNAM ) - { - QgsDebugMsg( "application doesn't have a network access manager - creating wmscache" ); - smNAM = new QNetworkAccessManager( this ); - QNetworkDiskCache *ndc = new QNetworkDiskCache( this ); - ndc->setCacheDirectory( "wmsCache" ); - smNAM->setCache( ndc ); - } -#endif - } - // URL may contain username/password information for a WMS // requiring authentication. In this case the URL is prefixed // with username=user,password=pass,url=http://xxx.xxx.xx/yyy... @@ -537,7 +493,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i QgsDebugMsg( QString( "getmap: %1" ).arg( url ) ); QNetworkRequest request( url ); request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true ); - cacheReply = smNAM->get( request ); + cacheReply = QgsNetworkAccessManager::instance()->get( request ); connect( cacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) ); connect( cacheReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( cacheReplyProgress( qint64, qint64 ) ) ); @@ -571,8 +527,6 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i } double tres = mResolutions[i]; - double dx = mTileWidth * tres; - double dy = mTileHeight * tres; // clip view extent to layer extent double xmin = std::max( viewExtent.xMinimum(), layerExtent.xMinimum() ); @@ -581,12 +535,12 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i double ymax = std::min( viewExtent.yMaximum(), layerExtent.yMaximum() ); // snap to tile coordinates - double x0 = floor(( xmin - layerExtent.xMinimum() ) / dx ) * dx + layerExtent.xMinimum(); - double y0 = floor(( ymin - layerExtent.yMinimum() ) / dy ) * dy + layerExtent.yMinimum(); + double x0 = floor(( xmin - layerExtent.xMinimum() ) / mTileWidth / tres ) * mTileWidth * tres + layerExtent.xMinimum(); + double y0 = floor(( ymin - layerExtent.yMinimum() ) / mTileHeight / tres ) * mTileHeight * tres + layerExtent.yMinimum(); #ifdef QGISDEBUG // calculate number of tiles - int n = ceil(( xmax - xmin ) / dx ) * ceil(( ymax - ymin ) / dy ); + int n = ceil(( xmax - xmin ) / mTileWidth / tres ) * ceil(( ymax - ymin ) / mTileHeight / tres ); #endif QgsDebugMsg( QString( "layer extent: %1,%2 %3x%4" ) @@ -604,13 +558,13 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i ); QgsDebugMsg( QString( "tile extent: %1,%2 %3x%4 pixel:%5x%6 res:%7" ) .arg( x0, 0, 'f' ).arg( y0, 0, 'f' ) - .arg( dx, 0, 'f' ).arg( dy, 0, 'f' ) + .arg( mTileWidth * tres, 0, 'f' ).arg( mTileHeight * tres, 0, 'f' ) .arg( mTileWidth ).arg( mTileHeight ) .arg( tres, 0, 'f' ) ); QgsDebugMsg( QString( "tile number: %1x%2 = %3" ) - .arg( ceil(( xmax - xmin ) / dx ) ) - .arg( ceil(( ymax - ymin ) / dy ) ) + .arg( ceil(( xmax - xmin ) / mTileWidth / tres ) ) + .arg( ceil(( ymax - ymin ) / mTileHeight / tres ) ) .arg( n ) ); @@ -635,33 +589,40 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i urlargs += QString( "&FORMAT=%1" ).arg( imageMimeType ); urlargs += QString( "&TILED=true" ); + i = 0; int j = 0; - for ( double y = y0; y < ymax; y += dy ) + double y = y0; + while ( y < ymax ) { - for ( double x = x0; x <= xmax; x += dx ) + int k = 0; + double x = x0; + while ( x < xmax ) { QString turl; turl += url; turl += QString( changeXY ? "&BBOX=%2,%1,%4,%3" : "&BBOX=%1,%2,%3,%4" ) .arg( x, 0, 'f' ) .arg( y, 0, 'f' ) - .arg( x + dx, 0, 'f' ) - .arg( y + dy, 0, 'f' ); + .arg( x + mTileWidth * tres, 0, 'f' ) + .arg( y + mTileHeight * tres, 0, 'f' ); turl += urlargs; QNetworkRequest request( turl ); - QgsDebugMsg( QString( "tileRequest %1 %2/%3: %4" ).arg( mTileReqNo ).arg( j++ ).arg( n ).arg( turl ) ); + QgsDebugMsg( QString( "tileRequest %1 %2/%3: %4" ).arg( mTileReqNo ).arg( i++ ).arg( n ).arg( turl ) ); request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache ); request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true ); request.setAttribute( static_cast( QNetworkRequest::User + 0 ), mTileReqNo ); request.setAttribute( static_cast( QNetworkRequest::User + 1 ), j ); - request.setAttribute( static_cast( QNetworkRequest::User + 2 ), QRectF( x, y, dx, dy ) ); + request.setAttribute( static_cast( QNetworkRequest::User + 2 ), QRectF( x, y, mTileWidth * tres, mTileHeight * tres ) ); QgsDebugMsg( QString( "gettile: %1" ).arg( turl ) ); - QNetworkReply *reply = smNAM->get( request ); + QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( request ); tileReplies << reply; connect( reply, SIGNAL( finished() ), this, SLOT( tileReplyFinished() ) ); + + x = x0 + k++*mTileWidth * tres; } + y = y0 + j++*mTileHeight * tres; } mWaiting = true; @@ -729,7 +690,7 @@ void QgsWmsProvider::tileReplyFinished() reply->deleteLater(); QgsDebugMsg( QString( "redirected gettile: %1" ).arg( redirect.toString() ) ); - reply = smNAM->get( request ); + reply = QgsNetworkAccessManager::instance()->get( request ); tileReplies << reply; connect( reply, SIGNAL( finished() ), this, SLOT( tileReplyFinished() ) ); @@ -807,7 +768,7 @@ void QgsWmsProvider::cacheReplyFinished() cacheReply->deleteLater(); QgsDebugMsg( QString( "redirected getmap: %1" ).arg( redirect.toString() ) ); - cacheReply = smNAM->get( QNetworkRequest( redirect.toUrl() ) ); + cacheReply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( redirect.toUrl() ) ); connect( cacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) ); return; } @@ -861,7 +822,7 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh ) request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true ); QgsDebugMsg( QString( "getcapabilities: %1" ).arg( url ) ); - mCapabilitiesReply = smNAM->get( request ); + mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request ); connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) ); connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) ); @@ -916,7 +877,7 @@ void QgsWmsProvider::capabilitiesReplyFinished() mCapabilitiesReply->deleteLater(); QgsDebugMsg( QString( "redirected getcapabilities: %1" ).arg( redirect.toString() ) ); - mCapabilitiesReply = smNAM->get( request ); + mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request ); connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) ); connect( mCapabilitiesReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( capabilitiesReplyProgress( qint64, qint64 ) ) ); @@ -2637,7 +2598,7 @@ QString QgsWmsProvider::identifyAsText( const QgsPoint& point ) // requestUrl += QString( "&I=%1&J=%2" ).arg( point.x() ).arg( point.y() ); QgsDebugMsg( QString( "getfeatureinfo: %1" ).arg( requestUrl ) ); - mIdentifyReply = smNAM->get( QNetworkRequest( requestUrl ) ); + mIdentifyReply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( requestUrl ) ); connect( mIdentifyReply, SIGNAL( finished() ), this, SLOT( identifyReplyFinished() ) ); while ( mIdentifyReply ) @@ -2676,7 +2637,7 @@ void QgsWmsProvider::identifyReplyFinished() mIdentifyReply->deleteLater(); QgsDebugMsg( QString( "redirected getfeatureinfo: %1" ).arg( redirect.toString() ) ); - mIdentifyReply = smNAM->get( QNetworkRequest( redirect.toUrl() ) ); + mIdentifyReply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( redirect.toUrl() ) ); connect( mIdentifyReply, SIGNAL( finished() ), this, SLOT( identifyReplyFinished() ) ); return; @@ -2736,8 +2697,6 @@ QString QgsWmsProvider::description() const return WMS_DESCRIPTION; } // QgsWmsProvider::description() -QNetworkAccessManager *QgsWmsProvider::smNAM = 0; - /** * Class factory to return a pointer to a newly created diff --git a/src/providers/wms/qgswmsprovider.h b/src/providers/wms/qgswmsprovider.h index 032f1e2c6b1..39aa9a137ce 100644 --- a/src/providers/wms/qgswmsprovider.h +++ b/src/providers/wms/qgswmsprovider.h @@ -883,9 +883,6 @@ class QgsWmsProvider : public QgsRasterDataProvider int mTileWidth; int mTileHeight; QVector mResolutions; - - //! wms provider's network access manager - static QNetworkAccessManager *smNAM; }; #endif