Skip to content

Commit d0e5af4

Browse files
author
jef
committedApr 18, 2011
improve wms error and progress reporting (fixes #1576)
git-svn-id: http://svn.osgeo.org/qgis/trunk@15763 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 173037d commit d0e5af4

File tree

5 files changed

+87
-28
lines changed

5 files changed

+87
-28
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5522,7 +5522,15 @@ void QgisApp::layerWasAdded( QgsMapLayer *layer )
55225522

55235523
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer );
55245524
if ( rlayer )
5525+
{
5526+
// connect up any request the raster may make to update the app progress
5527+
connect( rlayer, SIGNAL( drawingProgress( int, int ) ), this, SLOT( showProgress( int, int ) ) );
5528+
5529+
// connect up any request the raster may make to update the statusbar message
5530+
connect( rlayer, SIGNAL( statusChanged( QString ) ), this, SLOT( showStatusMessage( QString ) ) );
5531+
55255532
provider = rlayer->dataProvider();
5533+
}
55265534

55275535
if ( provider )
55285536
{
@@ -6196,14 +6204,6 @@ bool QgisApp::addRasterLayer( QgsRasterLayer *theRasterLayer )
61966204
// register this layer with the central layers registry
61976205
QgsMapLayerRegistry::instance()->addMapLayer( theRasterLayer );
61986206

6199-
// connect up any request the raster may make to update the app progress
6200-
connect( theRasterLayer, SIGNAL( drawingProgress( int, int ) ),
6201-
this, SLOT( showProgress( int, int ) ) );
6202-
6203-
// connect up any request the raster may make to update the statusbar message
6204-
connect( theRasterLayer, SIGNAL( statusChanged( QString ) ),
6205-
this, SLOT( showStatusMessage( QString ) ) );
6206-
62076207
return true;
62086208
}
62096209

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,6 @@ QgsRasterLayer::QgsRasterLayer( int dummy,
155155

156156
// TODO: Connect signals from the dataprovider to the qgisapp
157157

158-
// Do a passthrough for the status bar text
159-
#if 0
160-
connect(
161-
mDataProvider, SIGNAL( statusChanged( QString ) ),
162-
this, SLOT( showStatusMessage( QString ) )
163-
);
164-
#endif
165158
QgsDebugMsg( "(8 arguments) exiting." );
166159

167160
emit statusChanged( tr( "QgsRasterLayer created" ) );
@@ -2199,7 +2192,7 @@ QLibrary* QgsRasterLayer::loadProviderLibrary( QString theProviderKey )
21992192

22002193
if ( !loaded )
22012194
{
2202-
QgsLogger::warning( "QgsRasterLayer::setDataProvider: Failed to load " );
2195+
QgsLogger::warning( "QgsRasterLayer::loadProviderLibrary: Failed to load " );
22032196
return NULL;
22042197
}
22052198
QgsDebugMsg( "Loaded data provider library" );
@@ -2223,7 +2216,7 @@ QgsRasterDataProvider* QgsRasterLayer::loadProvider( QString theProviderKey, QSt
22232216

22242217
if ( !classFactory )
22252218
{
2226-
QgsLogger::warning( "QgsRasterLayer::setDataProvider: Cannot resolve the classFactory function" );
2219+
QgsLogger::warning( "QgsRasterLayer::loadProvider: Cannot resolve the classFactory function" );
22272220
return NULL;
22282221
}
22292222
QgsDebugMsg( "Getting pointer to a mDataProvider object from the library" );
@@ -2237,7 +2230,7 @@ QgsRasterDataProvider* QgsRasterLayer::loadProvider( QString theProviderKey, QSt
22372230

22382231
if ( !myDataProvider )
22392232
{
2240-
QgsLogger::warning( "QgsRasterLayer::setDataProvider: Unable to instantiate the data provider plugin" );
2233+
QgsLogger::warning( "QgsRasterLayer::loadProvider: Unable to instantiate the data provider plugin" );
22412234
return NULL;
22422235
}
22432236
QgsDebugMsg( "Data driver created" );
@@ -2506,6 +2499,12 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
25062499
this, SLOT( onProgress( int, double, QString ) )
25072500
);
25082501

2502+
// Do a passthrough for the status bar text
2503+
connect(
2504+
mDataProvider, SIGNAL( statusChanged( QString ) ),
2505+
this, SIGNAL( statusChanged( QString ) )
2506+
);
2507+
25092508
//mark the layer as valid
25102509
mValid = true;
25112510

@@ -2895,6 +2894,7 @@ QStringList QgsRasterLayer::subLayers() const
28952894
return mDataProvider->subLayers();
28962895
}
28972896

2897+
28982898
void QgsRasterLayer::thumbnailAsPixmap( QPixmap * theQPixmap )
28992899
{
29002900
//TODO: This should be depreciated and a new function written that just returns a new QPixmap, it will be safer

‎src/gui/qgsmessageviewer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,15 @@ void QgsMessageViewer::setMessage( const QString& message, MessageType msgType )
6363
void QgsMessageViewer::showMessage( bool blocking )
6464
{
6565
if ( blocking )
66+
{
67+
QApplication::setOverrideCursor( Qt::ArrowCursor );
6668
exec();
69+
QApplication::restoreOverrideCursor();
70+
}
6771
else
72+
{
6873
show();
74+
}
6975
}
7076

7177
void QgsMessageViewer::setTitle( const QString& title )

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "qgsrectangle.h"
3333
#include "qgscoordinatereferencesystem.h"
3434
#include "qgsnetworkaccessmanager.h"
35+
#include <qgsmessageoutput.h>
3536

3637
#include <QNetworkRequest>
3738
#include <QNetworkReply>
@@ -772,9 +773,28 @@ void QgsWmsProvider::tileReplyFinished()
772773
if ( !status.isNull() && status.toInt() >= 400 )
773774
{
774775
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\nReason 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+
}
778798

779799
tileReplies.removeOne( reply );
780800
reply->deleteLater();
@@ -854,21 +874,40 @@ void QgsWmsProvider::cacheReplyFinished()
854874
if ( !status.isNull() && status.toInt() >= 400 )
855875
{
856876
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\nReason phrase: %2" ).arg( status.toInt() ).arg( phrase.toString() ) );
860879

861880
cacheReply->deleteLater();
862881
cacheReply = 0;
863882

864883
return;
865884
}
866885

886+
QString contentType = cacheReply->header( QNetworkRequest::ContentTypeHeader ).toString();
887+
QgsDebugMsg( "contentType: " + contentType );
888+
if ( contentType.startsWith( "image/" ) )
867889
{
868890
QImage myLocalImage = QImage::fromData( cacheReply->readAll() );
869891
QPainter p( cachedImage );
870892
p.drawImage( 0, 0, myLocalImage );
871893
}
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+
}
872911

873912
cacheReply->deleteLater();
874913
cacheReply = 0;
@@ -1015,12 +1054,16 @@ int QgsWmsProvider::bandCount() const
10151054

10161055
void QgsWmsProvider::capabilitiesReplyProgress( qint64 bytesReceived, qint64 bytesTotal )
10171056
{
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 );
10191060
}
10201061

