Skip to content
Permalink
Browse files

Merge https://github.com/luipir/Quantum-GIS

  • Loading branch information
jef-n committed Oct 15, 2013
2 parents 125decf + 23af7f7 commit 3035c95c8b1ee3558b71df42830b69d1fa95caba
Showing with 90 additions and 13 deletions.
  1. +6 −0 src/app/qgsoptions.cpp
  2. +57 −13 src/providers/wms/qgswmsprovider.cpp
  3. +9 −0 src/providers/wms/qgswmsprovider.h
  4. +18 −0 src/ui/qgsoptionsbase.ui
@@ -251,6 +251,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
// WMS/WMS-C tile expiry time
mDefaultTileExpirySpinBox->setValue( settings.value( "/qgis/defaultTileExpiry", "24" ).toInt() );

// WMS/WMS-C default max retry in case of tile request errors
mDefaultTileMaxRetrySpinBox->setValue( settings.value( "/qgis/defaultTileMaxRetry", "3" ).toInt() );

//Web proxy settings
grpProxy->setChecked( settings.value( "proxy/proxyEnabled", "0" ).toBool() );
leProxyHost->setText( settings.value( "proxy/proxyHost", "" ).toString() );
@@ -888,6 +891,9 @@ void QgsOptions::saveOptions()
// WMS/WMS-C tile expiry time
settings.setValue( "/qgis/defaultTileExpiry", mDefaultTileExpirySpinBox->value() );

// WMS/WMS-C default max retry in case of tile request errors
settings.setValue( "/qgis/defaultTileMaxRetry", mDefaultTileMaxRetrySpinBox->value() );

//Web proxy settings
settings.setValue( "proxy/proxyEnabled", grpProxy->isChecked() );
settings.setValue( "proxy/proxyHost", leProxyHost->text() );
@@ -80,7 +80,6 @@ static QString WMS_DESCRIPTION = "OGC Web Map Service version 1.3 data provider"

static QString DEFAULT_LATLON_CRS = "CRS:84";


QgsWmsProvider::QgsWmsProvider( QString const &uri )
: QgsRasterDataProvider( uri )
, mHttpUri( uri )
@@ -844,6 +843,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
}

int i = 0;
int retry = 0;
for ( int row = row0; row <= row1; row++ )
{
for ( int col = col0; col <= col1; col++ )
@@ -865,6 +865,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ), i );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 2 ),
QRectF( tm->topLeft.x() + col * twMap, tm->topLeft.y() - ( row + 1 ) * thMap, twMap, thMap ) );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ), retry );

QgsDebugMsg( QString( "gettile: %1" ).arg( turl ) );
QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( request );
@@ -901,6 +902,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
url.removeQueryItem( "TILECOL" );

int i = 0;
int retry = 0;
for ( int row = row0; row <= row1; row++ )
{
for ( int col = col0; col <= col1; col++ )
@@ -918,6 +920,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ), i );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 2 ),
QRectF( tm->topLeft.x() + col * twMap, tm->topLeft.y() - ( row + 1 ) * thMap, twMap, thMap ) );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ), retry );

QgsDebugMsg( QString( "gettile: %1" ).arg( turl ) );
QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( request );
@@ -941,6 +944,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
}

int i = 0;
int retry = 0;
for ( int row = row0; row <= row1; row++ )
{
for ( int col = col0; col <= col1; col++ )
@@ -958,6 +962,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ), i );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 2 ),
QRectF( tm->topLeft.x() + col * twMap, tm->topLeft.y() - ( row + 1 ) * thMap, twMap, thMap ) );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ), retry );

QgsDebugMsg( QString( "gettile: %1" ).arg( turl ) );
QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( request );
@@ -1034,6 +1039,47 @@ void QgsWmsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
//delete image;
}

void QgsWmsProvider::repeatTileRequest( QNetworkRequest const &oldRequest )
{
if ( mErrors == 100 )
{
QgsMessageLog::logMessage( tr( "Not logging more than 100 request errors." ), tr( "WMS" ) );
}

QNetworkRequest request( oldRequest );

QString url = request.url().toString();
int tileReqNo = request.attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 0 ) ).toInt();
int tileNo = request.attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ) ).toInt();
int retry = request.attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ) ).toInt();
retry++;

QSettings s;
int maxRetry = s.value( "/qgis/defaultTileMaxRetry", "3" ).toInt();
if ( retry > maxRetry )
{
if ( mErrors < 100 )
{
QgsMessageLog::logMessage( tr( "Tile request max retry error. Failed %1 requests for tile %2 of tileRequest %3 (url: %4)" )
.arg( maxRetry ).arg( tileNo ).arg( tileReqNo ).arg( url ), tr( "WMS" ) );
}
return;
}

