mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-12 00:06:43 -04:00
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 git-svn-id: http://svn.osgeo.org/qgis/trunk@13443 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
92e9c558fd
commit
f6483e9df5
@ -79,4 +79,6 @@
|
||||
%Include qgsvectorlayer.sip
|
||||
%Include qgsvectoroverlay.sip
|
||||
|
||||
%Include qgsnetworkaccessmanager.sip
|
||||
|
||||
%Include symbology-ng-core.sip
|
||||
|
51
python/core/qgsnetworkaccessmanager.sip
Normal file
51
python/core/qgsnetworkaccessmanager.sip
Normal file
@ -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 );
|
||||
};
|
@ -75,7 +75,6 @@ SET(QGIS_APP_SRCS
|
||||
qgsuniquevaluedialog.cpp
|
||||
qgsvectorlayerproperties.cpp
|
||||
qgsquerybuilder.cpp
|
||||
qgsnetworkproxyfactory.cpp
|
||||
|
||||
qgsmanageconnectionsdialog.cpp
|
||||
|
||||
|
@ -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 @@ 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<QObject*>( 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<QNetworkDiskCache*>( nam()->cache() );
|
||||
QNetworkDiskCache *cache = qobject_cast<QNetworkDiskCache*>( 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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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
|
@ -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 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
|
||||
|
||||
#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_mBrowseCacheDirectory_clicked()
|
||||
void QgsOptions::on_mClearCache_clicked()
|
||||
{
|
||||
#if QT_VERSION >= 0x40500
|
||||
QgisApp::instance()->nam()->cache()->clear();
|
||||
QgsNetworkAccessManager::instance()->cache()->clear();
|
||||
#endif
|
||||
}
|
||||
|
@ -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 @@ 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() ) );
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
117
src/core/qgsnetworkaccessmanager.cpp
Normal file
117
src/core/qgsnetworkaccessmanager.cpp
Normal file
@ -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;
|
||||
}
|
83
src/core/qgsnetworkaccessmanager.h
Normal file
83
src/core/qgsnetworkaccessmanager.h
Normal file
@ -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
|
@ -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 @@ QgsWmsProvider::QgsWmsProvider( QString const &uri )
|
||||
, 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 @@ 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::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 @@ 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
|
||||
|
@ -883,9 +883,6 @@ class QgsWmsProvider : public QgsRasterDataProvider
|
||||
int mTileWidth;
|
||||
int mTileHeight;
|
||||
QVector<double> mResolutions;
|
||||
|
||||
//! wms provider's network access manager
|
||||
static QNetworkAccessManager *smNAM;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user