Skip to content

Commit

Permalink
improve wms error and progress reporting (fixes #1576)
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15763 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 18, 2011
1 parent 6e38336 commit 93404c4
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 28 deletions.
16 changes: 8 additions & 8 deletions src/app/qgisapp.cpp
Expand Up @@ -5522,7 +5522,15 @@ void QgisApp::layerWasAdded( QgsMapLayer *layer )

QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer );
if ( rlayer )
{
// connect up any request the raster may make to update the app progress
connect( rlayer, SIGNAL( drawingProgress( int, int ) ), this, SLOT( showProgress( int, int ) ) );

// connect up any request the raster may make to update the statusbar message
connect( rlayer, SIGNAL( statusChanged( QString ) ), this, SLOT( showStatusMessage( QString ) ) );

provider = rlayer->dataProvider();
}

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

// connect up any request the raster may make to update the app progress
connect( theRasterLayer, SIGNAL( drawingProgress( int, int ) ),
this, SLOT( showProgress( int, int ) ) );

// connect up any request the raster may make to update the statusbar message
connect( theRasterLayer, SIGNAL( statusChanged( QString ) ),
this, SLOT( showStatusMessage( QString ) ) );

return true;
}

Expand Down
20 changes: 10 additions & 10 deletions src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -155,13 +155,6 @@ QgsRasterLayer::QgsRasterLayer( int dummy,

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

// Do a passthrough for the status bar text
#if 0
connect(
mDataProvider, SIGNAL( statusChanged( QString ) ),
this, SLOT( showStatusMessage( QString ) )
);
#endif
QgsDebugMsg( "(8 arguments) exiting." );

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

if ( !loaded )
{
QgsLogger::warning( "QgsRasterLayer::setDataProvider: Failed to load " );
QgsLogger::warning( "QgsRasterLayer::loadProviderLibrary: Failed to load " );
return NULL;
}
QgsDebugMsg( "Loaded data provider library" );
Expand All @@ -2223,7 +2216,7 @@ QgsRasterDataProvider* QgsRasterLayer::loadProvider( QString theProviderKey, QSt

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

if ( !myDataProvider )
{
QgsLogger::warning( "QgsRasterLayer::setDataProvider: Unable to instantiate the data provider plugin" );
QgsLogger::warning( "QgsRasterLayer::loadProvider: Unable to instantiate the data provider plugin" );
return NULL;
}
QgsDebugMsg( "Data driver created" );
Expand Down Expand Up @@ -2506,6 +2499,12 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
this, SLOT( onProgress( int, double, QString ) )
);

// Do a passthrough for the status bar text
connect(
mDataProvider, SIGNAL( statusChanged( QString ) ),
this, SIGNAL( statusChanged( QString ) )
);

//mark the layer as valid
mValid = true;

Expand Down Expand Up @@ -2895,6 +2894,7 @@ QStringList QgsRasterLayer::subLayers() const
return mDataProvider->subLayers();
}


