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 ); QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer );
if ( rlayer ) 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(); provider = rlayer->dataProvider();
}


if ( provider ) if ( provider )
{ {
Expand Down Expand Up @@ -6196,14 +6204,6 @@ bool QgisApp::addRasterLayer( QgsRasterLayer *theRasterLayer )
// register this layer with the central layers registry // register this layer with the central layers registry
QgsMapLayerRegistry::instance()->addMapLayer( theRasterLayer ); 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; 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 // 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." ); QgsDebugMsg( "(8 arguments) exiting." );


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


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


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


if ( !myDataProvider ) 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; return NULL;
} }
QgsDebugMsg( "Data driver created" ); QgsDebugMsg( "Data driver created" );
Expand Down Expand Up @@ -2506,6 +2499,12 @@ void QgsRasterLayer::setDataProvider( QString const & provider,
this, SLOT( onProgress( int, double, QString ) ) 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 //mark the layer as valid
mValid = true; mValid = true;


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



void QgsRasterLayer::thumbnailAsPixmap( QPixmap * theQPixmap ) 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 //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 ) void QgsMessageViewer::showMessage( bool blocking )
{ {
if ( blocking ) if ( blocking )
{
QApplication::setOverrideCursor( Qt::ArrowCursor );
exec(); exec();
QApplication::restoreOverrideCursor();
}
else else
{
show(); show();
}
} }


void QgsMessageViewer::setTitle( const QString& title ) 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 "qgsrectangle.h"
#include "qgscoordinatereferencesystem.h" #include "qgscoordinatereferencesystem.h"
#include "qgsnetworkaccessmanager.h" #include "qgsnetworkaccessmanager.h"
#include <qgsmessageoutput.h>


#include <QNetworkRequest> #include <QNetworkRequest>
#include <QNetworkReply> #include <QNetworkReply>
Expand Down Expand Up @@ -772,9 +773,28 @@ void QgsWmsProvider::tileReplyFinished()
if ( !status.isNull() && status.toInt() >= 400 ) if ( !status.isNull() && status.toInt() >= 400 )
{ {
QVariant phrase = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ); QVariant phrase = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
mErrorFormat = "text/plain";
mError = tr( "tile request err %1: %2" ).arg( status.toInt() ).arg( phrase.toString() ); showMessageBox( tr( "Tile request error" ), tr( "Status: %1\nReason phrase: %2" ).arg( status.toInt() ).arg( phrase.toString() ) );
emit statusChanged( mError );
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 ); tileReplies.removeOne( reply );
reply->deleteLater(); reply->deleteLater();
Expand Down Expand Up @@ -854,21 +874,40 @@ void QgsWmsProvider::cacheReplyFinished()
if ( !status.isNull() && status.toInt() >= 400 ) if ( !status.isNull() && status.toInt() >= 400 )
{ {
QVariant phrase = cacheReply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ); QVariant phrase = cacheReply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
mErrorFormat = "text/plain";
mError = tr( "map request error %1: %2" ).arg( status.toInt() ).arg( phrase.toString() ); showMessageBox( tr( "Map request error" ), tr( "Status: %1\nReason phrase: %2" ).arg( status.toInt() ).arg( phrase.toString() ) );
emit statusChanged( mError );


cacheReply->deleteLater(); cacheReply->deleteLater();
cacheReply = 0; cacheReply = 0;


return; return;
} }


QString contentType = cacheReply->header( QNetworkRequest::ContentTypeHeader ).toString();
QgsDebugMsg( "contentType: " + contentType );
if ( contentType.startsWith( "image/" ) )
{ {
QImage myLocalImage = QImage::fromData( cacheReply->readAll() ); QImage myLocalImage = QImage::fromData( cacheReply->readAll() );
QPainter p( cachedImage ); QPainter p( cachedImage );
p.drawImage( 0, 0, myLocalImage ); 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->deleteLater();
cacheReply = 0; cacheReply = 0;
Expand Down Expand Up @@ -1015,12 +1054,16 @@ int QgsWmsProvider::bandCount() const


void QgsWmsProvider::capabilitiesReplyProgress( qint64 bytesReceived, qint64 bytesTotal ) 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 ) 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 ) 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 ); QVariant redirect = mIdentifyReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
if ( !redirect.isNull() ) 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." ) ); emit statusChanged( tr( "identify request redirected." ) );


mIdentifyReply->deleteLater(); mIdentifyReply->deleteLater();
Expand All @@ -2829,7 +2872,7 @@ void QgsWmsProvider::identifyReplyFinished()
{ {
QVariant phrase = mIdentifyReply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ); QVariant phrase = mIdentifyReply->attribute( QNetworkRequest::HttpReasonPhraseAttribute );
mErrorFormat = "text/plain"; 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 ); emit statusChanged( mError );


mIdentifyResult = ""; 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 * Class factory to return a pointer to a newly created
* QgsWmsProvider object * 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(); void tileReplyFinished();


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

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

0 comments on commit 93404c4

Please sign in to comment.