[QGIS Commit] r8258 - branches/rendercontext-branch/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Mar 21 06:59:42 EDT 2008


Author: mhugent
Date: 2008-03-21 06:59:42 -0400 (Fri, 21 Mar 2008)
New Revision: 8258

Modified:
   branches/rendercontext-branch/src/core/qgslabel.cpp
   branches/rendercontext-branch/src/core/qgslabel.h
   branches/rendercontext-branch/src/core/qgsmaplayer.cpp
   branches/rendercontext-branch/src/core/qgsmaplayer.h
   branches/rendercontext-branch/src/core/qgsmaprender.cpp
   branches/rendercontext-branch/src/core/qgsmaprender.h
   branches/rendercontext-branch/src/core/qgsrendercontext.cpp
   branches/rendercontext-branch/src/core/qgsvectorlayer.cpp
   branches/rendercontext-branch/src/core/qgsvectorlayer.h
Log:
Fixed problems with reprojecting

Modified: branches/rendercontext-branch/src/core/qgslabel.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgslabel.cpp	2008-03-21 00:45:50 UTC (rev 8257)
+++ branches/rendercontext-branch/src/core/qgslabel.cpp	2008-03-21 10:59:42 UTC (rev 8258)
@@ -83,9 +83,9 @@
     }
 }
 
