[QGIS Commit] r9116 - in branches/advanced_printing_branch/src: app/composer core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Aug 22 03:01:00 EDT 2008


Author: mhugent
Date: 2008-08-22 03:00:58 -0400 (Fri, 22 Aug 2008)
New Revision: 9116

Modified:
   branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
   branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
   branches/advanced_printing_branch/src/app/composer/qgscomposition.h
   branches/advanced_printing_branch/src/core/qgsmaprenderer.cpp
   branches/advanced_printing_branch/src/core/qgsmaprenderer.h
Log:
Replaced QgsMapCanvas with QgsMapRenderer in composer map. The renderer object has all the information that composer map needs and is from core, while QgsMapCanvas is from gui

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp	2008-08-22 05:56:11 UTC (rev 9115)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposer.cpp	2008-08-22 07:00:58 UTC (rev 9116)
@@ -33,6 +33,7 @@
 #include "qgscomposerscalebarwidget.h"
 #include "qgsexception.h"
 #include "qgsproject.h"
+#include "qgsmapcanvas.h"
 #include "qgsmessageviewer.h"
 #include "qgscontexthelp.h"
 #include "qgscursors.h"
@@ -115,7 +116,7 @@
   mView = new QgsComposerView (mViewFrame);
   connectSlots();
 
-  mComposition  = new QgsComposition(mQgis->getMapCanvas());
+  mComposition  = new QgsComposition(mQgis->getMapCanvas()->mapRenderer());
   mView->setComposition(mComposition);
 
   QgsCompositionWidget* compositionWidget = new QgsCompositionWidget(mCompositionOptionsFrame, mComposition);
@@ -1215,7 +1216,7 @@
   mView = new QgsComposerView(mViewFrame);
   connectSlots();
 
-  mComposition = new QgsComposition(mQgis->getMapCanvas());
+  mComposition = new QgsComposition(mQgis->getMapCanvas()->mapRenderer());
   mComposition->readXML(compositionElem, doc);
   
   QGridLayout *l = new QGridLayout(mViewFrame );

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp	2008-08-22 05:56:11 UTC (rev 9115)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.cpp	2008-08-22 07:00:58 UTC (rev 9116)
@@ -19,7 +19,7 @@
 
 #include "qgscoordinatetransform.h"
 #include "qgslogger.h"
-#include "qgsmapcanvas.h"
+#include "qgsmaprenderer.h"
 #include "qgsmaplayer.h"
 #include "qgsmaptopixel.h"
 #include "qgsproject.h"
@@ -32,6 +32,7 @@
 #include "qgslabelattributes.h"
 
 #include <QGraphicsScene>
+#include <QGraphicsView>
 #include <QPainter>
 #include <iostream>
 #include <cmath>
