QGIS API Documentation  2.13.0-Master
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 = nullptr;
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 ), qgsDoubleToString( mapUnitsPerPixelY ) ) );
209  QgsDebugMsg( QString( "Pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( myWidth ), qgsDoubleToString( myHeight ) ) );
210  QgsDebugMsg( QString( "Extent dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() ), 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 ), qgsDoubleToString( mExtent.height() / myHeight ) ) );
220 
221  QgsDebugMsg( QString( "Recalced pixmap dimensions (x,y) : %1, %2" ).arg( qgsDoubleToString( mExtent.width() / mMapUnitsPerPixel ), 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 ( qgsDoubleNear( mSize.width(), 1.0 ) && qgsDoubleNear( mSize.height(), 1.0 ) )
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 ( !qgsDoubleNear( mRenderContext.rasterScaleFactor(), rasterScaleFactor ) )
319  {
320  mRenderContext.setRasterScaleFactor( rasterScaleFactor );
321  }
322  if ( !qgsDoubleNear( 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 = nullptr;
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 = nullptr;
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 occurring 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 = nullptr;
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 = nullptr;
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
942  QgsDebugMsg( QString( "Layer count: %1" ).arg( mLayerSet.count() ) );
943  Q_FOREACH ( const QString layerId, mLayerSet )
944  {
945  QgsMapLayer * lyr = registry->mapLayer( layerId );
946  if ( !lyr )
947  {
948  QgsDebugMsg( QString( "WARNING: layer '%1' not found in map layer registry!" ).arg( layerId ) );
949  }
950  else
951  {
952  QgsDebugMsg( "Updating extent using " + lyr->name() );
953  QgsDebugMsg( "Input extent: " + lyr->extent().toString() );
954 
955  if ( lyr->extent().isNull() )
956  {
957  continue;
958  }
959 
960  // Layer extents are stored in the coordinate system (CS) of the
961  // layer. The extent must be projected to the canvas CS
963 
964  QgsDebugMsg( "Output extent: " + extent.toString() );
965  mFullExtent.unionRect( extent );
966 
967  }
968  }
969 
970  if ( mFullExtent.width() == 0.0 || mFullExtent.height() == 0.0 )
971  {
972  // If all of the features are at the one point, buffer the
973  // rectangle a bit. If they are all at zero, do something a bit
974  // more crude.
975 
976  if ( mFullExtent.xMinimum() == 0.0 && mFullExtent.xMaximum() == 0.0 &&
977  mFullExtent.yMinimum() == 0.0 && mFullExtent.yMaximum() == 0.0 )
978  {
979  mFullExtent.set( -1.0, -1.0, 1.0, 1.0 );
980  }
981  else
982  {
983  const double padFactor = 1e-8;
984  double widthPad = mFullExtent.xMinimum() * padFactor;
985  double heightPad = mFullExtent.yMinimum() * padFactor;
986  double xmin = mFullExtent.xMinimum() - widthPad;
987  double xmax = mFullExtent.xMaximum() + widthPad;
988  double ymin = mFullExtent.yMinimum() - heightPad;
989  double ymax = mFullExtent.yMaximum() + heightPad;
990  mFullExtent.set( xmin, ymin, xmax, ymax );
991  }
992  }
993 
994  QgsDebugMsg( "Full extent: " + mFullExtent.toString() );
995 }
996 
998 {
1000  return mFullExtent;
1001 }
1002 
1004 {
1005  QgsDebugMsg( QString( "Entering: %1" ).arg( layers.join( ", " ) ) );
1006  mLayerSet = layers;
1007  updateFullExtent();
1008 }
1009 
1011 {
1012  return mLayerSet;
1013 }
1014 
1015 
1017 {
1018  QgsMapSettings tmpSettings;
1019  tmpSettings.readXML( theNode );
1020  //load coordinate transform into
1022  QDomElement layerCoordTransformInfoElem = theNode.firstChildElement( "layer_coordinate_transform_info" );
1023  if ( !layerCoordTransformInfoElem.isNull() )
1024  {
1025  QDomNodeList layerCoordinateTransformList = layerCoordTransformInfoElem.elementsByTagName( "layer_coordinate_transform" );
1026  QDomElement layerCoordTransformElem;
1027  for ( int i = 0; i < layerCoordinateTransformList.size(); ++i )
1028  {
1029  layerCoordTransformElem = layerCoordinateTransformList.at( i ).toElement();
1030  QString layerId = layerCoordTransformElem.attribute( "layerid" );
1031  if ( layerId.isEmpty() )
1032  {
1033  continue;
1034  }
1035 
1037  lct.srcAuthId = layerCoordTransformElem.attribute( "srcAuthId" );
1038  lct.destAuthId = layerCoordTransformElem.attribute( "destAuthId" );
1039  lct.srcDatumTransform = layerCoordTransformElem.attribute( "srcDatumTransform", "-1" ).toInt();
1040  lct.destDatumTransform = layerCoordTransformElem.attribute( "destDatumTransform", "-1" ).toInt();
1041  mLayerCoordinateTransformInfo.insert( layerId, lct );
1042  }
1043  }
1044 
1045 
1046  setMapUnits( tmpSettings.mapUnits() );
1047  setExtent( tmpSettings.extent() );
1049  setDestinationCrs( tmpSettings.destinationCrs() );
1050 
1051 
1052  return true;
1053 }
1054 
1056 {
1057  QgsMapSettings tmpSettings;
1058  tmpSettings.setOutputDpi( outputDpi() );
1059  tmpSettings.setOutputSize( outputSize() );
1060  tmpSettings.setMapUnits( mapUnits() );
1061  tmpSettings.setExtent( extent() );
1063  tmpSettings.setDestinationCrs( destinationCrs() );
1064 
1065  tmpSettings.writeXML( theNode, theDoc );
1066  // layer coordinate transform infos
1067  QDomElement layerCoordTransformInfo = theDoc.createElement( "layer_coordinate_transform_info" );
1069  for ( ; coordIt != mLayerCoordinateTransformInfo.constEnd(); ++coordIt )
1070  {
1071  QDomElement layerCoordTransformElem = theDoc.createElement( "layer_coordinate_transform" );
1072  layerCoordTransformElem.setAttribute( "layerid", coordIt.key() );
1073  layerCoordTransformElem.setAttribute( "srcAuthId", coordIt->srcAuthId );
1074  layerCoordTransformElem.setAttribute( "destAuthId", coordIt->destAuthId );
1075  layerCoordTransformElem.setAttribute( "srcDatumTransform", QString::number( coordIt->srcDatumTransform ) );
1076  layerCoordTransformElem.setAttribute( "destDatumTransform", QString::number( coordIt->destDatumTransform ) );
1077  layerCoordTransformInfo.appendChild( layerCoordTransformElem );
1078  }
1079  theNode.appendChild( layerCoordTransformInfo );
1080  return true;
1081 }
1082 
1084 {
1085  if ( mLabelingEngine )
1086  delete mLabelingEngine;
1087 
1088  mLabelingEngine = iface;
1089 }
1090 
1092 {
1093  if ( !layer || !mDestCRS )
1094  {
1095  return nullptr;
1096  }
1097 
1098  if ( layer->crs().authid() == mDestCRS->authid() )
1099  {
1100  return nullptr;
1101  }
1102 
1105  && ctIt->srcAuthId == layer->crs().authid()
1106  && ctIt->destAuthId == mDestCRS->authid() )
1107  {
1108  return QgsCoordinateTransformCache::instance()->transform( ctIt->srcAuthId, ctIt->destAuthId, ctIt->srcDatumTransform, ctIt->destDatumTransform );
1109  }
1110  else
1111  {
1112  emit datumTransformInfoRequested( layer, layer->crs().authid(), mDestCRS->authid() );
1113  }
1114 
1115  //still not present? get coordinate transformation with -1/-1 datum transform as default
1116  ctIt = mLayerCoordinateTransformInfo.find( layer->id() );
1118  || ctIt->srcAuthId == layer->crs().authid()
1119  || ctIt->destAuthId == mDestCRS->authid()
1120  )
1121  {
1123  }
1124  return QgsCoordinateTransformCache::instance()->transform( ctIt->srcAuthId, ctIt->destAuthId, ctIt->srcDatumTransform, ctIt->destDatumTransform );
1125 }
1126 
1130 {
1131  // Map QgsMapRenderer::BlendNormal to QPainter::CompositionMode
1132  switch ( blendMode )
1133  {
1135  return QPainter::CompositionMode_SourceOver;
1137  return QPainter::CompositionMode_Lighten;
1139  return QPainter::CompositionMode_Screen;
1141  return QPainter::CompositionMode_ColorDodge;
1143  return QPainter::CompositionMode_Plus;
1145  return QPainter::CompositionMode_Darken;
1147  return QPainter::CompositionMode_Multiply;
1149  return QPainter::CompositionMode_ColorBurn;
1151  return QPainter::CompositionMode_Overlay;
1153  return QPainter::CompositionMode_SoftLight;
1155  return QPainter::CompositionMode_HardLight;
1157  return QPainter::CompositionMode_Difference;
1159  return QPainter::CompositionMode_Exclusion;
1161  return QPainter::CompositionMode_Source;
1163  return QPainter::CompositionMode_DestinationOver;
1165  return QPainter::CompositionMode_Clear;
1167  return QPainter::CompositionMode_Destination;
1169  return QPainter::CompositionMode_SourceIn;
1171  return QPainter::CompositionMode_DestinationIn;
1173  return QPainter::CompositionMode_SourceOut;
1175  return QPainter::CompositionMode_DestinationOut;
1177  return QPainter::CompositionMode_SourceAtop;
1179  return QPainter::CompositionMode_DestinationAtop;
1181  return QPainter::CompositionMode_Xor;
1182  default:
1183  QgsDebugMsg( QString( "Blend mode %1 mapped to SourceOver" ).arg( blendMode ) );
1184  return QPainter::CompositionMode_SourceOver;
1185  }
1186 }
1187 
1188 QgsMapRenderer::BlendMode QgsMapRenderer::getBlendModeEnum( QPainter::CompositionMode blendMode )
1189 {
1190  // Map QPainter::CompositionMode to QgsMapRenderer::BlendNormal
1191  switch ( blendMode )
1192  {
1193  case QPainter::CompositionMode_SourceOver:
1195  case QPainter::CompositionMode_Lighten:
1197  case QPainter::CompositionMode_Screen:
1199  case QPainter::CompositionMode_ColorDodge:
1201  case QPainter::CompositionMode_Plus:
1203  case QPainter::CompositionMode_Darken:
1205  case QPainter::CompositionMode_Multiply:
1207  case QPainter::CompositionMode_ColorBurn:
1209  case QPainter::CompositionMode_Overlay:
1211  case QPainter::CompositionMode_SoftLight:
1213  case QPainter::CompositionMode_HardLight:
1215  case QPainter::CompositionMode_Difference:
1217  case QPainter::CompositionMode_Exclusion:
1219  case QPainter::CompositionMode_Source:
1221  case QPainter::CompositionMode_DestinationOver:
1223  case QPainter::CompositionMode_Clear:
1225  case QPainter::CompositionMode_Destination:
1227  case QPainter::CompositionMode_SourceIn:
1229  case QPainter::CompositionMode_DestinationIn:
1231  case QPainter::CompositionMode_SourceOut:
1233  case QPainter::CompositionMode_DestinationOut:
1235  case QPainter::CompositionMode_SourceAtop:
1237  case QPainter::CompositionMode_DestinationAtop:
1239  case QPainter::CompositionMode_Xor:
1240  return QgsMapRenderer::BlendXor;
1241  default:
1242  QgsDebugMsg( QString( "Composition mode %1 mapped to Normal" ).arg( blendMode ) );
1244  }
1245 }
1246 
1247 Q_GUI_EXPORT extern int qt_defaultDpiX();
1248 
1250 {
1251  // make sure the settings object is up-to-date
1259  return mMapSettings;
1260 }
1261 
1262 void QgsMapRenderer::addLayerCoordinateTransform( const QString& layerId, const QString& srcAuthId, const QString& destAuthId, int srcDatumTransform, int destDatumTransform )
1263 {
1265  lt.srcAuthId = srcAuthId;
1266  lt.destAuthId = destAuthId;
1267  lt.srcDatumTransform = srcDatumTransform;
1268  lt.destDatumTransform = destDatumTransform;
1269  mLayerCoordinateTransformInfo.insert( layerId, lt );
1270 }
1271 
1273 {
1275 }
1276 
1277 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 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:99
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
QString name() const
Get the display name of the layer.
void setRenderHint(RenderHint hint, bool on)
QDomNode appendChild(const QDomNode &newChild)
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:171
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:196
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
long srsid() const
Returns the SrsId, if available.
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:155
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:407
void drawingProgress(int current, int total)
static QgsMapRenderer::BlendMode getBlendModeEnum(QPainter::CompositionMode blendMode)
Returns a BlendMode corresponding to a QPainter::CompositionMode.
~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
Transform the point from Source Coordinate System to Destination Coordinate System If the direction i...
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)
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Definition: qgis.h:285
const QgsCoordinateTransform * transformation(const QgsMapLayer *layer) const
QgsRectangle mExtent
current extent to be drawn
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
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.
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:41
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)
void setOutputSize(QSize size)
Set the size of the resulting map image.
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:201
void fill(uint pixelValue)
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:186
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
QString qgsDoubleToString(double a, int precision=17)
Definition: qgis.h:274
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:176
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:353
static void logMessage(const QString &message, const QString &tag=QString::null, MessageLevel level=WARNING)
add a message to the instance (and create it if necessary)
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.
Reads and writes project states.
Definition: qgsproject.h:69
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()
static QPainter::CompositionMode getCompositionMode(BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
A class to represent a point.
Definition: qgspoint.h:65
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()
void setRotation(double degrees)
sets rotation value in clockwise degrees
iterator find(const Key &key)
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
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
void restore()
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:408
General purpose distance and area calculator.
QgsRectangle fullExtent()
returns current extent of layer set
QString what() const
Definition: qgsexception.h:36
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 setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:181
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:379
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.
QString authid() const
Returns the authority identifier for the CRS, which includes both the authority (eg EPSG) and the CRS...
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()
void updateScale()
Recalculate the map scale.
QStringList mLayerSet
stores array of layers to be rendered (identified by string)
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:206
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 (nullptr by default)
bool geographicFlag() const
Returns whether the CRS is a geographic CRS.
QString toString(bool automaticPrecision=false) const
returns string representation of form xmin,ymin xmax,ymax
bool readXML(QDomNode &theNode)
read settings
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:191
QStringList & layerSet()
returns current layer set
void render(QPainter *painter, double *forceWidthScale=nullptr)
starts rendering
qreal width() const
QgsRectangle mFullExtent
full extent of the layer set
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:166
QgsRectangle transformBoundingBox(const QgsRectangle &theRect, TransformDirection direction=ForwardTransform, const bool handle180Crossover=false) const
Transform a QgsRectangle to the dest Coordinate system If the direction is ForwardTransform then coor...
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:211
void setCrsTransformEnabled(bool enabled)
sets whether to use projections for this layer set
QDomNode at(int index) const
QString toProj4() const
Returns a Proj4 string representation of this CRS.
void writeXML(QDomNode &theNode, QDomDocument &theDoc)