-void QgsLabel::renderLabel( QPainter * painter, QgsRect &viewExtent,
-                            QgsCoordinateTransform* coordTransform,
-                            QgsMapToPixel *transform,
+void QgsLabel::renderLabel( QPainter * painter, const QgsRect& viewExtent,
+                            const QgsCoordinateTransform* coordTransform,
+                            const QgsMapToPixel *transform,
                             QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes,
        			    double sizeScale )
 {
@@ -336,8 +336,8 @@
 }
 
 void QgsLabel::renderLabel(QPainter* painter, QgsPoint point, 
-                           QgsCoordinateTransform* coordTransform,
-                           QgsMapToPixel* transform,
+                           const QgsCoordinateTransform* coordTransform,
+                           const QgsMapToPixel* transform,
                            QString text, QFont font, QPen pen,
                            int dx, int dy, 
                            double xoffset, double yoffset, 

Modified: branches/rendercontext-branch/src/core/qgslabel.h
===================================================================
--- branches/rendercontext-branch/src/core/qgslabel.h	2008-03-21 00:45:50 UTC (rev 8257)
+++ branches/rendercontext-branch/src/core/qgslabel.h	2008-03-21 10:59:42 UTC (rev 8258)
@@ -79,9 +79,9 @@
     /** \brief render label
      *  \param sizeScale global scale factor for size in pixels, labels in map units are not scaled
      */
-    void renderLabel ( QPainter* painter, QgsRect& viewExtent, 
-                       QgsCoordinateTransform* coordTransform,
-                       QgsMapToPixel *transform,
+    void renderLabel ( QPainter* painter, const QgsRect& viewExtent, 
+                       const QgsCoordinateTransform* coordTransform,
+                       const QgsMapToPixel *transform,
 		       QgsFeature &feature, bool selected, QgsLabelAttributes *classAttributes=0, double sizeScale = 1.);
 
     /** Reads the renderer configuration from an XML file
@@ -122,8 +122,8 @@
      * 
      */
     void renderLabel(QPainter* painter, QgsPoint point, 
-                     QgsCoordinateTransform* coordTransform,
-                     QgsMapToPixel* transform,
+                     const QgsCoordinateTransform* coordTransform,
+                     const QgsMapToPixel* transform,
                      QString text, QFont font, QPen pen,
                      int dx, int dy,
                      double xoffset, double yoffset,

Modified: branches/rendercontext-branch/src/core/qgsmaplayer.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaplayer.cpp	2008-03-21 00:45:50 UTC (rev 8257)
+++ branches/rendercontext-branch/src/core/qgsmaplayer.cpp	2008-03-21 10:59:42 UTC (rev 8258)
@@ -131,7 +131,7 @@
   return false;
 }
 
-void QgsMapLayer::drawLabels(QPainter* painter, const QgsRenderContext& renderContext)
+void QgsMapLayer::drawLabels(QgsRenderContext& renderContext)
 {
     //  std::cout << "In QgsMapLayer::draw" << std::endl;
 }

Modified: branches/rendercontext-branch/src/core/qgsmaplayer.h
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaplayer.h	2008-03-21 00:45:50 UTC (rev 8257)
+++ branches/rendercontext-branch/src/core/qgsmaplayer.h	2008-03-21 10:59:42 UTC (rev 8258)
@@ -76,7 +76,7 @@
     /** Draw labels
      * @TODO to be removed: used only in vector layers
      */
-    virtual void drawLabels(QPainter* painter, const QgsRenderContext& renderContext);
+    virtual void drawLabels(QgsRenderContext& renderContext);
 
     /** Return the extent of the layer as a QRect */
     const QgsRect extent();

Modified: branches/rendercontext-branch/src/core/qgsmaprender.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaprender.cpp	2008-03-21 00:45:50 UTC (rev 8257)
+++ branches/rendercontext-branch/src/core/qgsmaprender.cpp	2008-03-21 10:59:42 UTC (rev 8258)
@@ -62,13 +62,13 @@
 
 QgsRect QgsMapRender::extent()
 {
-  return mRenderContext.extent();
+  return mExtent;
 }
 
 void QgsMapRender::updateScale()
 {
   
-  mScale = mScaleCalculator->calculate(mRenderContext.extent(), mSize.width());
+  mScale = mScaleCalculator->calculate(mExtent, mSize.width());
 }
 
 bool QgsMapRender::setExtent(const QgsRect& extent)
@@ -103,7 +103,7 @@
       return false;
   }
 
-  mRenderContext.setExtent(extent);
+  mExtent = extent;
   if (!extent.isEmpty())
     adjustExtentToSize();
   return true;
@@ -132,7 +132,6 @@
   int myWidth = mSize.width();
 
   QgsMapToPixel newCoordXForm;
-  QgsRect theExtent = mRenderContext.extent();
   
   if (!myWidth || !myHeight)
   {
@@ -143,9 +142,9 @@
 
   // calculate the translation and scaling parameters
   // mupp = map units per pixel
-  double muppY = static_cast<double>(theExtent.height()) 
+  double muppY = static_cast<double>(mExtent.height()) 
                / static_cast<double>(myHeight);
-  double muppX = static_cast<double>(theExtent.width())  
+  double muppX = static_cast<double>(mExtent.width())  
                / static_cast<double>(myWidth);
   mMupp = muppY > muppX ? muppY : muppX;
 
@@ -154,39 +153,39 @@
 
   if (muppY > muppX)
   {
-    dymin = theExtent.yMin();
-    dymax = theExtent.yMax();
-    whitespace = ((myWidth * mMupp) - theExtent.width()) * 0.5;
-    dxmin = theExtent.xMin() - whitespace;
-    dxmax = theExtent.xMax() + whitespace;
+    dymin = mExtent.yMin();
+    dymax = mExtent.yMax();
+    whitespace = ((myWidth * mMupp) - mExtent.width()) * 0.5;
+    dxmin = mExtent.xMin() - whitespace;
+    dxmax = mExtent.xMax() + whitespace;
   }
   else
   {
-    dxmin = theExtent.xMin();
-    dxmax = theExtent.xMax();
-    whitespace = ((myHeight * mMupp) - theExtent.height()) * 0.5;
-    dymin = theExtent.yMin() - whitespace;
-    dymax = theExtent.yMax() + whitespace;
+    dxmin = mExtent.xMin();
+    dxmax = mExtent.xMax();
+    whitespace = ((myHeight * mMupp) - mExtent.height()) * 0.5;
+    dymin = mExtent.yMin() - whitespace;
+    dymax = mExtent.yMax() + whitespace;
   }
 
 #ifdef QGISDEBUG
   QgsDebugMsg("========== Current Scale ==========");
-  QgsDebugMsg("Current extent is " + theExtent.stringRep());
+  QgsDebugMsg("Current extent is " + mExtent.stringRep());
   QgsLogger::debug("MuppX", muppX, 1, __FILE__, __FUNCTION__, __LINE__);
   QgsLogger::debug("MuppY", muppY, 1, __FILE__, __FUNCTION__, __LINE__);
   QgsLogger::debug("Pixmap width", myWidth, 1, __FILE__, __FUNCTION__, __LINE__);
   QgsLogger::debug("Pixmap height", myHeight, 1, __FILE__, __FUNCTION__, __LINE__);
-  QgsLogger::debug("Extent width", theExtent.width(), 1, __FILE__, __FUNCTION__, __LINE__);
-  QgsLogger::debug("Extent height", theExtent.height(), 1, __FILE__, __FUNCTION__, __LINE__);
+  QgsLogger::debug("Extent width", mExtent.width(), 1, __FILE__, __FUNCTION__, __LINE__);
+  QgsLogger::debug("Extent height", mExtent.height(), 1, __FILE__, __FUNCTION__, __LINE__);
   QgsLogger::debug("whitespace: ", whitespace, 1, __FILE__, __FUNCTION__, __LINE__);
 #endif
 
 
   // update extent
-  theExtent.setXmin(dxmin);
-  theExtent.setXmax(dxmax);
-  theExtent.setYmin(dymin);
-  theExtent.setYmax(dymax);
+  mExtent.setXmin(dxmin);
+  mExtent.setXmax(dxmax);
+  mExtent.setYmin(dymin);
+  mExtent.setYmax(dymax);
 
   // update the scale
   updateScale();
@@ -197,7 +196,7 @@
 
   newCoordXForm.setParameters(mMupp, dxmin, dymin, myHeight);
   mRenderContext.setMapToPixel(newCoordXForm);
-  mRenderContext.setExtent(theExtent);
+  mRenderContext.setExtent(mExtent);
 }
 
 
@@ -205,7 +204,7 @@
 {
   QgsDebugMsg("========== Rendering ==========");
 
-  if (mRenderContext.extent().isEmpty())
+  if (mExtent.isEmpty())
   {
     QgsLogger::debug("empty extent... not rendering");
     return;
@@ -231,6 +230,8 @@
   // render all layers in the stack, starting at the base
   QListIterator<QString> li(mLayerSet);
   li.toBack();
+
+  QgsRect r1, r2;
   
   while (li.hasPrevious())
   {
@@ -266,17 +267,19 @@
     {
       connect(ml, SIGNAL(drawingProgress(int,int)), this, SLOT(onDrawingProgress(int,int)));        
       
-      QgsRect r1 = mRenderContext.extent();
-      QgsRect r2;
-      bool split = splitLayersExtent(ml, r1, r2);
       //
                   // Now do the call to the layer that actually does
                   // the rendering work!
       //
+
+      bool split = false;
       
       if (projectionsEnabled())
       {
+	r1 = mExtent;
+	split = splitLayersExtent(ml, r1, r2);
         ct = new QgsCoordinateTransform(ml->srs(), *mDestSRS);
+	mRenderContext.setExtent(r1);
       }
       else
       {
@@ -292,9 +295,11 @@
       
       if (split)
       {
-	//todo: set render context extent to r2
-        //if (!ml->draw(painter, r2, mCoordXForm, ct, !mOverview))
-	//emit drawError(ml);
+	mRenderContext.setExtent(r2);
+        if (!ml->draw(mRenderContext))
+	  {
+	    emit drawError(ml);
+	  }
       }
       
       delete ct;
@@ -329,23 +334,28 @@
         if ((ml->scaleBasedVisibility() && ml->minScale() < mScale  && ml->maxScale() > mScale)
             || (!ml->scaleBasedVisibility()))
         {
-          QgsRect r1 = mRenderContext.extent();
-	  QgsRect r2;
+          bool split = false;
 
-          bool split = splitLayersExtent(ml, r1, r2);
-      
           if (projectionsEnabled())
           {
+	    QgsRect r1 = mExtent;
+	    split = splitLayersExtent(ml, r1, r2);
             ct = new QgsCoordinateTransform(ml->srs(), *mDestSRS);
+	    mRenderContext.setExtent(r1);
           }
           else
           {
             ct = NULL;
           }
       
-          //ml->drawLabels(painter, r1, mCoordXForm, ct);
+	  mRenderContext.setCoordTransform(ct);
+          
+	  ml->drawLabels(mRenderContext);
           if (split)
-            //ml->drawLabels(painter, r2, mCoordXForm, ct);
+	    {
+	      mRenderContext.setExtent(r2);
+	      ml->drawLabels(mRenderContext);
+	    }
           
           delete ct;
         }

Modified: branches/rendercontext-branch/src/core/qgsmaprender.h
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaprender.h	2008-03-21 00:45:50 UTC (rev 8257)
+++ branches/rendercontext-branch/src/core/qgsmaprender.h	2008-03-21 10:59:42 UTC (rev 8258)
@@ -178,11 +178,8 @@
     //! scale calculator
     QgsScaleCalculator * mScaleCalculator;
     
-    //! utility class for transformation between map and pixmap units
-    //QgsMapToPixel* mCoordXForm; //in mRenderContext
-    
     //! current extent to be drawn
-    //QgsRect mExtent; //in mRenderContext
+    QgsRect mExtent;
     
     //! indicates whether it's map image for overview
     bool mOverview;

Modified: branches/rendercontext-branch/src/core/qgsrendercontext.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsrendercontext.cpp	2008-03-21 00:45:50 UTC (rev 8257)
+++ branches/rendercontext-branch/src/core/qgsrendercontext.cpp	2008-03-21 10:59:42 UTC (rev 8258)
@@ -30,7 +30,7 @@
 
 void QgsRenderContext::setCoordTransform(QgsCoordinateTransform* t) 
 {
-  delete mCoordTransform;
+  //delete mCoordTransform;
   mCoordTransform = t;
 }
 

Modified: branches/rendercontext-branch/src/core/qgsvectorlayer.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsvectorlayer.cpp	2008-03-21 00:45:50 UTC (rev 8257)
+++ branches/rendercontext-branch/src/core/qgsvectorlayer.cpp	2008-03-21 10:59:42 UTC (rev 8258)
@@ -277,17 +277,20 @@
 }
 
 //void QgsVectorLayer::drawLabels(QPainter * p, QgsRect & viewExtent, QgsMapToPixel * theMapToPixelTransform, QgsCoordinateTransform* ct)
-void QgsVectorLayer::drawLabels(QPainter* painter, const QgsRenderContext& renderContext)
+void QgsVectorLayer::drawLabels(QgsRenderContext& renderContext)
 {
-#if 0 //todo: adapt to render context
-  drawLabels(p, viewExtent, theMapToPixelTransform, ct, 1.);
-#endif //0
+  QPainter* thePainter = renderContext.painter();
+  if(!thePainter)
+    {
+      return;
+    }
+  drawLabels(thePainter, renderContext.extent(), &(renderContext.mapToPixel()), renderContext.coordTransform(), renderContext.scaleFactor());
 }
 
 // NOTE this is a temporary method added by Tim to prevent label clipping
 // which was occurring when labeller was called in the main draw loop
 // This method will probably be removed again in the near future!
-void QgsVectorLayer::drawLabels(QPainter * p, QgsRect & viewExtent, QgsMapToPixel * theMapToPixelTransform, QgsCoordinateTransform* ct, double scale)
+void QgsVectorLayer::drawLabels(QPainter * p, const QgsRect& viewExtent, const QgsMapToPixel* theMapToPixelTransform, const QgsCoordinateTransform* ct, double scale)
 {
   QgsDebugMsg("Starting draw of labels");
 

Modified: branches/rendercontext-branch/src/core/qgsvectorlayer.h
===================================================================
--- branches/rendercontext-branch/src/core/qgsvectorlayer.h	2008-03-21 00:45:50 UTC (rev 8257)
+++ branches/rendercontext-branch/src/core/qgsvectorlayer.h	2008-03-21 10:59:42 UTC (rev 8258)
@@ -340,7 +340,7 @@
   bool draw(QgsRenderContext& renderContext);
 
   /** Draws the layer labels using coordinate transformation */
-  void drawLabels(QPainter* painter, const QgsRenderContext& renderContext);
+  void drawLabels(QgsRenderContext& renderContext);
 
   /** \brief Draws the layer using coordinate transformation
    *  \param widthScale line width scale
@@ -357,7 +357,7 @@
   /** \brief Draws the layer labels using coordinate transformation
    *  \param scale size scale, applied to all values in pixels
    */
-  void drawLabels(QPainter * p, QgsRect & viewExtent, QgsMapToPixel * cXf, QgsCoordinateTransform* ct, double scale);
+  void drawLabels(QPainter * p, const QgsRect& viewExtent, const QgsMapToPixel* cXf, const QgsCoordinateTransform* ct, double scale);
 
   /** returns array of added features */
   QgsFeatureList& addedFeatures();



More information about the QGIS-commit mailing list