[QGIS Commit] r13443 - in trunk/qgis: python/core src/app src/core
src/providers/wms
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sat May 8 15:16:25 EDT 2010
Author: jef
Date: 2010-05-08 15:16:21 -0400 (Sat, 08 May 2010)
New Revision: 13443
Added:
trunk/qgis/python/core/qgsnetworkaccessmanager.sip
trunk/qgis/src/core/qgsnetworkaccessmanager.cpp
trunk/qgis/src/core/qgsnetworkaccessmanager.h
Removed:
trunk/qgis/src/app/qgsnetworkproxyfactory.cpp
trunk/qgis/src/app/qgsnetworkproxyfactory.h
Modified:
trunk/qgis/python/core/core.sip
trunk/qgis/src/app/CMakeLists.txt
trunk/qgis/src/app/qgisapp.cpp
trunk/qgis/src/app/qgisapp.h
trunk/qgis/src/app/qgsoptions.cpp
trunk/qgis/src/app/qgswmssourceselect.cpp
trunk/qgis/src/core/CMakeLists.txt
trunk/qgis/src/providers/wms/qgswmsprovider.cpp
trunk/qgis/src/providers/wms/qgswmsprovider.h
Log:
network manager changes:
- add QgsNetworkAccessManager to core as singleton
- add support for multiple proxy factories
- remove qgisNetworkAccessManager property hack
- python bindings
wms provider:
- use QgsNetworkAccessManager
- some precision changes
Modified: trunk/qgis/python/core/core.sip
===================================================================
--- trunk/qgis/python/core/core.sip 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/python/core/core.sip 2010-05-08 19:16:21 UTC (rev 13443)
@@ -79,4 +79,6 @@
%Include qgsvectorlayer.sip
%Include qgsvectoroverlay.sip
+%Include qgsnetworkaccessmanager.sip
+
%Include symbology-ng-core.sip
Added: trunk/qgis/python/core/qgsnetworkaccessmanager.sip
===================================================================
--- trunk/qgis/python/core/qgsnetworkaccessmanager.sip (rev 0)
+++ trunk/qgis/python/core/qgsnetworkaccessmanager.sip 2010-05-08 19:16:21 UTC (rev 13443)
@@ -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 <qgsnetworkaccessmanager.h>
+%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<QNetworkProxyFactory *> 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 );
+};
Property changes on: trunk/qgis/python/core/qgsnetworkaccessmanager.sip
___________________________________________________________________
Added: svn:keywords
+ Revision Author Id
Modified: trunk/qgis/src/app/CMakeLists.txt
===================================================================
--- trunk/qgis/src/app/CMakeLists.txt 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/src/app/CMakeLists.txt 2010-05-08 19:16:21 UTC (rev 13443)
@@ -75,7 +75,6 @@
qgsuniquevaluedialog.cpp
qgsvectorlayerproperties.cpp
qgsquerybuilder.cpp
- qgsnetworkproxyfactory.cpp
qgsmanageconnectionsdialog.cpp
Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/src/app/qgisapp.cpp 2010-05-08 19:16:21 UTC (rev 13443)
@@ -67,7 +67,8 @@
#include <QVBoxLayout>
#include <QWhatsThis>
-#include <QNetworkAccessManager>
+#include <qgsnetworkaccessmanager.h>
+
#include <QNetworkReply>
#include <QNetworkProxy>
#include <QAuthenticator>
@@ -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 @@
: 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,28 +6519,17 @@
void QgisApp::namSetup()
{
- if ( mNAM )
- return;
+ QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
- mNAM = new QNetworkAccessManager( this );
-
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<QObject*>( mNAM ) );
}
-QNetworkAccessManager *QgisApp::nam()
-{
- namSetup();
- return mNAM;
-}
-
void QgisApp::namAuthenticationRequired( QNetworkReply *reply, QAuthenticator *auth )
{
QString username = auth->user();
@@ -6627,15 +6612,11 @@
}
#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<QNetworkDiskCache*>( nam()->cache() );
+ QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( nam->cache() );
if ( !cache )
cache = new QNetworkDiskCache( this );
@@ -6648,9 +6629,9 @@
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
}
Modified: trunk/qgis/src/app/qgisapp.h
===================================================================
--- trunk/qgis/src/app/qgisapp.h 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/src/app/qgisapp.h 2010-05-08 19:16:21 UTC (rev 13443)
@@ -62,7 +62,6 @@
class QgsTileScaleWidget;
class QDomDocument;
-class QNetworkAccessManager;
class QNetworkReply;
class QNetworkProxy;
class QAuthenticator;
@@ -80,10 +79,6 @@
#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 @@
//! 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 @@
QgsUndoWidget* mUndoWidget;
- QNetworkAccessManager *mNAM;
-
//! Persistent tile scale slider
QgsTileScaleWidget * mpTileScaleWidget;
-#if QT_VERSION >= 0x40500
- QgsNetworkProxyFactory *mProxyFactory;
-#endif
-
int mLastComposerId;
#ifdef HAVE_QWT
Deleted: trunk/qgis/src/app/qgsnetworkproxyfactory.cpp
===================================================================
--- trunk/qgis/src/app/qgsnetworkproxyfactory.cpp 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/src/app/qgsnetworkproxyfactory.cpp 2010-05-08 19:16:21 UTC (rev 13443)
@@ -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 <QtGlobal>
-
-#if QT_VERSION >= 0x40500
-
-#include <QSettings>
-#include <QUrl>
-
-#include "qgsnetworkproxyfactory.h"
-#include "qgslogger.h"
-
-QgsNetworkProxyFactory::QgsNetworkProxyFactory()
-{
-}
-
-void QgsNetworkProxyFactory::setProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes )
-{
- mProxy = proxy;
- mExcludedURLs = excludes;
-}
-
-QgsNetworkProxyFactory::~QgsNetworkProxyFactory()
-{
-}
-
-QList<QNetworkProxy> QgsNetworkProxyFactory::queryProxy( const QNetworkProxyQuery &query )
-{
- if( query.queryType() != QNetworkProxyQuery::UrlRequest )
- return QList<QNetworkProxy>() << 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>() << QNetworkProxy();
- }
- }
-
- QgsDebugMsg( QString("using user proxy for %1").arg( url ) );
- return QList<QNetworkProxy>() << mProxy;
-}
-
-#endif // QT_VERSION >= 0x40500
Deleted: trunk/qgis/src/app/qgsnetworkproxyfactory.h
===================================================================
--- trunk/qgis/src/app/qgsnetworkproxyfactory.h 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/src/app/qgsnetworkproxyfactory.h 2010-05-08 19:16:21 UTC (rev 13443)
@@ -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 <QNetworkProxyFactory>
-#include <QStringList>
-
-class QgsNetworkProxyFactory : public QNetworkProxyFactory
-{
- public:
- QgsNetworkProxyFactory();
- virtual ~QgsNetworkProxyFactory();
- virtual QList<QNetworkProxy> queryProxy( const QNetworkProxyQuery & query = QNetworkProxyQuery() );
-
- void setProxyAndExcludes( const QNetworkProxy &proxy, const QStringList &excludes );
-
- private:
- QStringList mExcludedURLs;
- QNetworkProxy mProxy;
-};
-
-#endif // QT_VERSION >= 0x40500
-
-#endif
Modified: trunk/qgis/src/app/qgsoptions.cpp
===================================================================
--- trunk/qgis/src/app/qgsoptions.cpp 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/src/app/qgsoptions.cpp 2010-05-08 19:16:21 UTC (rev 13443)
@@ -23,12 +23,12 @@
#include "qgsgenericprojectionselector.h"
#include "qgscoordinatereferencesystem.h"
#include "qgstolerance.h"
+#include "qgsnetworkaccessmanager.h"
#include <QFileDialog>
#include <QSettings>
#include <QColorDialog>
#include <QLocale>
-#include <QNetworkAccessManager>
#if QT_VERSION >= 0x40500
#include <QNetworkDiskCache>
@@ -121,7 +121,7 @@
#if QT_VERSION >= 0x40500
// cache settings
- QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( QgisApp::instance()->nam()->cache() );
+ QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( QgsNetworkAccessManager::instance()->cache() );
if ( cache )
{
mCacheDirectory->setText( cache->cacheDirectory() );
@@ -873,6 +873,6 @@
void QgsOptions::on_mClearCache_clicked()
{
#if QT_VERSION >= 0x40500
- QgisApp::instance()->nam()->cache()->clear();
+ QgsNetworkAccessManager::instance()->cache()->clear();
#endif
}
Modified: trunk/qgis/src/app/qgswmssourceselect.cpp
===================================================================
--- trunk/qgis/src/app/qgswmssourceselect.cpp 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/src/app/qgswmssourceselect.cpp 2010-05-08 19:16:21 UTC (rev 13443)
@@ -33,7 +33,7 @@
#include "qgsproject.h"
#include "qgsproviderregistry.h"
#include "qgswmssourceselect.h"
-#include <qgisinterface.h>
+#include "qgsnetworkaccessmanager.h"
#include <QButtonGroup>
#include <QRadioButton>
@@ -47,7 +47,6 @@
#include <QSettings>
#include <QUrl>
-#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
@@ -1051,7 +1050,7 @@
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() ) );
}
Modified: trunk/qgis/src/core/CMakeLists.txt
===================================================================
--- trunk/qgis/src/core/CMakeLists.txt 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/src/core/CMakeLists.txt 2010-05-08 19:16:21 UTC (rev 13443)
@@ -88,6 +88,8 @@
qgsvectorlayerundocommand.cpp
qgsvectoroverlay.cpp
+ qgsnetworkaccessmanager.cpp
+
composer/qgscomposerarrow.cpp
composer/qgscomposeritem.cpp
composer/qgscomposeritemgroup.cpp
@@ -232,6 +234,7 @@
qgsrunprocess.h
qgsvectorlayer.h
qgsrasterdataprovider.h
+ qgsnetworkaccessmanager.h
composer/qgscomposerlegend.h
composer/qgscomposermap.h
Added: trunk/qgis/src/core/qgsnetworkaccessmanager.cpp
===================================================================
--- trunk/qgis/src/core/qgsnetworkaccessmanager.cpp (rev 0)
+++ trunk/qgis/src/core/qgsnetworkaccessmanager.cpp 2010-05-08 19:16:21 UTC (rev 13443)
@@ -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 <qgsnetworkaccessmanager.h>
+#include <qgslogger.h>
+
+#include <QUrl>
+
+class QgsNetworkProxyFactory : public QNetworkProxyFactory
+{
+ public:
+ QgsNetworkProxyFactory() {}
+ virtual ~QgsNetworkProxyFactory() {}
+
+ virtual QList<QNetworkProxy> queryProxy( const QNetworkProxyQuery & query = QNetworkProxyQuery() )
+ {
+ QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
+
+ // iterate proxies factories and take first non empty list
+ foreach( QNetworkProxyFactory *f, nam->proxyFactories() )
+ {
+ QList<QNetworkProxy> 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<QNetworkProxy>() << 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>() << QNetworkProxy();
+ }
+ }
+
+ QgsDebugMsg( QString( "using user proxy for %1" ).arg( url ) );
+ return QList<QNetworkProxy>() << 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<QNetworkProxyFactory *> 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;
+}
Property changes on: trunk/qgis/src/core/qgsnetworkaccessmanager.cpp
___________________________________________________________________
Added: svn:keywords
+ Revision Author Id
Added: trunk/qgis/src/core/qgsnetworkaccessmanager.h
===================================================================
--- trunk/qgis/src/core/qgsnetworkaccessmanager.h (rev 0)
+++ trunk/qgis/src/core/qgsnetworkaccessmanager.h 2010-05-08 19:16:21 UTC (rev 13443)
@@ -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 <QList>
+#include <QStringList>
+#include <QNetworkAccessManager>
+#include <QNetworkProxy>
+
+/*
+ * \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<QNetworkProxyFactory *> 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<QNetworkProxyFactory*> mProxyFactories;
+ QNetworkProxy mFallbackProxy;
+ QStringList mExcludedURLs;
+
+ static QgsNetworkAccessManager *smNAM;
+};
+
+#endif // QGSNETWORKACCESSMANAGER_H
Property changes on: trunk/qgis/src/core/qgsnetworkaccessmanager.h
___________________________________________________________________
Added: svn:keywords
+ Revision Author Id
Modified: trunk/qgis/src/providers/wms/qgswmsprovider.cpp
===================================================================
--- trunk/qgis/src/providers/wms/qgswmsprovider.cpp 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/src/providers/wms/qgswmsprovider.cpp 2010-05-08 19:16:21 UTC (rev 13443)
@@ -31,8 +31,8 @@
#include "qgscoordinatetransform.h"
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
+#include "qgsnetworkaccessmanager.h"
-#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkProxy>
@@ -83,50 +83,6 @@
, mCacheMisses( 0 )
, mErrors( 0 )
{
- if ( !smNAM )
- {
- QList<QByteArray> propertyNames = QCoreApplication::instance()->dynamicPropertyNames();
- foreach( QByteArray name, propertyNames )
- {
- QgsDebugMsg( QString( "property name: %1" ).arg( QString::fromUtf8( name ) ) );
- }
-
- if ( propertyNames.contains( "qgisNetworkAccessManager" ) )
- {
- smNAM = qobject_cast<QNetworkAccessManager*>( QCoreApplication::instance()->property( "qgisNetworkAccessManager" ).value<QObject*>() );
-
- 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 @@
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 @@
}
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 @@
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 @@
);
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 @@
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::Attribute>( QNetworkRequest::User + 0 ), mTileReqNo );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ), j );
- request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 2 ), QRectF( x, y, dx, dy ) );
+ request.setAttribute( static_cast<QNetworkRequest::Attribute>( 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 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
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,9 +2697,7 @@
return WMS_DESCRIPTION;
} // QgsWmsProvider::description()
-QNetworkAccessManager *QgsWmsProvider::smNAM = 0;
-
/**
* Class factory to return a pointer to a newly created
* QgsWmsProvider object
Modified: trunk/qgis/src/providers/wms/qgswmsprovider.h
===================================================================
--- trunk/qgis/src/providers/wms/qgswmsprovider.h 2010-05-08 19:09:42 UTC (rev 13442)
+++ trunk/qgis/src/providers/wms/qgswmsprovider.h 2010-05-08 19:16:21 UTC (rev 13443)
@@ -883,9 +883,6 @@
int mTileWidth;
int mTileHeight;
QVector<double> mResolutions;
-
- //! wms provider's network access manager
- static QNetworkAccessManager *smNAM;
};
#endif
More information about the QGIS-commit
mailing list