32
32
#include " qgsrectangle.h"
33
33
#include " qgscoordinatereferencesystem.h"
34
34
#include " qgsnetworkaccessmanager.h"
35
+ #include < qgsmessageoutput.h>
35
36
36
37
#include < QNetworkRequest>
37
38
#include < QNetworkReply>
@@ -772,9 +773,28 @@ void QgsWmsProvider::tileReplyFinished()
772
773
if ( !status.isNull () && status.toInt () >= 400 )
773
774
{
774
775
QVariant phrase = reply->attribute ( QNetworkRequest::HttpReasonPhraseAttribute );
775
- mErrorFormat = " text/plain" ;
776
- mError = tr ( " tile request err %1: %2" ).arg ( status.toInt () ).arg ( phrase.toString () );
777
- emit statusChanged ( mError );
776
+
777
+ showMessageBox ( tr ( " Tile request error" ), tr ( " Status: %1\n Reason phrase: %2" ).arg ( status.toInt () ).arg ( phrase.toString () ) );
778
+
779
+ tileReplies.removeOne ( reply );
780
+ reply->deleteLater ();
781
+
782
+ return ;
783
+ }
784
+
785
+ QString contentType = reply->header ( QNetworkRequest::ContentTypeHeader ).toString ();
786
+ QgsDebugMsg ( " contentType: " + contentType );
787
+ if ( !contentType.startsWith ( " image/" ) )
788
+ {
789
+ QByteArray text = reply->readAll ();
790
+ if ( contentType == " text/xml" && parseServiceExceptionReportDom ( text ) )
791
+ {
792
+ showMessageBox ( mErrorCaption , mError );
793
+ }
794
+ else
795
+ {
796
+ showMessageBox ( " Tile request error" , tr ( " response: %1" ).arg ( QString::fromUtf8 ( text ) ) );
797
+ }
778
798
779
799
tileReplies.removeOne ( reply );
780
800
reply->deleteLater ();
@@ -854,21 +874,40 @@ void QgsWmsProvider::cacheReplyFinished()
854
874
if ( !status.isNull () && status.toInt () >= 400 )
855
875
{
856
876
QVariant phrase = cacheReply->attribute ( QNetworkRequest::HttpReasonPhraseAttribute );
857
- mErrorFormat = " text/plain" ;
858
- mError = tr ( " map request error %1: %2" ).arg ( status.toInt () ).arg ( phrase.toString () );
859
- emit statusChanged ( mError );
877
+
878
+ showMessageBox ( tr ( " Map request error" ), tr ( " Status: %1\n Reason phrase: %2" ).arg ( status.toInt () ).arg ( phrase.toString () ) );
860
879
861
880
cacheReply->deleteLater ();
862
881
cacheReply = 0 ;
863
882
864
883
return ;
865
884
}
866
885
886
+ QString contentType = cacheReply->header ( QNetworkRequest::ContentTypeHeader ).toString ();
887
+ QgsDebugMsg ( " contentType: " + contentType );
888
+ if ( contentType.startsWith ( " image/" ) )
867
889
{
868
890
QImage myLocalImage = QImage::fromData ( cacheReply->readAll () );
869
891
QPainter p ( cachedImage );
870
892
p.drawImage ( 0 , 0 , myLocalImage );
871
893
}
894
+ else
895
+ {
896
+ QByteArray text = cacheReply->readAll ();
897
+ if ( contentType == " text/xml" && parseServiceExceptionReportDom ( text ) )
898
+ {
899
+ showMessageBox ( mErrorCaption , mError );
900
+ }
901
+ else
902
+ {
903
+ showMessageBox ( tr ( " Map request error" ), tr ( " Response: %1" ).arg ( QString::fromUtf8 ( text ) ) );
904
+ }
905
+
906
+ cacheReply->deleteLater ();
907
+ cacheReply = 0 ;
908
+
909
+ return ;
910
+ }
872
911
873
912
cacheReply->deleteLater ();
874
913
cacheReply = 0 ;
@@ -1015,12 +1054,16 @@ int QgsWmsProvider::bandCount() const
1015
1054
1016
1055
void QgsWmsProvider::capabilitiesReplyProgress ( qint64 bytesReceived, qint64 bytesTotal )
1017
1056
{
1018
- emit statusChanged ( tr ( " %1 of %2 bytes of capabilities downloaded." ).arg ( bytesReceived ).arg ( bytesTotal < 0 ? QString ( " unknown number of" ) : QString::number ( bytesTotal ) ) );
1057
+ QString msg = tr ( " %1 of %2 bytes of capabilities downloaded." ).arg ( bytesReceived ).arg ( bytesTotal < 0 ? QString ( " unknown number of" ) : QString::number ( bytesTotal ) );
1058
+ QgsDebugMsg ( msg );
1059
+ emit statusChanged ( msg );
1019
1060
}
1020
1061
1021
1062
void QgsWmsProvider::cacheReplyProgress ( qint64 bytesReceived, qint64 bytesTotal )
1022
1063
{
1023
- emit statusChanged ( tr ( " %1 of %2 bytes of map downloaded." ).arg ( bytesReceived ).arg ( bytesTotal < 0 ? QString ( " unknown number of" ) : QString::number ( bytesTotal ) ) );
1064
+ QString msg = tr ( " %1 of %2 bytes of map downloaded." ).arg ( bytesReceived ).arg ( bytesTotal < 0 ? QString ( " unknown number of" ) : QString::number ( bytesTotal ) );
1065
+ QgsDebugMsg ( msg );
1066
+ emit statusChanged ( msg );
1024
1067
}
1025
1068
1026
1069
bool QgsWmsProvider::parseCapabilitiesDom ( QByteArray const &xml, QgsWmsCapabilitiesProperty& capabilitiesProperty )
@@ -2812,7 +2855,7 @@ void QgsWmsProvider::identifyReplyFinished()
2812
2855
QVariant redirect = mIdentifyReply ->attribute ( QNetworkRequest::RedirectionTargetAttribute );
2813
2856
if ( !redirect.isNull () )
2814
2857
{
2815
- emit statusChanged ( QString ( " identify request redirected to %1" ).arg ( redirect.toString () ) );
2858
+ QgsDebugMsg ( QString ( " identify request redirected to %1" ).arg ( redirect.toString () ) );
2816
2859
emit statusChanged ( tr ( " identify request redirected." ) );
2817
2860
2818
2861
mIdentifyReply ->deleteLater ();
@@ -2829,7 +2872,7 @@ void QgsWmsProvider::identifyReplyFinished()
2829
2872
{
2830
2873
QVariant phrase = mIdentifyReply ->attribute ( QNetworkRequest::HttpReasonPhraseAttribute );
2831
2874
mErrorFormat = " text/plain" ;
2832
- mError = tr ( " map request error %1: %2" ).arg ( status.toInt () ).arg ( phrase.toString () );
2875
+ mError = tr ( " Map request error %1: %2" ).arg ( status.toInt () ).arg ( phrase.toString () );
2833
2876
emit statusChanged ( mError );
2834
2877
2835
2878
mIdentifyResult = " " ;
@@ -2895,6 +2938,14 @@ void QgsWmsProvider::setAuthorization( QNetworkRequest &request ) const
2895
2938
}
2896
2939
}
2897
2940
2941
+ void QgsWmsProvider::showMessageBox ( const QString& title, const QString& text )
2942
+ {
2943
+ QgsMessageOutput *message = QgsMessageOutput::createMessageOutput ();
2944
+ message->setTitle ( title );
2945
+ message->setMessage ( text, QgsMessageOutput::MessageText );
2946
+ message->showMessage ();
2947
+ }
2948
+
2898
2949
/* *
2899
2950
* Class factory to return a pointer to a newly created
2900
2951
* QgsWmsProvider object
0 commit comments