10211062
void QgsWmsProvider::cacheReplyProgress( qint64 bytesReceived, qint64 bytesTotal )
10221063
{
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 );
10241067
}
10251068

10261069
bool QgsWmsProvider::parseCapabilitiesDom( QByteArray const &xml, QgsWmsCapabilitiesProperty& capabilitiesProperty )
@@ -2812,7 +2855,7 @@ void QgsWmsProvider::identifyReplyFinished()
28122855
QVariant redirect = mIdentifyReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
28132856
if ( !redirect.isNull() )
28142857
{
2815-
emit statusChanged( QString( "identify request redirected to %1" ).arg( redirect.toString() ) );
2858+
QgsDebugMsg( QString( "identify request redirected to %1" ).arg( redirect.toString() ) );
28162859
emit statusChanged( tr( "identify request redirected." ) );
28172860

28182861
mIdentifyReply->deleteLater();
@@ -2829,7 +2872,7 @@ void QgsWmsProvider::identifyReplyFinished()
28292872
{
28302873
QVariant phrase = mIdentifyReply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
28312874
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() );
28332876
emit statusChanged( mError );
28342877

28352878
mIdentifyResult = "";
@@ -2895,6 +2938,14 @@ void QgsWmsProvider::setAuthorization( QNetworkRequest &request ) const
28952938
}
28962939
}
28972940

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+
28982949
/**
28992950
* Class factory to return a pointer to a newly created
29002951
* QgsWmsProvider object

‎src/providers/wms/qgswmsprovider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,8 @@ class QgsWmsProvider : public QgsRasterDataProvider
650650
void tileReplyFinished();
651651

652652
private:
653+
void showMessageBox( const QString& title, const QString& text );
654+
653655
/**
654656
* \brief Retrieve and parse the (cached) Capabilities document from the server
655657
*

0 commit comments

Comments
 (0)