setAuthorization( request );
if ( mErrors < 100 )
{
QgsMessageLog::logMessage( tr( "repeat tileRequest %1 tile %2(retry %3)" )
.arg( tileReqNo ).arg( tileNo ).arg( retry ), tr( "WMS" ), QgsMessageLog::INFO );
}
QgsDebugMsg( QString( "repeat tileRequest %1 %2(retry %3) for url: %4" ).arg( tileReqNo ).arg( tileNo ).arg( retry ).arg( url ) );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ), retry );

QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( request );
mTileReplies << reply;
connect( reply, SIGNAL( finished() ), this, SLOT( tileReplyFinished() ) );
}

void QgsWmsProvider::tileReplyFinished()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>( sender() );
@@ -1080,18 +1126,19 @@ void QgsWmsProvider::tileReplyFinished()
int tileReqNo = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 0 ) ).toInt();
int tileNo = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ) ).toInt();
QRectF r = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 2 ) ).toRectF();
int retry = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ) ).toInt();

#if QT_VERSION >= 0x40500
QgsDebugMsg( QString( "tile reply %1 (%2) tile:%3 rect:%4,%5 %6,%7) fromcache:%8 error:%9 url:%10" )
.arg( tileReqNo ).arg( mTileReqNo ).arg( tileNo )
QgsDebugMsg( QString( "tile reply %1 (%2) tile:%3(retry %4) rect:%5,%6 %7,%8) fromcache:%9 error:%10 url:%11" )
.arg( tileReqNo ).arg( mTileReqNo ).arg( tileNo ).arg( retry )
.arg( r.left(), 0, 'f' ).arg( r.bottom(), 0, 'f' ).arg( r.right(), 0, 'f' ).arg( r.top(), 0, 'f' )
.arg( fromCache )
.arg( reply->errorString() )
.arg( reply->url().toString() )
);
#else
QgsDebugMsg( QString( "tile reply %1 (%2) tile:%3 rect:%4,%5 %6,%7) error:%8 url:%9" )
.arg( tileReqNo ).arg( mTileReqNo ).arg( tileNo )
QgsDebugMsg( QString( "tile reply %1 (%2) tile:%3(retry %4) rect:%5,%6 %7,%8) error:%9 url:%10" )
.arg( tileReqNo ).arg( mTileReqNo ).arg( tileNo ).arg( retry )
.arg( r.left(), 0, 'f' ).arg( r.bottom(), 0, 'f' ).arg( r.right(), 0, 'f' ).arg( r.top(), 0, 'f' )
.arg( reply->errorString() )
.arg( reply->url().toString() )
@@ -1110,6 +1157,7 @@ void QgsWmsProvider::tileReplyFinished()
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 0 ), tileReqNo );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ), tileNo );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 2 ), r );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ), retry );

mTileReplies.removeOne( reply );
reply->deleteLater();
@@ -1205,6 +1253,8 @@ void QgsWmsProvider::tileReplyFinished()
{
QgsMessageLog::logMessage( tr( "Returned image is flawed [Content-Type:%1; URL: %2]" )
.arg( contentType ).arg( reply->url().toString() ), tr( "WMS" ) );

repeatTileRequest( reply->request() );
}
}
else
@@ -1224,14 +1274,8 @@ void QgsWmsProvider::tileReplyFinished()
else
{
mErrors++;
if ( mErrors < 100 )
{
QgsMessageLog::logMessage( tr( "Tile request failed [error:%1 url:%2]" ).arg( reply->errorString() ).arg( reply->url().toString() ), tr( "WMS" ) );
}
else if ( mErrors == 100 )
{
QgsMessageLog::logMessage( tr( "Not logging more than 100 request errors." ), tr( "WMS" ) );
}

repeatTileRequest( reply->request() );

mTileReplies.removeOne( reply );
reply->deleteLater();
@@ -743,6 +743,15 @@ class QgsWmsProvider : public QgsRasterDataProvider
// case insensitive attribute value lookup
static QString nodeAttribute( const QDomElement &e, QString name, QString defValue = QString::null );

/**
* \brief Relaunch tile request cloning previous request parameters and managing max repeat
*
* \param oldRequest request to clone to generate new tile request
*
* request is not launched if max retry is reached. Message is logged.
*/
void repeatTileRequest( QNetworkRequest const &oldRequest );

/**
* \brief Retrieve and parse the (cached) Capabilities document from the server
*
@@ -3785,6 +3785,24 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_33">
<item>
<widget class="QLabel" name="label_57">
<property name="text">
<string>Max retry in case of tile request errors</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="mDefaultTileMaxRetrySpinBox">
<property name="maximum">
<number>100000000</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>

0 comments on commit 3035c95

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