[QGIS Commit] r15763 - in trunk/qgis/src: app core/raster gui providers/wms

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Apr 18 18:34:36 EDT 2011


Author: jef
Date: 2011-04-18 15:34:36 -0700 (Mon, 18 Apr 2011)
New Revision: 15763

Modified:
   trunk/qgis/src/app/qgisapp.cpp
   trunk/qgis/src/core/raster/qgsrasterlayer.cpp
   trunk/qgis/src/gui/qgsmessageviewer.cpp
   trunk/qgis/src/providers/wms/qgswmsprovider.cpp
   trunk/qgis/src/providers/wms/qgswmsprovider.h
Log:
improve wms error and progress reporting (fixes #1576)

Modified: trunk/qgis/src/app/qgisapp.cpp
===================================================================
--- trunk/qgis/src/app/qgisapp.cpp	2011-04-18 20:54:50 UTC (rev 15762)
+++ trunk/qgis/src/app/qgisapp.cpp	2011-04-18 22:34:36 UTC (rev 15763)
@@ -5522,7 +5522,15 @@
 
   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 )
   {
@@ -6196,14 +6204,6 @@
   // 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;
 }
 

Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2011-04-18 20:54:50 UTC (rev 15762)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp	2011-04-18 22:34:36 UTC (rev 15763)
@@ -155,13 +155,6 @@
 
   // 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" ) );
@@ -2199,7 +2192,7 @@
 
   if ( !loaded )
   {
-    QgsLogger::warning( "QgsRasterLayer::setDataProvider: Failed to load " );
+    QgsLogger::warning( "QgsRasterLayer::loadProviderLibrary: Failed to load " );
     return NULL;
   }
   QgsDebugMsg( "Loaded data provider library" );
@@ -2223,7 +2216,7 @@
 
   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" );
@@ -2237,7 +2230,7 @@
 
   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" );
@@ -2506,6 +2499,12 @@
     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;
 
@@ -2895,6 +2894,7 @@
   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

Modified: trunk/qgis/src/gui/qgsmessageviewer.cpp
===================================================================
--- trunk/qgis/src/gui/qgsmessageviewer.cpp	2011-04-18 20:54:50 UTC (rev 15762)
+++ trunk/qgis/src/gui/qgsmessageviewer.cpp	2011-04-18 22:34:36 UTC (rev 15763)
@@ -63,9 +63,15 @@
 void QgsMessageViewer::showMessage( bool blocking )
 {
   if ( blocking )
+  {
+    QApplication::setOverrideCursor( Qt::ArrowCursor );
     exec();
+    QApplication::restoreOverrideCursor();
+  }
   else
+  {
     show();
+  }
 }
 
 void QgsMessageViewer::setTitle( const QString& title )

Modified: trunk/qgis/src/providers/wms/qgswmsprovider.cpp
===================================================================
--- trunk/qgis/src/providers/wms/qgswmsprovider.cpp	2011-04-18 20:54:50 UTC (rev 15762)
+++ trunk/qgis/src/providers/wms/qgswmsprovider.cpp	2011-04-18 22:34:36 UTC (rev 15763)
@@ -32,6 +32,7 @@
 #include "qgsrectangle.h"
 #include "qgscoordinatereferencesystem.h"
 #include "qgsnetworkaccessmanager.h"
+#include <qgsmessageoutput.h>
 
 #include <QNetworkRequest>
 #include <QNetworkReply>
@@ -772,16 +773,35 @@
     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();
+
+      return;
+    }
+
     // only take results from current request number
     if ( mTileReqNo == tileReqNo )
     {
@@ -854,22 +874,41 @@
     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;
 
@@ -1015,12 +1054,16 @@
 
 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 )
@@ -2812,7 +2855,7 @@
     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();
@@ -2829,7 +2872,7 @@
     {
       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 = "";
@@ -2895,6 +2938,14 @@
   }
 }
 
+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

Modified: trunk/qgis/src/providers/wms/qgswmsprovider.h
===================================================================
--- trunk/qgis/src/providers/wms/qgswmsprovider.h	2011-04-18 20:54:50 UTC (rev 15762)
+++ trunk/qgis/src/providers/wms/qgswmsprovider.h	2011-04-18 22:34:36 UTC (rev 15763)
@@ -650,6 +650,8 @@
     void tileReplyFinished();
 
   private:
+    void showMessageBox( const QString& title, const QString& text );
+
     /**
      * \brief Retrieve and parse the (cached) Capabilities document from the server
      *



More information about the QGIS-commit mailing list