void QgsRasterLayer::thumbnailAsPixmap( QPixmap * theQPixmap )
{
//TODO: This should be depreciated and a new function written that just returns a new QPixmap, it will be safer
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmessageviewer.cpp
Expand Up @@ -63,9 +63,15 @@ void QgsMessageViewer::setMessage( const QString& message, MessageType msgType )
void QgsMessageViewer::showMessage( bool blocking )
{
if ( blocking )
{
QApplication::setOverrideCursor( Qt::ArrowCursor );
exec();
QApplication::restoreOverrideCursor();
}
else
{
show();
}
}

void QgsMessageViewer::setTitle( const QString& title )
Expand Down
71 changes: 61 additions & 10 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -32,6 +32,7 @@
#include "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h"
#include "qgsnetworkaccessmanager.h"
#include <qgsmessageoutput.h>

#include <QNetworkRequest>
#include <QNetworkReply>
Expand Down Expand Up @@ -772,9 +773,28 @@ void QgsWmsProvider::tileReplyFinished()
if ( !status.isNull() && status.toInt() >= 400 )
{
QVariant phrase = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
mErrorFormat = "text/plain";
mError = tr( "tile request err %1: %2" ).arg( status.toInt() ).arg( phrase.toString() );
emit statusChanged( mError );

showMessageBox( tr( "Tile request error" ), tr( "Status: %1\nReason phrase: %2" ).arg( status.toInt() ).arg( phrase.toString() ) );

tileReplies.removeOne( reply );
reply->deleteLater();

return;
}

QString contentType = reply->header( QNetworkRequest::ContentTypeHeader ).toString();
QgsDebugMsg( "contentType: " + contentType );
if ( !contentType.startsWith( "image/" ) )
{
QByteArray text = reply->readAll();
if ( contentType == "text/xml" && parseServiceExceptionReportDom( text ) )
{
showMessageBox( mErrorCaption, mError );
}
else
{
showMessageBox( "Tile request error", tr( "response: %1" ).arg( QString::fromUtf8( text ) ) );
}

tileReplies.removeOne( reply );
reply->deleteLater();
Expand Down Expand Up @@ -854,21 +874,40 @@ void QgsWmsProvider::cacheReplyFinished()
if ( !status.isNull() && status.toInt() >= 400 )
{
QVariant phrase = cacheReply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
mErrorFormat = "text/plain";
mError = tr( "map request error %1: %2" ).arg( status.toInt() ).arg( phrase.toString() );
emit statusChanged( mError );

showMessageBox( tr( "Map request error" ), tr( "Status: %1\nReason phrase: %2" ).arg( status.toInt() ).arg( phrase.toString() ) );

cacheReply->deleteLater();
cacheReply = 0;

return;
}

QString contentType = cacheReply->header( QNetworkRequest::ContentTypeHeader ).toString();
QgsDebugMsg( "contentType: " + contentType );
if ( contentType.startsWith( "image/" ) )
{
QImage myLocalImage = QImage::fromData( cacheReply->readAll() );
QPainter p( cachedImage );
p.drawImage( 0, 0, myLocalImage );
}
else
{
QByteArray text = cacheReply->readAll();
if ( contentType == "text/xml" && parseServiceExceptionReportDom( text ) )
{
showMessageBox( mErrorCaption, mError );
}
else
{
showMessageBox( tr( "Map request error" ), tr( "Response: %1" ).arg( QString::fromUtf8( text ) ) );
}

cacheReply->deleteLater();
cacheReply = 0;

return;
}

cacheReply->deleteLater();
cacheReply = 0;
Expand Down Expand Up @@ -1015,12 +1054,16 @@ int QgsWmsProvider::bandCount() const

void QgsWmsProvider::capabilitiesReplyProgress( qint64 bytesReceived, qint64 bytesTotal )
{
emit statusChanged( tr( "%1 of %2 bytes of capabilities downloaded." ).arg( bytesReceived ).arg( bytesTotal < 0 ? QString( "unknown number of" ) : QString::number( bytesTotal ) ) );
QString msg = tr( "%1 of %2 bytes of capabilities downloaded." ).arg( bytesReceived ).arg( bytesTotal < 0 ? QString( "unknown number of" ) : QString::number( bytesTotal ) );
QgsDebugMsg( msg );
emit statusChanged( msg );
}

void QgsWmsProvider::cacheReplyProgress( qint64 bytesReceived, qint64 bytesTotal )
{
emit statusChanged( tr( "%1 of %2 bytes of map downloaded." ).arg( bytesReceived ).arg( bytesTotal < 0 ? QString( "unknown number of" ) : QString::number( bytesTotal ) ) );
QString msg = tr( "%1 of %2 bytes of map downloaded." ).arg( bytesReceived ).arg( bytesTotal < 0 ? QString( "unknown number of" ) : QString::number( bytesTotal ) );
QgsDebugMsg( msg );
emit statusChanged( msg );
}

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

mIdentifyReply->deleteLater();
Expand All @@ -2829,7 +2872,7 @@ void QgsWmsProvider::identifyReplyFinished()
{
QVariant phrase = mIdentifyReply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
mErrorFormat = "text/plain";
mError = tr( "map request error %1: %2" ).arg( status.toInt() ).arg( phrase.toString() );
mError = tr( "Map request error %1: %2" ).arg( status.toInt() ).arg( phrase.toString() );
emit statusChanged( mError );

mIdentifyResult = "";
Expand Down Expand Up @@ -2895,6 +2938,14 @@ void QgsWmsProvider::setAuthorization( QNetworkRequest &request ) const
}
}

void QgsWmsProvider::showMessageBox( const QString& title, const QString& text )
{
QgsMessageOutput *message = QgsMessageOutput::createMessageOutput();
message->setTitle( title );
message->setMessage( text, QgsMessageOutput::MessageText );
message->showMessage();
}

/**
* Class factory to return a pointer to a newly created
* QgsWmsProvider object
Expand Down
2 changes: 2 additions & 0 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -650,6 +650,8 @@ class QgsWmsProvider : public QgsRasterDataProvider
void tileReplyFinished();

private:
void showMessageBox( const QString& title, const QString& text );

/**
* \brief Retrieve and parse the (cached) Capabilities document from the server
*
Expand Down

0 comments on commit 93404c4

Please sign in to comment.