@@ -42,7 +43,7 @@
   : QgsComposerItem(x, y, width, height, composition)
 {
     mComposition = composition;
-    mMapCanvas = mComposition->mapCanvas();
+    mMapRenderer = mComposition->mapRenderer();
     mId = mCurrentComposerId++;
     
     // Cache
@@ -54,12 +55,15 @@
     mYOffset = 0.0;
 
     //calculate mExtent based on width/height ratio and map canvas extent
-    mExtent = mMapCanvas->extent();
+    if(mMapRenderer)
+      {
+	mExtent = mMapRenderer->extent();
+      }
     setSceneRect(QRectF(x, y, width, height));
 
     QGraphicsRectItem::setZValue(20);
 
-    connect ( mMapCanvas, SIGNAL(layersChanged()), this, SLOT(mapCanvasChanged()) );
+    
 
     setToolTip(tr("Map") + " " + QString::number(mId));
 
@@ -74,7 +78,7 @@
   mYOffset = 0.0;
   
   mComposition = composition;
-  mMapCanvas = mComposition->mapCanvas();
+  mMapRenderer = mComposition->mapRenderer();
   mId = mCurrentComposerId++;
   setToolTip(tr("Map") + " " + QString::number(mId));
   QGraphicsRectItem::show();
@@ -88,15 +92,12 @@
 from QGraphicsItem. */
 void QgsComposerMap::draw ( QPainter *painter, const QgsRect& extent, const QSize& size, int dpi)
 {
-  mMapCanvas->freeze(true);  // necessary ?
-
   if(!painter)
     {
       return;
     }
 
-  QgsMapRenderer* canvasMapRender = mMapCanvas->mapRenderer();
-  if(!canvasMapRender)
+  if(!mMapRenderer)
     {
       return;
     }
@@ -104,9 +105,9 @@
   QgsMapRenderer theMapRender;
   theMapRender.setExtent(extent);
   theMapRender.setOutputSize(size, dpi);
-  theMapRender.setLayerSet(canvasMapRender->layerSet());
-  theMapRender.setProjectionsEnabled(canvasMapRender->projectionsEnabled());
-  theMapRender.setDestinationSrs(canvasMapRender->destinationSrs());
+  theMapRender.setLayerSet(mMapRenderer->layerSet());
+  theMapRender.setProjectionsEnabled(mMapRenderer->projectionsEnabled());
+  theMapRender.setDestinationSrs(mMapRenderer->destinationSrs());
   
   QgsRenderContext* theRenderContext = theMapRender.rendererContext();
   if(theRenderContext)
@@ -120,8 +121,6 @@
   theMapRender.setScale(scale());
   theMapRender.render(painter);  
   theMapRender.setScale(bk_scale);
-    
-  mMapCanvas->freeze(false);
 }
 
 void QgsComposerMap::cache ( void )
@@ -238,7 +237,7 @@
 double QgsComposerMap::scale() const
 {
   QgsScaleCalculator calculator;
-  calculator.setMapUnits(mMapCanvas->mapUnits());
+  calculator.setMapUnits(mMapRenderer->mapUnits());
   calculator.setDpi(25.4);  //QGraphicsView units are mm
   return calculator.calculate(mExtent, rect().width());
 }
@@ -340,6 +339,10 @@
 	{
 	  result = viewList.at(0)->transform().m11();
 	}
+      else
+	{
+	  return 1; //probably called from non-gui code
+	}
     }
   return result;
 }

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermap.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermap.h	2008-08-22 05:56:11 UTC (rev 9115)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermap.h	2008-08-22 07:00:58 UTC (rev 9116)
@@ -25,7 +25,7 @@
 #include <QPixmap>
 
 class QgsComposition;
-class QgsMapCanvas;
+class QgsMapRenderer;
 class QgsMapToPixel;
 class QDomNode;
 class QDomDocument;
@@ -106,7 +106,7 @@
 
     QgsRect extent() const {return mExtent;}
 
-    const QgsMapCanvas* mapCanvas() const {return mMapCanvas;}
+    const QgsMapRenderer* mapRenderer() const {return mMapRenderer;}
 
     /**Sets offset values to shift image (useful for live updates when moving item content)*/
     void setOffset(double xOffset, double yOffset);
@@ -133,8 +133,8 @@
 
 private:
 
-    // Pointer to map canvas
-    QgsMapCanvas *mMapCanvas;
+    // Pointer to map renderer of main map
+    QgsMapRenderer *mMapRenderer;
     
     /**Unique identifier*/
     int mId;

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp	2008-08-22 05:56:11 UTC (rev 9115)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposermapwidget.cpp	2008-08-22 07:00:58 UTC (rev 9116)
@@ -18,7 +18,7 @@
 #include "qgscomposermapwidget.h"
 #include "qgscomposeritemwidget.h"
 #include "qgscomposermap.h"
