QGIS API Documentation  2.11.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
qgsmaprenderer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmaprender.cpp - class for rendering map layer set
3  ----------------------
4  begin : January 2006
5  copyright : (C) 2006 by Martin Dobias
6  email : wonder.sk at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include <cmath>
17 #include <cfloat>
18 
19 #include "qgscoordinatetransform.h"
20 #include "qgscrscache.h"
21 #include "qgslogger.h"
22 #include "qgsmessagelog.h"
23 #include "qgsmaprenderer.h"
24 #include "qgsscalecalculator.h"
25 #include "qgsmaptopixel.h"
26 #include "qgsmaplayer.h"
27 #include "qgsmaplayerregistry.h"
28 #include "qgsmapsettings.h"
29 #include "qgsdistancearea.h"
30 #include "qgsproject.h"
31 #include "qgsvectorlayer.h"
32 
33 #include <QDomDocument>
34 #include <QDomNode>
35 #include <QMutexLocker>
36 #include <QPainter>
37 #include <QListIterator>
38 #include <QSettings>
39 #include <QTime>
40 #include <QCoreApplication>
41 
43 {
44  mScale = 1.0;
45  mRotation = 0.0;
48 
49  mDrawing = false;
50  mOverview = false;
51 
52  // set default map units - we use WGS 84 thus use degrees
54 
55  mSize = QSize( 0, 0 );
56 
57  mProjectionsEnabled = false;
59 
61 
62  mLabelingEngine = NULL;
63 }
64 
66 {
67  delete mScaleCalculator;
68  delete mDistArea;
69  delete mDestCRS;
70  delete mLabelingEngine;
71 }
72 
74 {
75  return mExtent;
76 }
77 
79 {
81 }
82 
84 {
85  //remember the previous extent
87 
88  // Don't allow zooms where the current extent is so small that it
89  // can't be accurately represented using a double (which is what
90  // currentExtent uses). Excluding 0 avoids a divide by zero and an
91  // infinite loop when rendering to a new canvas. Excluding extents
92  // greater than 1 avoids doing unnecessary calculations.
93 
94  // The scheme is to compare the width against the mean x coordinate
95  // (and height against mean y coordinate) and only allow zooms where
96  // the ratio indicates that there is more than about 12 significant
97  // figures (there are about 16 significant figures in a double).
98 
99  if ( extent.width() > 0 &&
100  extent.height() > 0 &&
101  extent.width() < 1 &&
102  extent.height() < 1 )
103  {
104  // Use abs() on the extent to avoid the case where the extent is
105  // symmetrical about 0.
106  double xMean = ( qAbs( extent.xMinimum() ) + qAbs( extent.xMaximum() ) ) * 0.5;
107  double yMean = ( qAbs( extent.yMinimum() ) + qAbs( extent.yMaximum() ) ) * 0.5;
108 
109  double xRange = extent.width() / xMean;
110  double yRange = extent.height() / yMean;
111 
112  static const double minProportion = 1e-12;
113  if ( xRange < minProportion || yRange < minProportion )
114  return false;
115  }
116 
117  mExtent = extent;
118  if ( !extent.isEmpty() )
120 
121  emit extentsChanged();
122  return true;
123 }
124 
125 void QgsMapRenderer::setRotation( double rotation )
126 {
128  // TODO: adjust something ?
129 
130  emit rotationChanged( rotation );
131 }
132 
134 {
135  return mRotation;
136 }
137 
138 
140 {
141  mSize = QSizeF( size.width(), size.height() );
142  mScaleCalculator->setDpi( dpi );
144 }
145 
146 void QgsMapRenderer::setOutputSize( QSizeF size, double dpi )
147 {
148  mSize = size;
149  mScaleCalculator->setDpi( dpi );
151 }
152 
154 {
155  return mScaleCalculator->dpi();
156 }
157 
159 {
160  return mSize.toSize();
161 }
162 
164 {
165  return mSize;
166 }
167 
169 {
170  double myHeight = mSize.height();
171  double myWidth = mSize.width();
172 
173  QgsMapToPixel newCoordXForm;
174 
175  if ( !myWidth || !myHeight )
176  {
177  mScale = 1.0;
178  newCoordXForm.setParameters( 1, 0, 0, 0, 0, 0 );
179  return;
180  }
181 
182  // calculate the translation and scaling parameters
183  // mapUnitsPerPixel = map units per pixel
184  double mapUnitsPerPixelY = mExtent.height() / myHeight;
185  double mapUnitsPerPixelX = mExtent.width() / myWidth;
186  mMapUnitsPerPixel = mapUnitsPerPixelY > mapUnitsPerPixelX ? mapUnitsPerPixelY : mapUnitsPerPixelX;
187 
188  // calculate the actual extent of the mapCanvas
189  double dxmin, dxmax, dymin, dymax, whitespace;
190 
191  if ( mapUnitsPerPixelY > mapUnitsPerPixelX )
192  {
193  dymin = mExtent.yMinimum();
194  dymax = mExtent.yMaximum();
195  whitespace = (( myWidth * mMapUnitsPerPixel ) - mExtent.width() ) * 0.5;
196  dxmin = mExtent.xMinimum() - whitespace;
197  dxmax = mExtent.xMaximum() + whitespace;
198  }
199  else
200  {
201  dxmin = mExtent.xMinimum();
202  dxmax = mExtent.xMaximum();
203  whitespace = (( myHeight * mMapUnitsPerPixel ) - mExtent.height() ) * 0.5;
204  dymin = mExtent.yMinimum() - whitespace;
205  dymax = mExtent.yMaximum() + whitespace;
206  }
207 
208  QgsDebugMsg( QString( "Map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mapUnitsPerPixelX ) ).arg( qgsDoubleToString( mapUnitsPerPixelY ) ) );
209  QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( myWidth ) ).arg( qgsDoubleToString( myHeight ) ) );
210  QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ) ).arg( qgsDoubleToString( mExtent.height() ) ) );
212 
213  // update extent
214  mExtent.setXMinimum( dxmin );
215  mExtent.setXMaximum( dxmax );
216  mExtent.setYMinimum( dymin );
217  mExtent.setYMaximum( dymax );
218 
219  QgsDebugMsg( QString( "Adjusted map units per pixel (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() / myWidth ) ).arg( qgsDoubleToString( mExtent.height() / myHeight ) ) );
220 
221  QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() / mMapUnitsPerPixel ) ).arg( qgsDoubleToString( mExtent.height() / mMapUnitsPerPixel ) ) );
222 
223  // update the scale
224  updateScale();
225 
226  QgsDebugMsg( QString( "Scale (assuming meters as map units) = 1:%1" ).arg( qgsDoubleToString( mScale ) ) );
227 
229  newCoordXForm.setParameters( mMapUnitsPerPixel, dxmin, dymin, myHeight );
231  mRenderContext.setMapToPixel( newCoordXForm );
233 }
234 
235 
236 void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
237 {
238  //Lock render method for concurrent threads (e.g. from globe)
239  QMutexLocker renderLock( &mRenderMutex );
240 
241  QgsDebugMsg( "========== Rendering ==========" );
242 
243  if ( mExtent.isEmpty() )
244  {
245  QgsDebugMsg( "empty extent... not rendering" );
246  return;
247  }
248 
249  if ( mSize.width() == 1 && mSize.height() == 1 )
250  {
251  QgsDebugMsg( "size 1x1... not rendering" );
252  return;
253  }
254 
255  QPaintDevice* thePaintDevice = painter->device();
256  if ( !thePaintDevice )
257  {
258  return;
259  }
260 
261  // wait
262  if ( mDrawing )
263  {
264  QgsDebugMsg( "already rendering" );
266  }
267 
268  if ( mDrawing )
269  {
270  QgsDebugMsg( "still rendering - skipping" );
271  return;
272  }
273 
274  mDrawing = true;
275 
276  const QgsCoordinateTransform *ct;
277 
278 #ifdef QGISDEBUG
279  QgsDebugMsg( "Starting to render layer stack." );
280  QTime renderTime;
281  renderTime.start();
282 #endif
283 
284  if ( mOverview )
286 
287  mRenderContext.setPainter( painter );
289  //this flag is only for stopping during the current rendering progress,
290  //so must be false at every new render operation
292 
293  // set selection color
295  int myRed = prj->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
296  int myGreen = prj->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
297  int myBlue = prj->readNumEntry( "Gui", "/SelectionColorBluePart", 0 );
298  int myAlpha = prj->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 );
299  mRenderContext.setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) );
300 
301  //calculate scale factor
302  //use the specified dpi and not those from the paint device
303  //because sometimes QPainter units are in a local coord sys (e.g. in case of QGraphicsScene)
304  double sceneDpi = mScaleCalculator->dpi();
305  double scaleFactor = 1.0;
307  {
308  if ( forceWidthScale )
309  {
310  scaleFactor = *forceWidthScale;
311  }
312  else
313  {
314  scaleFactor = sceneDpi / 25.4;
315  }
316  }
317  double rasterScaleFactor = ( thePaintDevice->logicalDpiX() + thePaintDevice->logicalDpiY() ) / 2.0 / sceneDpi;
318  if ( mRenderContext.rasterScaleFactor() != rasterScaleFactor )
319  {
320  mRenderContext.setRasterScaleFactor( rasterScaleFactor );
321  }
322  if ( mRenderContext.scaleFactor() != scaleFactor )
323  {
324  mRenderContext.setScaleFactor( scaleFactor );
325  }
327  {
328  //add map scale to render context
330  }
331  if ( mLastExtent != mExtent )
332  {
334  }
335 
337  if ( mLabelingEngine )
339 
340  // render all layers in the stack, starting at the base
342  li.toBack();
343 
344  QgsRectangle r1, r2;
345 
346  while ( li.hasPrevious() )
347  {
349  {
350  break;
351  }
352 
353  // Store the painter in case we need to swap it out for the
354  // cache painter
355  QPainter * mypContextPainter = mRenderContext.painter();
356  // Flattened image for drawing when a blending mode is set
357  QImage * mypFlattenedImage = 0;
358 
359  QString layerId = li.previous();
360 
361  QgsDebugMsg( "Rendering at layer item " + layerId );
362 
363  // This call is supposed to cause the progress bar to
364  // advance. However, it seems that updating the progress bar is
365  // incompatible with having a QPainter active (the one that is
366  // passed into this function), as Qt produces a number of errors
367  // when try to do so. I'm (Gavin) not sure how to fix this, but
368  // added these comments and debug statement to help others...
369  QgsDebugMsg( "If there is a QPaintEngine error here, it is caused by an emit call" );
370 
371  //emit drawingProgress(myRenderCounter++, mLayerSet.size());
373 
374  if ( !ml )
375  {
376  QgsDebugMsg( "Layer not found in registry!" );
377  continue;
378  }
379 
380  QgsDebugMsg( QString( "layer %1: minscale:%2 maxscale:%3 scaledepvis:%4 extent:%5 blendmode:%6" )
381  .arg( ml->name() )
382  .arg( ml->minimumScale() )
383  .arg( ml->maximumScale() )
384  .arg( ml->hasScaleBasedVisibility() )
385  .arg( ml->extent().toString() )
386  .arg( ml->blendMode() )
387  );
388 
390  {
391  // Set the QPainter composition mode so that this layer is rendered using
392  // the desired blending mode
393  mypContextPainter->setCompositionMode( ml->blendMode() );
394  }
395 
396  if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mScale && mScale < ml->maximumScale() ) || mOverview )
397  {
398  connect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
399 
400  //
401  // Now do the call to the layer that actually does
402  // the rendering work!
403  //
404 
405  bool split = false;
406 
407  if ( hasCrsTransformEnabled() )
408  {
409  r1 = mExtent;
410  split = splitLayersExtent( ml, r1, r2 );
411  ct = transformation( ml );
413  QgsDebugMsg( " extent 1: " + r1.toString() );
414  QgsDebugMsg( " extent 2: " + r2.toString() );
415  if ( !r1.isFinite() || !r2.isFinite() ) //there was a problem transforming the extent. Skip the layer
416  {
417  continue;
418  }
419  }
420  else
421  {
422  ct = NULL;
423  }
424 
426 
427  //decide if we have to scale the raster
428  //this is necessary in case QGraphicsScene is used
429  bool scaleRaster = false;
430  QgsMapToPixel rasterMapToPixel;
431  QgsMapToPixel bk_mapToPixel;
432 
433  if ( ml->type() == QgsMapLayer::RasterLayer && qAbs( rasterScaleFactor - 1.0 ) > 0.000001 )
434  {
435  scaleRaster = true;
436  }
437 
438  QSettings mySettings;
439 
440  // If we are drawing with an alternative blending mode then we need to render to a separate image
441  // before compositing this on the map. This effectively flattens the layer and prevents
442  // blending occuring between objects on the layer
443  // (this is not required for raster layers or when layer caching is enabled, since that has the same effect)
444  bool flattenedLayer = false;
446  {
447  QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
448  if ((( vl->blendMode() != QPainter::CompositionMode_SourceOver )
449  || ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver )
450  || ( vl->layerTransparency() != 0 ) ) )
451  {
452  flattenedLayer = true;
453  mypFlattenedImage = new QImage( mRenderContext.painter()->device()->width(),
454  mRenderContext.painter()->device()->height(), QImage::Format_ARGB32 );
455  if ( mypFlattenedImage->isNull() )
456  {
457  QgsDebugMsg( "insufficient memory for image " + QString::number( mRenderContext.painter()->device()->width() ) + "x" + QString::number( mRenderContext.painter()->device()->height() ) );
458  emit drawError( ml );
459  painter->end(); // drawError is not caught by anyone, so we end painting to notify caller
460  return;
461  }
462  mypFlattenedImage->fill( 0 );
463  QPainter * mypPainter = new QPainter( mypFlattenedImage );
464  if ( mySettings.value( "/qgis/enable_anti_aliasing", true ).toBool() )
465  {
466  mypPainter->setRenderHint( QPainter::Antialiasing );
467  }
468  mypPainter->scale( rasterScaleFactor, rasterScaleFactor );
469  mRenderContext.setPainter( mypPainter );
470  }
471  }
472 
473  // Per feature blending mode
475  {
476  QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
477  if ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver )
478  {
479  // set the painter to the feature blend mode, so that features drawn
480  // on this layer will interact and blend with each other
482  }
483  }
484 
485  if ( scaleRaster )
486  {
487  bk_mapToPixel = mRenderContext.mapToPixel();
488  rasterMapToPixel = mRenderContext.mapToPixel();
489  rasterMapToPixel.setMapUnitsPerPixel( mRenderContext.mapToPixel().mapUnitsPerPixel() / rasterScaleFactor );
491  rasterMapToPixel.setYMaximum( mSize.height() * rasterScaleFactor );
493  mRenderContext.setMapToPixel( rasterMapToPixel );
495  mRenderContext.painter()->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
496  }
497 
498  if ( !ml->draw( mRenderContext ) )
499  {
500  emit drawError( ml );
501  }
502  else
503  {
504  QgsDebugMsg( "Layer rendered without issues" );
505  }
506 
507  if ( split )
508  {
510  if ( !ml->draw( mRenderContext ) )
511  {
512  emit drawError( ml );
513  }
514  }
515 
516  if ( scaleRaster )
517  {
518  mRenderContext.setMapToPixel( bk_mapToPixel );
520  }
521 
522  //apply layer transparency for vector layers
524  {
525  QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
526  if ( vl->layerTransparency() != 0 )
527  {
528  // a layer transparency has been set, so update the alpha for the flattened layer
529  // by combining it with the layer transparency
530  QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * vl->layerTransparency() / 100 ) );
531  // use destination in composition mode to merge source's alpha with destination
532  mRenderContext.painter()->setCompositionMode( QPainter::CompositionMode_DestinationIn );
534  mRenderContext.painter()->device()->height(), transparentFillColor );
535  }
536  }
537 
538  if ( flattenedLayer )
539  {
540  // If we flattened this layer for alternate blend modes, composite it now
541  delete mRenderContext.painter();
542  mRenderContext.setPainter( mypContextPainter );
543  mypContextPainter->save();
544  mypContextPainter->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
545  mypContextPainter->drawImage( 0, 0, *( mypFlattenedImage ) );
546  mypContextPainter->restore();
547  delete mypFlattenedImage;
548  mypFlattenedImage = 0;
549  }
550 
551  disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
552  }
553  else // layer not visible due to scale
554  {
555  QgsDebugMsg( "Layer not rendered because it is not within the defined "
556  "visibility scale range" );
557  }
558 
559  } // while (li.hasPrevious())
560 
561  QgsDebugMsg( "Done rendering map layers" );
562 
563  // Reset the composition mode before rendering the labels
564  mRenderContext.painter()->setCompositionMode( QPainter::CompositionMode_SourceOver );
565 
566  if ( !mOverview )
567  {
568  // render all labels for vector layers in the stack, starting at the base
569  li.toBack();
570  while ( li.hasPrevious() )
571  {
573  {
574  break;
575  }
576 
577  QString layerId = li.previous();
578 
579  // TODO: emit drawingProgress((myRenderCounter++),zOrder.size());
581 
582  if ( ml && ( ml->type() != QgsMapLayer::RasterLayer ) )
583  {
584  // only make labels if the layer is visible
585  // after scale dep viewing settings are checked
586  if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() < mScale && mScale < ml->maximumScale() ) )
587  {
588  bool split = false;
589 
590  if ( hasCrsTransformEnabled() )
591  {
592  QgsRectangle r1 = mExtent;
593  split = splitLayersExtent( ml, r1, r2 );
594  ct = transformation( ml );
596  }
597  else
598  {
599  ct = NULL;
600  }
601 
603 
604  ml->drawLabels( mRenderContext );
605  if ( split )
606  {
608  ml->drawLabels( mRenderContext );
609  }
610  }
611  }
612  }
613  } // if (!mOverview)
614 
615  // make sure progress bar arrives at 100%!
616  emit drawingProgress( 1, 1 );
617 
618  if ( mLabelingEngine )
619  {
620  // set correct extent
623 
626  }
627 
628  QgsDebugMsg( "Rendering completed in (seconds): " + QString( "%1" ).arg( renderTime.elapsed() / 1000.0 ) );
629 
630  mDrawing = false;
631 }
632 
634 {
636 
637  // Since the map units have changed, force a recalculation of the scale.
638  updateScale();
639 
640  emit mapUnitsChanged();
641 }
642 
644 {
645  return mScaleCalculator->mapUnits();
646 }
647 
648 void QgsMapRenderer::onDrawingProgress( int current, int total )
649 {
650  Q_UNUSED( current );
651  Q_UNUSED( total );
652 }
653 
655 {
656  if ( mProjectionsEnabled != enabled )
657  {
658  mProjectionsEnabled = enabled;
659  QgsDebugMsg( "Adjusting DistArea projection on/off" );
660  mDistArea->setEllipsoidalMode( enabled );
663 
665  emit hasCrsTransformEnabled( enabled ); // deprecated
667 
668  emit hasCrsTransformEnabledChanged( enabled );
669  }
670 }
671 
673 {
674  return mProjectionsEnabled;
675 }
676 
677 void QgsMapRenderer::setDestinationCrs( const QgsCoordinateReferenceSystem& crs, bool refreshCoordinateTransformInfo, bool transformExtent )
678 {
679  QgsDebugMsg( "* Setting destCRS : = " + crs.toProj4() );
680  QgsDebugMsg( "* DestCRS.srsid() = " + QString::number( crs.srsid() ) );
681  if ( *mDestCRS != crs )
682  {
683  if ( refreshCoordinateTransformInfo )
684  {
686  }
687  QgsRectangle rect;
688  if ( transformExtent && !mExtent.isEmpty() )
689  {
690  QgsCoordinateTransform transform( *mDestCRS, crs );
691  try
692  {
693  rect = transform.transformBoundingBox( mExtent );
694  }
695  catch ( QgsCsException &e )
696  {
697  QgsDebugMsg( QString( "Transform error caught: %1" ).arg( e.what() ) );
698  }
699  }
700 
701  QgsDebugMsg( "Setting DistArea CRS to " + QString::number( crs.srsid() ) );
702  mDistArea->setSourceCrs( crs.srsid() );
703  *mDestCRS = crs;
705 
706  if ( !rect.isEmpty() )
707  {
708  setExtent( rect );
709  }
710 
711  emit destinationSrsChanged();
712  }
713 }
714 
716 {
717  QgsDebugMsgLevel( "* Returning destCRS", 3 );
718  QgsDebugMsgLevel( "* DestCRS.srsid() = " + QString::number( mDestCRS->srsid() ), 3 );
719  QgsDebugMsgLevel( "* DestCRS.proj4() = " + mDestCRS->toProj4(), 3 );
720  return *mDestCRS;
721 }
722 
723 
725 {
726  bool split = false;
727 
728  if ( hasCrsTransformEnabled() )
729  {
730  try
731  {
732 #ifdef QGISDEBUG
733  // QgsLogger::debug<QgsRectangle>("Getting extent of canvas in layers CS. Canvas is ", extent, __FILE__, __FUNCTION__, __LINE__);
734 #endif
735  // Split the extent into two if the source CRS is
736  // geographic and the extent crosses the split in
737  // geographic coordinates (usually +/- 180 degrees,
738  // and is assumed to be so here), and draw each
739  // extent separately.
740  static const double splitCoord = 180.0;
741 
742  const QgsCoordinateTransform *transform = transformation( layer );
743  if ( layer->crs().geographicFlag() )
744  {
745  // Note: ll = lower left point
746  // and ur = upper right point
747 
748  QgsPoint ll( extent.xMinimum(), extent.yMinimum() );
749  QgsPoint ur( extent.xMaximum(), extent.yMaximum() );
750 
751  if ( transform )
752  {
753  ll = transform->transform( ll.x(), ll.y(),
755  ur = transform->transform( ur.x(), ur.y(),
757  extent = transform->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
758  }
759 
760  if ( ll.x() > ur.x() )
761  {
762  r2 = extent;
763  extent.setXMinimum( splitCoord );
764  r2.setXMaximum( splitCoord );
765  split = true;
766  }
767  }
768  else // can't cross 180
769  {
770  if ( transform )
771  {
772  extent = transform->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
773  }
774  }
775  }
776  catch ( QgsCsException &cse )
777  {
778  Q_UNUSED( cse );
779  QgsDebugMsg( "Transform error caught" );
780  extent = QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
781  r2 = QgsRectangle( -DBL_MAX, -DBL_MAX, DBL_MAX, DBL_MAX );
782  }
783  }
784  return split;
785 }
786 
788 {
789  //QgsDebugMsg( QString( "sourceCrs = " + tr( theLayer )->sourceCrs().authid() ) );
790  //QgsDebugMsg( QString( "destCRS = " + tr( theLayer )->destCRS().authid() ) );
791  //QgsDebugMsg( QString( "extent = " + extent.toString() ) );
792  if ( hasCrsTransformEnabled() )
793  {
794  try
795  {
796  const QgsCoordinateTransform *transform = transformation( theLayer );
797  if ( transform )
798  {
799  extent = transform->transformBoundingBox( extent );
800  }
801  }
802  catch ( QgsCsException &cse )
803  {
804  QgsMessageLog::logMessage( tr( "Transform error caught: %1" ).arg( cse.what() ), tr( "CRS" ) );
805  }
806  }
807 
808  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
809 
810  return extent;
811 }
812 
814 {
815 #if QGISDEBUG
816  const QgsCoordinateTransform *transform = transformation( theLayer );
817  QgsDebugMsg( QString( "layer sourceCrs = " + ( transform ? transform->sourceCrs().authid() : "none" ) ) );
818  QgsDebugMsg( QString( "layer destCRS = " + ( transform ? transform->destCRS().authid() : "none" ) ) );
819  QgsDebugMsg( QString( "extent = " + extent.toString() ) );
820 #endif
821  if ( hasCrsTransformEnabled() )
822  {
823  try
824  {
825  const QgsCoordinateTransform *transform = transformation( theLayer );
826  if ( transform )
827  {
828  extent = transform->transformBoundingBox( extent, QgsCoordinateTransform::ReverseTransform );
829  }
830  }
831  catch ( QgsCsException &cse )
832  {
833  QgsMessageLog::logMessage( tr( "Transform error caught: %1" ).arg( cse.what() ), tr( "CRS" ) );
834  }
835  }
836 
837  QgsDebugMsg( QString( "proj extent = " + extent.toString() ) );
838 
839  return extent;
840 }
841 
843 {
844  if ( hasCrsTransformEnabled() )
845  {
846  try
847  {
848  const QgsCoordinateTransform *transform = transformation( theLayer );
849  if ( transform )
850  {
851  point = transform->transform( point, QgsCoordinateTransform::ForwardTransform );
852  }
853  }
854  catch ( QgsCsException &cse )
855  {
856  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ) );
857  }
858  }
859  else
860  {
861  // leave point without transformation
862  }
863  return point;
864 }
865 
867 {
868  if ( hasCrsTransformEnabled() )
869  {
870  try
871  {
872  const QgsCoordinateTransform *transform = transformation( theLayer );
873  if ( transform )
874  {
875  rect = transform->transform( rect, QgsCoordinateTransform::ForwardTransform );
876  }
877  }
878  catch ( QgsCsException &cse )
879  {
880  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ) );
881  }
882  }
883  else
884  {
885  // leave point without transformation
886  }
887  return rect;
888 }
889 
891 {
892  if ( hasCrsTransformEnabled() )
893  {
894  try
895  {
896  const QgsCoordinateTransform *transform = transformation( theLayer );
897  if ( transform )
898  point = transform->transform( point, QgsCoordinateTransform::ReverseTransform );
899  }
900  catch ( QgsCsException &cse )
901  {
902  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ) );
903  }
904  }
905  else
906  {
907  // leave point without transformation
908  }
909  return point;
910 }
911 
913 {
914  if ( hasCrsTransformEnabled() )
915  {
916  try
917  {
918  const QgsCoordinateTransform *transform = transformation( theLayer );
919  if ( transform )
920  rect = transform->transform( rect, QgsCoordinateTransform::ReverseTransform );
921  }
922  catch ( QgsCsException &cse )
923  {
924  QgsMessageLog::logMessage( QString( "Transform error caught: %1" ).arg( cse.what() ) );
925  }
926  }
927  return rect;
928 }
929 
930 
932 {
933  QgsDebugMsg( "called." );
935 
936  // reset the map canvas extent since the extent may now be smaller
937  // We can't use a constructor since QgsRectangle normalizes the rectangle upon construction
939 
940  // iterate through the map layers and test each layers extent
941  // against the current min and max values
943  QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayerSet.count() ) );
944  while ( it != mLayerSet.end() )
945  {
946  QgsMapLayer * lyr = registry->mapLayer( *it );
947  if ( lyr == NULL )
948  {
949  QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( *it ) );
950  }
951  else
952  {
953  QgsDebugMsg( "Updating extent using " + lyr->name() );
954  QgsDebugMsg( "Input extent: " + lyr->extent().toString() );
955 
956  if ( lyr->extent().isNull() )
957  {
958  ++it;
959  continue;
960  }
961 
962  // Layer extents are stored in the coordinate system (CS) of the
963  // layer. The extent must be projected to the canvas CS
965 
966  QgsDebugMsg( "Output extent: " + extent.toString() );
967  mFullExtent.unionRect( extent );
968 
969  }
970  ++it;
971  }
972 
973  if ( mFullExtent.width() == 0.0 || mFullExtent.height() == 0.0 )
974  {
975  // If all of the features are at the one point, buffer the
976  // rectangle a bit. If they are all at zero, do something a bit
977  // more crude.
978 
979  if ( mFullExtent.xMinimum() == 0.0 && mFullExtent.xMaximum() == 0.0 &&
980  mFullExtent.yMinimum() == 0.0 && mFullExtent.yMaximum() == 0.0 )
981  {
982  mFullExtent.set( -1.0, -1.0, 1.0, 1.0 );
983  }
984  else
985  {
986  const double padFactor = 1e-8;
987  double widthPad = mFullExtent.xMinimum() * padFactor;
988  double heightPad = mFullExtent.yMinimum() * padFactor;
989  double xmin = mFullExtent.xMinimum() - widthPad;
990  double xmax = mFullExtent.xMaximum() + widthPad;
991  double ymin = mFullExtent.yMinimum() - heightPad;
992  double ymax = mFullExtent.yMaximum() + heightPad;
993  mFullExtent.set( xmin, ymin, xmax, ymax );
994  }
995  }
996 
997  QgsDebugMsg( "Full extent: " + mFullExtent.toString() );
998 }
999 
1001 {
1002  updateFullExtent();
1003  return mFullExtent;
1004 }
1005 
1007 {
1008  QgsDebugMsg( QString( "Entering: %1" ).arg( layers.join( ", " ) ) );
1009  mLayerSet = layers;
1010  updateFullExtent();
1011 }
1012 
1014 {
1015  return mLayerSet;
1016 }
1017 
1018 
1020 {
1021  QgsMapSettings tmpSettings;
1022  tmpSettings.readXML( theNode );
1023  //load coordinate transform into
1025  QDomElement layerCoordTransformInfoElem = theNode.firstChildElement( "layer_coordinate_transform_info" );
1026  if ( !layerCoordTransformInfoElem.isNull() )
1027  {
1028  QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName( "layer_coordinate_transform" );
1029  QDomElement layerCoordTransformElem;
1030  for ( int i = 0; i < layerCoordinateTransformList.size(); ++i )
1031  {
1032  layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement();
1033  QString layerId = layerCoordTransformElem.attribute( "layerid" );
1034  if ( layerId.isEmpty() )
1035  {
1036  continue;
1037  }
1038 
1040  lct.srcAuthId = layerCoordTransformElem.attribute( "srcAuthId" );
1041  lct.destAuthId = layerCoordTransformElem.attribute( "destAuthId" );
1042  lct.srcDatumTransform = layerCoordTransformElem.attribute( "srcDatumTransform", "-1" ).toInt();
1043  lct.destDatumTransform = layerCoordTransformElem.attribute( "destDatumTransform", "-1" ).toInt();
1044  mLayerCoordinateTransformInfo.insert( layerId, lct );
1045  }
1046  }
1047 
1048 
1049  setMapUnits( tmpSettings.mapUnits() );
1050  setExtent( tmpSettings.extent() );
1052  setDestinationCrs( tmpSettings.destinationCrs() );
1053 
1054 
1055  return true;
1056 }
1057 
1059 {
1060  QgsMapSettings tmpSettings;
1061  tmpSettings.setOutputDpi( outputDpi() );
1062  tmpSettings.setOutputSize( outputSize() );
1063  tmpSettings.setMapUnits( mapUnits() );
1064  tmpSettings.setExtent( extent() );
1066  tmpSettings.setDestinationCrs( destinationCrs() );
1067 
1068  tmpSettings.writeXML( theNode, theDoc );
1069  // layer coordinate transform infos
1070  QDomElement layerCoordTransformInfo = theDoc.createElement( "layer_coordinate_transform_info" );
1072  for ( ; coordIt != mLayerCoordinateTransformInfo.constEnd(); ++coordIt )
1073  {
1074  QDomElement layerCoordTransformElem = theDoc.createElement( "layer_coordinate_transform" );
1075  layerCoordTransformElem.setAttribute( "layerid", coordIt.key() );
1076  layerCoordTransformElem.setAttribute( "srcAuthId", coordIt->srcAuthId );
1077  layerCoordTransformElem.setAttribute( "destAuthId", coordIt->destAuthId );
1078  layerCoordTransformElem.setAttribute( "srcDatumTransform", QString::number( coordIt->srcDatumTransform ) );
1079  layerCoordTransformElem.setAttribute( "destDatumTransform", QString::number( coordIt->destDatumTransform ) );
1080  layerCoordTransformInfo.appendChild( layerCoordTransformElem );
1081  }
1082  theNode.appendChild( layerCoordTransformInfo );
1083  return true;
1084 }
1085 
1087 {
1088  if ( mLabelingEngine )
1089  delete mLabelingEngine;
1090 
1091  mLabelingEngine = iface;
1092 }
1093 
1095 {
1096  if ( !layer || !mDestCRS )
1097  {
1098  return 0;
1099  }
1100 
1101  if ( layer->crs().authid() == mDestCRS->authid() )
1102  {
1103  return 0;
1104  }
1105 
1108  && ctIt->srcAuthId == layer->crs().authid()
1109  && ctIt->destAuthId == mDestCRS->authid() )
1110  {
1111  return QgsCoordinateTransformCache::instance()->transform( ctIt->srcAuthId, ctIt->destAuthId, ctIt->srcDatumTransform, ctIt->destDatumTransform );
1112  }
1113  else
1114  {
1115  emit datumTransformInfoRequested( layer, layer->crs().authid(), mDestCRS->authid() );
1116  }
1117 
1118  //still not present? get coordinate transformation with -1/-1 datum transform as default
1119  ctIt = mLayerCoordinateTransformInfo.find( layer->id() );
1121  || ctIt->srcAuthId == layer->crs().authid()
1122  || ctIt->destAuthId == mDestCRS->authid()
1123  )
1124  {
1126  }
1127  return QgsCoordinateTransformCache::instance()->transform( ctIt->srcAuthId, ctIt->destAuthId, ctIt->srcDatumTransform, ctIt->destDatumTransform );
1128 }
1129 
1132 QPainter::CompositionMode QgsMapRenderer::getCompositionMode( const QgsMapRenderer::BlendMode &blendMode )
1133 {
1134  // Map QgsMapRenderer::BlendNormal to QPainter::CompositionMode
1135  switch ( blendMode )
1136  {
1138  return QPainter::CompositionMode_SourceOver;
1140  return QPainter::CompositionMode_Lighten;
1142  return QPainter::CompositionMode_Screen;
1144  return QPainter::CompositionMode_ColorDodge;
1146  return QPainter::CompositionMode_Plus;
1148  return QPainter::CompositionMode_Darken;
1150  return QPainter::CompositionMode_Multiply;
1152  return QPainter::CompositionMode_ColorBurn;
1154  return QPainter::CompositionMode_Overlay;
1156  return QPainter::CompositionMode_SoftLight;
1158  return QPainter::CompositionMode_HardLight;
1160  return QPainter::CompositionMode_Difference;
1162  return QPainter::CompositionMode_Exclusion;
1164  return QPainter::CompositionMode_Source;
1166  return QPainter::CompositionMode_DestinationOver;
1168  return QPainter::CompositionMode_Clear;
1170  return QPainter::CompositionMode_Destination;
1172  return QPainter::CompositionMode_SourceIn;
1174  return QPainter::CompositionMode_DestinationIn;
1176  return QPainter::CompositionMode_SourceOut;
1178  return QPainter::CompositionMode_DestinationOut;
1180  return QPainter::CompositionMode_SourceAtop;
1182  return QPainter::CompositionMode_DestinationAtop;
1184  return QPainter::CompositionMode_Xor;
1185  default:
1186  QgsDebugMsg( QString( "Blend mode %1 mapped to SourceOver" ).arg( blendMode ) );
1187  return QPainter::CompositionMode_SourceOver;
1188  }
1189 }
1190 
1191 QgsMapRenderer::BlendMode QgsMapRenderer::getBlendModeEnum( const QPainter::CompositionMode &blendMode )
1192 {
1193  // Map QPainter::CompositionMode to QgsMapRenderer::BlendNormal
1194  switch ( blendMode )
1195  {
1196  case QPainter::CompositionMode_SourceOver:
1198  case QPainter::CompositionMode_Lighten:
1200  case QPainter::CompositionMode_Screen:
1202  case QPainter::CompositionMode_ColorDodge:
1204  case QPainter::CompositionMode_Plus:
1206  case QPainter::CompositionMode_Darken:
1208  case QPainter::CompositionMode_Multiply:
1210  case QPainter::CompositionMode_ColorBurn:
1212  case QPainter::CompositionMode_Overlay:
1214  case QPainter::CompositionMode_SoftLight:
1216  case QPainter::CompositionMode_HardLight:
1218  case QPainter::CompositionMode_Difference:
1220  case QPainter::CompositionMode_Exclusion:
1222  case QPainter::CompositionMode_Source:
1224  case QPainter::CompositionMode_DestinationOver:
1226  case QPainter::CompositionMode_Clear:
1228  case QPainter::CompositionMode_Destination:
1230  case QPainter::CompositionMode_SourceIn:
1232  case QPainter::CompositionMode_DestinationIn:
1234  case QPainter::CompositionMode_SourceOut:
1236  case QPainter::CompositionMode_DestinationOut:
1238  case QPainter::CompositionMode_SourceAtop:
1240  case QPainter::CompositionMode_DestinationAtop:
1242  case QPainter::CompositionMode_Xor:
1243  return QgsMapRenderer::BlendXor;
1244  default:
1245  QgsDebugMsg( QString( "Composition mode %1 mapped to Normal" ).arg( blendMode ) );
1247  }
1248 }
1249 
1250 Q_GUI_EXPORT extern int qt_defaultDpiX();
1251 
1253 {
1254  // make sure the settings object is up-to-date
1262  return mMapSettings;
1263 }
1264 
1265 void QgsMapRenderer::addLayerCoordinateTransform( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform )
1266 {
1268  lt.srcAuthId = srcAuthId;
1269  lt.destAuthId = destAuthId;
1270  lt.srcDatumTransform = srcDatumTransform;
1271  lt.destDatumTransform = destDatumTransform;
1272  mLayerCoordinateTransformInfo.insert( layerId, lt );
1273 }
1274 
1276 {
1278 }
1279 
1280 bool QgsMapRenderer::mDrawing = false;
const QgsMapSettings & mapSettings()
bridge to QgsMapSettings
virtual void exit()=0
called when we're done with rendering
void setMapUnits(QGis::UnitType mapUnits)
Set the map units.
const QgsCoordinateReferenceSystem & sourceCrs() const
void unionRect(const QgsRectangle &rect)
updates rectangle to include passed argument
QDomNodeList elementsByTagName(const QString &tagname) const
void rotationChanged(double)
emitted when the current rotation gets changed
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
virtual Q_DECL_DEPRECATED void init(QgsMapRenderer *mp)=0
called when we're going to start with rendering
void setRenderingStopped(bool stopped)
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:49
void clearLayerCoordinateTransforms()
void render(QPainter *painter, double *forceWidthScale=0)
starts rendering
void setLabelingEngine(QgsLabelingEngineInterface *iface)
Set labeling engine.
bool isEmpty() const
test if rectangle is empty.
iterator insert(const Key &key, const T &value)
QgsMapLayer::LayerType type() const
Get the type of the layer.
Definition: qgsmaplayer.cpp:93
void setMinimal()
Set a rectangle so that min corner is at max and max corner is at min.
int width() const
virtual void drawLabels(QgsRenderContext &rendererContext)
Draw labels.
bool end()
const Key key(const T &value) const
void fillRect(const QRectF &rectangle, const QBrush &brush)
void setCompositionMode(CompositionMode mode)
void drawError(QgsMapLayer *)
emitted when layer's draw() returned false
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:167
void readXML(QDomNode &theNode)
const T & previous()
OutputUnits mOutputUnits
Output units.
QString attribute(const QString &name, const QString &defValue) const
bool isFinite() const
Returns true if the rectangle has finite boundaries.
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:192
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
UnitType
Map units that qgis supports.
Definition: qgis.h:229
bool mProjectionsEnabled
detemines whether on the fly projection support is enabled
QgsRectangle mLastExtent
Last extent to we drew so we know if we can used layer render caching or not.
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
double rendererScale() const
QgsScaleCalculator * mScaleCalculator
scale calculator
QgsRectangle extent() const
returns current extent
void scale(qreal sx, qreal sy)
void addLayerCoordinateTransform(const QString &layerId, const QString &srcAuthId, const QString &destAuthId, int srcDatumTransform=-1, int destDatumTransform=-1)
void setRendererScale(double scale)
float minimumScale() const
Returns the minimum scale denominator at which the layer is visible.
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:464
void drawingProgress(int current, int total)
~QgsMapRenderer()
destructor
void save()
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
Q_DECL_DEPRECATED void setParameters(double mapUnitsPerPixel, double xmin, double ymin, double height)
Set parameters for use in transforming coordinates.
QGis::UnitType mapUnits() const
Returns current map units.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
void setProjectionsEnabled(bool enabled)
sets whether to use projections for this layer set
static bool mDrawing
indicates drawing in progress
bool splitLayersExtent(QgsMapLayer *layer, QgsRectangle &extent, QgsRectangle &r2)
Convenience function to project an extent into the layer source CRS, but also split it into two exten...
QgsPoint transform(const QgsPoint &p, TransformDirection direction=ForwardTransform) const
QString join(const QString &separator) const
double scaleFactor() const
bool isNull() const
void setLayerSet(const QStringList &layers)
change current layer set
double outputDpi()
accessor for output dpi
Q_DECL_DEPRECATED void setYMaximum(double yMax)
Set maximum y value.
QgsPoint mapToLayerCoordinates(QgsMapLayer *theLayer, QgsPoint point)
transform point coordinates from output CRS to layer's CRS
void setLayers(const QStringList &layers)
Set list of layer IDs for map rendering.
static QgsCoordinateTransformCache * instance()
Definition: qgscrscache.cpp:22
QgsRectangle outputExtentToLayerExtent(QgsMapLayer *theLayer, QgsRectangle extent)
transform bounding box from output CRS to layer's CRS
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QString tr(const char *sourceText, const char *disambiguation, int n)
void setExtent(const QgsRectangle &extent)
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=0) const
const QgsCoordinateTransform * transformation(const QgsMapLayer *layer) const
QgsRectangle mExtent
current extent to be drawn
static void logMessage(QString message, QString tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
QgsMapRenderer()
constructor
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point)
transform point coordinates from layer's CRS to output CRS
void set(const QgsPoint &p1, const QgsPoint &p2)
Set the rectangle from two QgsPoints.
The QgsMapSettings class contains configuration for rendering of the map.
void setCoordinateTransform(const QgsCoordinateTransform *t)
Sets coordinate transformation.
QSize outputSize()
accessor for output size
virtual bool draw(QgsRenderContext &rendererContext)
This is the method that does the actual work of drawing the layer onto a paint device.
bool useAdvancedEffects() const
Returns true if advanced effects such as blend modes such be used.
int width() const
QDomElement toElement() const
double mRotation
Map rotation.
const QString & name() const
Get the display name of the layer.
QMutex mRenderMutex
Locks rendering loop for concurrent draws.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
const QgsCoordinateTransform * transform(const QString &srcAuthId, const QString &destAuthId, int srcDatumTransform=-1, int destDatumTransform=-1)
Returns coordinate transformation.
Definition: qgscrscache.cpp:37
void setSelectionColor(const QColor &color)
int elapsed() const
QString number(int n, int base)
int count(const T &value) const
void extentsChanged()
emitted when the current extent gets changed
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
void processEvents(QFlags< QEventLoop::ProcessEventsFlag > flags)
QgsCoordinateReferenceSystem * mDestCRS
destination spatial reference system of the projection
void setScaleFactor(double factor)
QgsDistanceArea * mDistArea
tool for measuring
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
bool hasScaleBasedVisibility() const
Returns whether scale based visibility is enabled for the layer.
void adjustExtentToSize()
adjust extent to fit the pixmap size
const_iterator constEnd() const
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:197
void fill(uint pixelValue)
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:182
void hasCrsTransformEnabledChanged(bool flag)
This signal is emitted when CRS transformation is enabled/disabled.
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:34
bool renderingStopped() const
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
void setAttribute(const QString &name, const QString &value)
QSize toSize() const
void setMapUnits(QGis::UnitType u)
Set units of map's geographical coordinates - used for scale calculation.
float maximumScale() const
Returns the maximum scale denominator at which the layer is visible.
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
int toInt(bool *ok, int base) const
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:172
void setDrawEditingInformation(bool b)
bool isEmpty() const
bool setExtent(const QgsRectangle &extent)
sets extent and checks whether suitable (returns false if not)
Q_GUI_EXPORT int qt_defaultDpiX()
void setMapUnits(QGis::UnitType u)
const long GEOCRS_ID
Magic number for a geographic coord sys in QGIS srs.db tbl_srs.srs_id.
Definition: qgis.h:410
QPaintDevice * device() const
void destinationSrsChanged()
void setPainter(QPainter *p)
double rasterScaleFactor() const
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
Definition: qgsmaplayer.cpp:99
Reads and writes project states.
Definition: qgsproject.h:67
bool mOverview
indicates whether it's map image for overview
double rotation() const
returns current rotation in clockwise degrees
double mapUnitsPerPixel() const
Return current map units per pixel.
QGis::UnitType mapUnits() const
Get units of map's geographical coordinates - used for scale calculation.
void setOutputSize(QSize size, int dpi)
void mapUnitsChanged()
A class to represent a point.
Definition: qgspoint.h:63
void updateFullExtent()
updates extent of the layer set
This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a m...
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
int logicalDpiX() const
int logicalDpiY() const
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs, bool refreshCoordinateTransformInfo=true, bool transformExtent=true)
sets destination coordinate reference system
void clear()
iterator end()
void setRotation(double degrees)
sets rotation value in clockwise degrees
iterator find(const Key &key)
QString qgsDoubleToString(const double &a, const int &precision=17)
Definition: qgis.h:339
double dpi()
Accessor for dpi used in scale calculations.
bool writeXML(QDomNode &theNode, QDomDocument &theDoc)
write settings
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
int layerTransparency() const
Returns the current transparency for the vector layer.
bool isNull() const
static QPainter::CompositionMode getCompositionMode(const QgsMapRenderer::BlendMode &blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
void restore()
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:465
General purpose distance and area calculator.
QgsRectangle fullExtent()
returns current extent of layer set
QString what() const
Definition: qgsexception.h:35
QVariant value(const QString &key, const QVariant &defaultValue) const
const_iterator constBegin() const
bool hasPrevious() const
QgsMapSettings mMapSettings
map settings - used only for export in mapSettings() for use in classes that deal with QgsMapSettings...
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, QFlags< Qt::ImageConversionFlag > flags)
QPainter * painter()
virtual void drawLabeling(QgsRenderContext &context)=0
called when the map is drawn and labels should be placed
void setOutputSize(const QSize &size)
Set the size of the resulting map image.
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:177
Q_DECL_DEPRECATED void onDrawingProgress(int current, int total)
void setLabelingEngine(QgsLabelingEngineInterface *iface)
double mScale
Map scale denominator at its current zoom level.
QHash< QString, QgsLayerCoordinateTransform > mLayerCoordinateTransformInfo
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:351
QDomElement firstChildElement(const QString &tagName) const
Class for storing a coordinate reference system (CRS)
void setExtent(const QgsRectangle &rect)
Set coordinates of the rectangle which should be rendered.
int height() const
void setMapToPixel(const QgsMapToPixel &mtp)
QgsRectangle extent() const
Return geographical coordinates of the rectangle that should be rendered.
Class for doing transforms between two map coordinate systems.
bool toBool() const
const QgsMapToPixel & mapToPixel() const
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
void start()
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
void updateScale()
Recalculate the map scale.
QStringList mLayerSet
stores array of layers to be rendered (identified by string)
static QgsMapRenderer::BlendMode getBlendModeEnum(const QPainter::CompositionMode &blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
void setRasterScaleFactor(double factor)
void datumTransformInfoRequested(const QgsMapLayer *ml, const QString &srcAuthId, const QString &destAuthId) const
Notifies higher level components to show the datum transform dialog and add a QgsLayerCoordinateTrans...
Custom exception class for Coordinate Reference System related exceptions.
double mMapUnitsPerPixel
map units per pixel
int size() const
Labeling engine interface.
int height() const
QgsRenderContext mRenderContext
Encapsulates context of rendering.
QDomElement createElement(const QString &tagName)
qreal height() const
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:202
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setMapUnitsPerPixel(double mapUnitsPerPixel)
Set map units per pixel.
const QgsCoordinateReferenceSystem & destCRS() const
virtual QgsRectangle extent()
Return the extent of the layer.
QGis::UnitType mapUnits() const
Represents a vector layer which manages a vector based data sets.
QgsLabelingEngineInterface * mLabelingEngine
Labeling engine (NULL by default)
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
bool readXML(QDomNode &theNode)
read settings
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:187
QStringList & layerSet()
returns current layer set
iterator begin()
qreal width() const
QgsRectangle mFullExtent
full extent of the layer set
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:162
QgsRectangle transformBoundingBox(const QgsRectangle &theRect, TransformDirection direction=ForwardTransform, const bool handle180Crossover=false) const
void setEllipsoidalMode(bool flag)
sets whether coordinates must be projected to ellipsoid before measuring
QgsRectangle layerExtentToOutputExtent(QgsMapLayer *theLayer, QgsRectangle extent)
transform bounding box from layer's CRS to output CRS
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:207
void setCrsTransformEnabled(bool enabled)
sets whether to use projections for this layer set
QDomNode at(int index) const
QString toProj4() const
Get the Proj Proj4 string representation of this srs.
void writeXML(QDomNode &theNode, QDomDocument &theDoc)