Skip to content

Commit 3035c95

Browse files
committedOct 15, 2013
2 parents 125decf + 23af7f7 commit 3035c95

File tree

4 files changed

+90
-13
lines changed

4 files changed

+90
-13
lines changed
 

‎src/app/qgsoptions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WFlags fl ) :
251251
// WMS/WMS-C tile expiry time
252252
mDefaultTileExpirySpinBox->setValue( settings.value( "/qgis/defaultTileExpiry", "24" ).toInt() );
253253

254+
// WMS/WMS-C default max retry in case of tile request errors
255+
mDefaultTileMaxRetrySpinBox->setValue( settings.value( "/qgis/defaultTileMaxRetry", "3" ).toInt() );
256+
254257
//Web proxy settings
255258
grpProxy->setChecked( settings.value( "proxy/proxyEnabled", "0" ).toBool() );
256259
leProxyHost->setText( settings.value( "proxy/proxyHost", "" ).toString() );
@@ -888,6 +891,9 @@ void QgsOptions::saveOptions()
888891
// WMS/WMS-C tile expiry time
889892
settings.setValue( "/qgis/defaultTileExpiry", mDefaultTileExpirySpinBox->value() );
890893

894+
// WMS/WMS-C default max retry in case of tile request errors
895+
settings.setValue( "/qgis/defaultTileMaxRetry", mDefaultTileMaxRetrySpinBox->value() );
896+
891897
//Web proxy settings
892898
settings.setValue( "proxy/proxyEnabled", grpProxy->isChecked() );
893899
settings.setValue( "proxy/proxyHost", leProxyHost->text() );

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ static QString WMS_DESCRIPTION = "OGC Web Map Service version 1.3 data provider"
8080

8181
static QString DEFAULT_LATLON_CRS = "CRS:84";
8282

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

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

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

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

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

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

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

1042+
void QgsWmsProvider::repeatTileRequest( QNetworkRequest const &oldRequest )
1043+
{
1044+
if ( mErrors == 100 )
1045+
{
1046+
QgsMessageLog::logMessage( tr( "Not logging more than 100 request errors." ), tr( "WMS" ) );
1047+
}
1048+
1049+
QNetworkRequest request( oldRequest );
1050+
1051+
QString url = request.url().toString();
1052+
int tileReqNo = request.attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 0 ) ).toInt();
1053+
int tileNo = request.attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ) ).toInt();
1054+
int retry = request.attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ) ).toInt();
1055+
retry++;
1056+
1057+
QSettings s;
1058+
int maxRetry = s.value( "/qgis/defaultTileMaxRetry", "3" ).toInt();
1059+
if ( retry > maxRetry )
1060+
{
1061+
if ( mErrors < 100 )
1062+
{
1063+
QgsMessageLog::logMessage( tr( "Tile request max retry error. Failed %1 requests for tile %2 of tileRequest %3 (url: %4)" )
1064+
.arg( maxRetry ).arg( tileNo ).arg( tileReqNo ).arg( url ), tr( "WMS" ) );
1065+
}
1066+
return;
1067+
}
1068+
1069+
setAuthorization( request );
1070+
if ( mErrors < 100 )
1071+
{
1072+
QgsMessageLog::logMessage( tr( "repeat tileRequest %1 tile %2(retry %3)" )
1073+
.arg( tileReqNo ).arg( tileNo ).arg( retry ), tr( "WMS" ), QgsMessageLog::INFO );
1074+
}
1075+
QgsDebugMsg( QString( "repeat tileRequest %1 %2(retry %3) for url: %4" ).arg( tileReqNo ).arg( tileNo ).arg( retry ).arg( url ) );
1076+
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ), retry );
1077+
1078+
QNetworkReply *reply = QgsNetworkAccessManager::instance()->get( request );
1079+
mTileReplies << reply;
1080+
connect( reply, SIGNAL( finished() ), this, SLOT( tileReplyFinished() ) );
1081+
}
1082+
10371083
void QgsWmsProvider::tileReplyFinished()
10381084
{
10391085
QNetworkReply *reply = qobject_cast<QNetworkReply*>( sender() );
@@ -1080,18 +1126,19 @@ void QgsWmsProvider::tileReplyFinished()
10801126
int tileReqNo = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 0 ) ).toInt();
10811127
int tileNo = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ) ).toInt();
10821128
QRectF r = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 2 ) ).toRectF();
1129+
int retry = reply->request().attribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ) ).toInt();
10831130

