[QGIS Commit] r8320 - in branches/rendercontext-branch/src:
app/composer core core/raster
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Sun Apr 6 06:49:26 EDT 2008
Author: mhugent
Date: 2008-04-06 06:49:26 -0400 (Sun, 06 Apr 2008)
New Revision: 8320
Modified:
branches/rendercontext-branch/src/app/composer/qgscomposer.cpp
branches/rendercontext-branch/src/app/composer/qgscomposermap.h
branches/rendercontext-branch/src/core/qgsmaprender.cpp
branches/rendercontext-branch/src/core/raster/qgsrasterlayer.cpp
Log:
Set vector scale factor such that widths are always mm. Scale raster layers to have the correct resolution in print output. Point symbol resolution is not handled yet
Modified: branches/rendercontext-branch/src/app/composer/qgscomposer.cpp
===================================================================
--- branches/rendercontext-branch/src/app/composer/qgscomposer.cpp 2008-04-04 19:16:34 UTC (rev 8319)
+++ branches/rendercontext-branch/src/app/composer/qgscomposer.cpp 2008-04-06 10:49:26 UTC (rev 8320)
@@ -332,6 +332,7 @@
//set the resolution and paper orientation each time we call up the dialog, not just the first time we run it
mPrinter->setResolution(mComposition->resolution());
+
if (mComposition->paperOrientation() == QgsComposition::Portrait)
{
mPrinter->setOrientation(QPrinter::Portrait);
Modified: branches/rendercontext-branch/src/app/composer/qgscomposermap.h
===================================================================
--- branches/rendercontext-branch/src/app/composer/qgscomposermap.h 2008-04-04 19:16:34 UTC (rev 8319)
+++ branches/rendercontext-branch/src/app/composer/qgscomposermap.h 2008-04-06 10:49:26 UTC (rev 8320)
@@ -71,7 +71,10 @@
bool writeXML( QDomNode & node, QDomDocument & document, bool temp = false );
bool readXML( QDomNode & node );
- /** \brief Draw to paint device */
+ /** \brief Draw to paint device
+ @param extent map extent
+ @param size size in scene coordinates
+ @param dpi scene dpi*/
void draw(QPainter *painter, const QgsRect& extent, const QSize& size, int dpi);
/** \brief Reimplementation of QCanvasItem::paint - draw on canvas */
Modified: branches/rendercontext-branch/src/core/qgsmaprender.cpp
===================================================================
--- branches/rendercontext-branch/src/core/qgsmaprender.cpp 2008-04-04 19:16:34 UTC (rev 8319)
+++ branches/rendercontext-branch/src/core/qgsmaprender.cpp 2008-04-06 10:49:26 UTC (rev 8320)
@@ -212,6 +212,12 @@
if (mDrawing)
return;
+
+ QPaintDevice* thePaintDevice = painter->device();
+ if(!thePaintDevice)
+ {
+ return;
+ }
mDrawing = true;
@@ -233,8 +239,9 @@
//calculate scale factor
//use the specified dpi and not those from the paint device
//because sometimes QPainter units are in a local coord sys (e.g. in case of QGraphicsScene)
- double meanDpi = mScaleCalculator->dpi();
- double scaleFactor = meanDpi/25.4;
+ double sceneDpi = mScaleCalculator->dpi();
+ double scaleFactor = sceneDpi/25.4; //units should always be mm
+ double rasterScaleFactor = (thePaintDevice->logicalDpiX() + thePaintDevice->logicalDpiY()) / 2.0 /sceneDpi;
mRenderContext.setScaleFactor(scaleFactor);
// render all layers in the stack, starting at the base
@@ -303,6 +310,29 @@
mRenderContext.setCoordTransform(ct);
+ //decide if we have to scale the raster
+ //this is necessary in case QGraphicsScene is used
+ bool scaleRaster = false;
+ QgsMapToPixel rasterMapToPixel;
+ QgsMapToPixel bk_mapToPixel;
+ double debug = fabs(rasterScaleFactor - 1.0);
+ if(ml->type() == QgsMapLayer::RASTER && fabs(rasterScaleFactor - 1.0) > 0.000001)
+ {
+ scaleRaster = true;
+ }
+
+
+ if(scaleRaster)
+ {
+ bk_mapToPixel = mRenderContext.mapToPixel();
+ rasterMapToPixel = mRenderContext.mapToPixel();
+ rasterMapToPixel.setMapUnitsPerPixel(mRenderContext.mapToPixel().mapUnitsPerPixel() / rasterScaleFactor);
+ rasterMapToPixel.setYmax(mSize.height() * rasterScaleFactor);
+ mRenderContext.setMapToPixel(rasterMapToPixel);
+ mRenderContext.painter()->save();
+ mRenderContext.painter()->scale(1.0/rasterScaleFactor, 1.0/rasterScaleFactor);
+ }
+
if (!ml->draw(mRenderContext))
{
emit drawError(ml);
@@ -316,6 +346,12 @@
emit drawError(ml);
}
}
+
+ if(scaleRaster)
+ {
+ mRenderContext.setMapToPixel(bk_mapToPixel);
+ mRenderContext.painter()->restore();
+ }
disconnect(ml, SIGNAL(drawingProgress(int,int)), this, SLOT(onDrawingProgress(int,int)));
}
Modified: branches/rendercontext-branch/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- branches/rendercontext-branch/src/core/raster/qgsrasterlayer.cpp 2008-04-04 19:16:34 UTC (rev 8319)
+++ branches/rendercontext-branch/src/core/raster/qgsrasterlayer.cpp 2008-04-06 10:49:26 UTC (rev 8320)
@@ -1265,24 +1265,25 @@
else
{
if ((myRasterViewPort->drawableAreaXDim) > 4000 && (myRasterViewPort->drawableAreaYDim > 4000))
- {
- // We have scaled one raster pixel to more than 4000 screen pixels. What's the point of showing this layer?
- // Instead, we just stop displaying the layer. Prevents allocating the entire world of memory for showing
- // very few pixels.
- // (Alternatively, we have a very big screen > 2000 x 2000)
- QgsDebugMsg("Too zoomed in! Displaying raster requires too much memory. Raster will not display");
- } else {
- // Otherwise use the old-fashioned GDAL direct-drawing style
- // TODO: Move into its own GDAL provider.
-
- // \/\/\/ - commented-out to handle zoomed-in rasters
- // draw(theQPainter,myRasterViewPort);
- // /\/\/\ - commented-out to handle zoomed-in rasters
- // \/\/\/ - added to handle zoomed-in rasters
- draw(theQPainter, myRasterViewPort, &theQgsMapToPixel);
- // /\/\/\ - added to handle zoomed-in rasters
- }
-
+ {
+ // We have scaled one raster pixel to more than 4000 screen pixels. What's the point of showing this layer?
+ // Instead, we just stop displaying the layer. Prevents allocating the entire world of memory for showing
+ // very few pixels.
+ // (Alternatively, we have a very big screen > 2000 x 2000)
+ QgsDebugMsg("Too zoomed in! Displaying raster requires too much memory. Raster will not display");
+ }
+ else
+ {
+ // Otherwise use the old-fashioned GDAL direct-drawing style
+ // TODO: Move into its own GDAL provider.
+
+ // \/\/\/ - commented-out to handle zoomed-in rasters
+ // draw(theQPainter,myRasterViewPort);
+ // /\/\/\ - commented-out to handle zoomed-in rasters
+ // \/\/\/ - added to handle zoomed-in rasters
+ draw(theQPainter, myRasterViewPort, &theQgsMapToPixel);
+ // /\/\/\ - added to handle zoomed-in rasters
+ }
}
delete myRasterViewPort;
More information about the QGIS-commit
mailing list