[QGIS Commit] r10714 - in branches/Version-1_0/src: plugins/wfs providers/wfs

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon May 4 02:56:54 EDT 2009


Author: mhugent
Date: 2009-05-04 02:56:54 -0400 (Mon, 04 May 2009)
New Revision: 10714

Modified:
   branches/Version-1_0/src/plugins/wfs/qgswfssourceselect.cpp
   branches/Version-1_0/src/providers/wfs/qgswfsdata.cpp
   branches/Version-1_0/src/providers/wfs/qgswfsdata.h
Log:
backport wfs fix to 1.0

Modified: branches/Version-1_0/src/plugins/wfs/qgswfssourceselect.cpp
===================================================================
--- branches/Version-1_0/src/plugins/wfs/qgswfssourceselect.cpp	2009-05-04 03:25:26 UTC (rev 10713)
+++ branches/Version-1_0/src/plugins/wfs/qgswfssourceselect.cpp	2009-05-04 06:56:54 UTC (rev 10714)
@@ -166,10 +166,10 @@
     {
       tname = nameList.at( 0 ).toElement().text();
       //strip away namespace prefixes
-      if ( tname.contains( ":" ) )
+     /* if ( tname.contains( ":" ) )
       {
         tname = tname.section( ":", 1, 1 );
-      }
+      }*/
     }
     //Title
     QDomNodeList titleList = featureTypeElem.elementsByTagNameNS( WFS_NAMESPACE, "Title" );

Modified: branches/Version-1_0/src/providers/wfs/qgswfsdata.cpp
===================================================================
--- branches/Version-1_0/src/providers/wfs/qgswfsdata.cpp	2009-05-04 03:25:26 UTC (rev 10713)
+++ branches/Version-1_0/src/providers/wfs/qgswfsdata.cpp	2009-05-04 06:56:54 UTC (rev 10714)
@@ -15,10 +15,14 @@
 #include "qgswfsdata.h"
 #include "qgsrectangle.h"
 #include "qgscoordinatereferencesystem.h"
+#include "qgsgeometry.h"
+#include "qgshttptransaction.h"
+#include "qgslogger.h"
 #include <QBuffer>
 #include <QUrl>
 #include <QList>
 #include <QSet>
+#include <QWidget>
 
 //just for a test
 //#include <QProgressDialog>
@@ -76,6 +80,11 @@
   XML_SetElementHandler( p, QgsWFSData::start, QgsWFSData::end );
   XML_SetCharacterDataHandler( p, QgsWFSData::chars );
 
+  //start with empty extent
+  if(mExtent)
+  {
+      mExtent->set(0, 0, 0, 0);
+  }
 
   //separate host from query string
   QUrl requestUrl( mUri );
@@ -96,7 +105,7 @@
   //loop to read the data
   QByteArray readData;
   int atEnd = 0;
-  qWarning( "Entering loop" );
+
   while ( !mFinished || mHttp.bytesAvailable() > 0 )
   {
     if ( mFinished )
@@ -110,7 +119,16 @@
     }
     qApp->processEvents( QEventLoop::ExcludeUserInputEvents );
   }
-  qWarning( "Left loop" );
+
+  if(mExtent)
+  {
+    if(mExtent->isEmpty())
+      {
+        //reading of bbox from the server failed, so we calculate it less efficiently by evaluating the features
+        calculateExtentFromFeatures();
+      }
+  }
+
   return 0; //soon
 }
 
@@ -131,7 +149,7 @@
 void QgsWFSData::startElement( const XML_Char* el, const XML_Char** attr )
 {
   QString elementName( el );
-  QString localName = elementName.section( NS_SEPARATOR, 1, 1 );
+    QString localName = elementName.section( NS_SEPARATOR, 1, 1 );
   if ( elementName == GML_NAMESPACE + NS_SEPARATOR + "coordinates" )
   {
     mParseModeStack.push( QgsWFSData::coordinate );
@@ -752,3 +770,54 @@
   }
   return result;
 }
+
+QWidget* QgsWFSData::findMainWindow() const
+{
+  QWidget* mainWindow = 0;
+
+  QWidgetList topLevelWidgets = qApp->topLevelWidgets();
+  QWidgetList::iterator it = topLevelWidgets.begin();
+  for ( ; it != topLevelWidgets.end(); ++it )
+  {
+    if (( *it )->objectName() == "QgisApp" )
+    {
+      mainWindow = *it;
+      break;
+    }
+  }
+  return mainWindow;
+}
+
+void QgsWFSData::calculateExtentFromFeatures() const
+{
+    if(mFeatures.size() < 1)
+    {
+        return;
+    }
+
+    QgsRectangle bbox;
+
+    QgsFeature* currentFeature = 0;
+    QgsGeometry* currentGeometry = 0;
+    for(int i = 0; i < mFeatures.size(); ++i)
+    {
+        currentFeature = mFeatures[i];
+        if(!currentFeature)
+        {
+            continue;
+        }
+        currentGeometry = currentFeature->geometry();
+        if(currentGeometry)
+        {
+            if(bbox.isEmpty())
+            {
+                bbox = currentGeometry->boundingBox();
+            }
+            else
+            {
+                bbox.unionRect(currentGeometry->boundingBox());
+            }
+        }
+    }
+    (*mExtent) = bbox;
+}

Modified: branches/Version-1_0/src/providers/wfs/qgswfsdata.h
===================================================================
--- branches/Version-1_0/src/providers/wfs/qgswfsdata.h	2009-05-04 03:25:26 UTC (rev 10713)
+++ branches/Version-1_0/src/providers/wfs/qgswfsdata.h	2009-05-04 06:56:54 UTC (rev 10714)
@@ -126,6 +126,13 @@
     /**Adds all the integers contained in mCurrentWKBFragmentSizes*/
     int totalWKBFragmentSize() const;
 
+    /**Returns pointer to main window or 0 if it does not exist*/
+    QWidget* findMainWindow() const;
+    /**This function evaluates the layer bounding box from the features and sets it to mExtent.
+    Less efficient compared to reading the bbox from the provider, so it is only done if the wfs server \
+    does not provider extent information.*/
+    void calculateExtentFromFeatures() const;
+
     QString mUri;
     //results are members such that handler routines are able to manipulate them
     /**Bounding box of the layer*/



More information about the QGIS-commit mailing list