-#include "qgsmapcanvas.h"
+#include "qgsmaprenderer.h"
 
 QgsComposerMapWidget::QgsComposerMapWidget(QgsComposerMap* composerMap): QWidget(), mComposerMap(composerMap)
 {
@@ -141,10 +141,10 @@
 {
   if(mComposerMap)
     {
-      const QgsMapCanvas* canvas = mComposerMap->mapCanvas();
-      if(canvas)
+      const QgsMapRenderer* renderer = mComposerMap->mapRenderer();
+      if(renderer)
 	{
-	  QgsRect canvasExtent = canvas->extent();
+	  QgsRect canvasExtent = renderer->extent();
 	  
 	  //fill text into line edits
 	  mXMinLineEdit->setText(QString::number(canvasExtent.xMin()));

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp	2008-08-22 05:56:11 UTC (rev 9115)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposition.cpp	2008-08-22 07:00:58 UTC (rev 9116)
@@ -21,7 +21,7 @@
 #include <QDomElement>
 #include <QGraphicsRectItem>
 
-QgsComposition::QgsComposition(QgsMapCanvas* mapCanvas): QGraphicsScene(0), mMapCanvas(mapCanvas), mPlotStyle(QgsComposition::Preview), mPaperItem(0)
+QgsComposition::QgsComposition(QgsMapRenderer* mapRenderer): QGraphicsScene(0), mMapRenderer(mapRenderer), mPlotStyle(QgsComposition::Preview), mPaperItem(0)
 {
   setBackgroundBrush(Qt::gray);
 
@@ -33,7 +33,7 @@
   mPrintoutResolution = 300; //hardcoded default
 }
 
-QgsComposition::QgsComposition(): QGraphicsScene(0), mMapCanvas(0), mPlotStyle(QgsComposition::Preview), mPaperItem(0)
+QgsComposition::QgsComposition(): QGraphicsScene(0), mMapRenderer(0), mPlotStyle(QgsComposition::Preview), mPaperItem(0)
 {
 
 }

Modified: branches/advanced_printing_branch/src/app/composer/qgscomposition.h
===================================================================
--- branches/advanced_printing_branch/src/app/composer/qgscomposition.h	2008-08-22 05:56:11 UTC (rev 9115)
+++ branches/advanced_printing_branch/src/app/composer/qgscomposition.h	2008-08-22 07:00:58 UTC (rev 9116)
@@ -21,7 +21,7 @@
 class QgsComposerItem;
 class QgsComposerMap;
 class QGraphicsRectItem;
-class QgsMapCanvas;
+class QgsMapRenderer;
 
 class QDomDocument;
 class QDomElement;
@@ -42,7 +42,7 @@
       Postscript   // Fonts need different scaling!
     };
 
-  QgsComposition(QgsMapCanvas* mapCanvas);
+  QgsComposition(QgsMapRenderer* mapRenderer);
   ~QgsComposition();
 
   /**Changes size of paper item*/
@@ -70,7 +70,7 @@
   void setPrintoutResolution(int dpi){mPrintoutResolution = dpi;}
 
   /**Returns pointer to qgis map canvas*/
-  QgsMapCanvas* mapCanvas(){return mMapCanvas;}
+  QgsMapRenderer* mapRenderer(){return mMapRenderer;}
 
   QgsComposition::PlotStyle plotStyle() const {return mPlotStyle;}
   void setPlotStyle(QgsComposition::PlotStyle style) {mPlotStyle = style;}
@@ -90,7 +90,8 @@
   bool readXML(const QDomElement& compositionElem, const QDomDocument& doc);
 
  private:
-  QgsMapCanvas* mMapCanvas;
+  /**Pointere to map renderer of QGIS main map*/
+  QgsMapRenderer* mMapRenderer;
   QgsComposition::PlotStyle mPlotStyle;
   QGraphicsRectItem* mPaperItem;
 

Modified: branches/advanced_printing_branch/src/core/qgsmaprenderer.cpp
===================================================================
--- branches/advanced_printing_branch/src/core/qgsmaprenderer.cpp	2008-08-22 05:56:11 UTC (rev 9115)
+++ branches/advanced_printing_branch/src/core/qgsmaprenderer.cpp	2008-08-22 07:00:58 UTC (rev 9116)
@@ -59,7 +59,7 @@
 }
 
 
-QgsRect QgsMapRenderer::extent()
+QgsRect QgsMapRenderer::extent() const
 {
   return mExtent;
 }

Modified: branches/advanced_printing_branch/src/core/qgsmaprenderer.h
===================================================================
--- branches/advanced_printing_branch/src/core/qgsmaprenderer.h	2008-08-22 05:56:11 UTC (rev 9115)
+++ branches/advanced_printing_branch/src/core/qgsmaprenderer.h	2008-08-22 07:00:58 UTC (rev 9116)
@@ -59,7 +59,7 @@
     bool setExtent(const QgsRect& extent);
     
     //! returns current extent
-    QgsRect extent();
+    QgsRect extent() const;
     
     const QgsMapToPixel* coordinateTransform() { return &(mRenderContext.mapToPixel()); }
     



More information about the QGIS-commit mailing list