10841131
#if QT_VERSION >= 0x40500
1085-
QgsDebugMsg( QString( "tile reply %1 (%2) tile:%3 rect:%4,%5 %6,%7) fromcache:%8 error:%9 url:%10" )
1086-
.arg( tileReqNo ).arg( mTileReqNo ).arg( tileNo )
1132+
QgsDebugMsg( QString( "tile reply %1 (%2) tile:%3(retry %4) rect:%5,%6 %7,%8) fromcache:%9 error:%10 url:%11" )
1133+
.arg( tileReqNo ).arg( mTileReqNo ).arg( tileNo ).arg( retry )
10871134
.arg( r.left(), 0, 'f' ).arg( r.bottom(), 0, 'f' ).arg( r.right(), 0, 'f' ).arg( r.top(), 0, 'f' )
10881135
.arg( fromCache )
10891136
.arg( reply->errorString() )
10901137
.arg( reply->url().toString() )
10911138
);
10921139
#else
1093-
QgsDebugMsg( QString( "tile reply %1 (%2) tile:%3 rect:%4,%5 %6,%7) error:%8 url:%9" )
1094-
.arg( tileReqNo ).arg( mTileReqNo ).arg( tileNo )
1140+
QgsDebugMsg( QString( "tile reply %1 (%2) tile:%3(retry %4) rect:%5,%6 %7,%8) error:%9 url:%10" )
1141+
.arg( tileReqNo ).arg( mTileReqNo ).arg( tileNo ).arg( retry )
10951142
.arg( r.left(), 0, 'f' ).arg( r.bottom(), 0, 'f' ).arg( r.right(), 0, 'f' ).arg( r.top(), 0, 'f' )
10961143
.arg( reply->errorString() )
10971144
.arg( reply->url().toString() )
@@ -1110,6 +1157,7 @@ void QgsWmsProvider::tileReplyFinished()
11101157
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 0 ), tileReqNo );
11111158
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 1 ), tileNo );
11121159
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 2 ), r );
1160+
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 3 ), retry );
11131161

11141162
mTileReplies.removeOne( reply );
11151163
reply->deleteLater();
@@ -1205,6 +1253,8 @@ void QgsWmsProvider::tileReplyFinished()
12051253
{
12061254
QgsMessageLog::logMessage( tr( "Returned image is flawed [Content-Type:%1; URL: %2]" )
12071255
.arg( contentType ).arg( reply->url().toString() ), tr( "WMS" ) );
1256+
1257+
repeatTileRequest( reply->request() );
12081258
}
12091259
}
12101260
else
@@ -1224,14 +1274,8 @@ void QgsWmsProvider::tileReplyFinished()
12241274
else
12251275
{
12261276
mErrors++;
1227-
if ( mErrors < 100 )
1228-
{
1229-
QgsMessageLog::logMessage( tr( "Tile request failed [error:%1 url:%2]" ).arg( reply->errorString() ).arg( reply->url().toString() ), tr( "WMS" ) );
1230-
}
1231-
else if ( mErrors == 100 )
1232-
{
1233-
QgsMessageLog::logMessage( tr( "Not logging more than 100 request errors." ), tr( "WMS" ) );
1234-
}
1277+
1278+
repeatTileRequest( reply->request() );
12351279

12361280
mTileReplies.removeOne( reply );
12371281
reply->deleteLater();

‎src/providers/wms/qgswmsprovider.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,15 @@ class QgsWmsProvider : public QgsRasterDataProvider
743743
// case insensitive attribute value lookup
744744
static QString nodeAttribute( const QDomElement &e, QString name, QString defValue = QString::null );
745745

746+
/**
747+
* \brief Relaunch tile request cloning previous request parameters and managing max repeat
748+
*
749+
* \param oldRequest request to clone to generate new tile request
750+
*
751+
* request is not launched if max retry is reached. Message is logged.
752+
*/
753+
void repeatTileRequest( QNetworkRequest const &oldRequest );
754+
746755
/**
747756
* \brief Retrieve and parse the (cached) Capabilities document from the server
748757
*

‎src/ui/qgsoptionsbase.ui

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,6 +3785,24 @@
37853785
</item>
37863786
</layout>
37873787
</item>
3788+
<item>
3789+
<layout class="QHBoxLayout" name="horizontalLayout_33">
3790+
<item>
3791+
<widget class="QLabel" name="label_57">
3792+
<property name="text">
3793+
<string>Max retry in case of tile request errors</string>
3794+
</property>
3795+
</widget>
3796+
</item>
3797+
<item>
3798+
<widget class="QSpinBox" name="mDefaultTileMaxRetrySpinBox">
3799+
<property name="maximum">
3800+
<number>100000000</number>
3801+
</property>
3802+
</widget>
3803+
</item>
3804+
</layout>
3805+
</item>
37883806
</layout>
37893807
</widget>
37903808
</item>

0 commit comments

Comments
 (0)
Please sign in to comment.