QGIS API Documentation  2.14.11-Essen
qgscomposermap.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposermap.cpp
3  -------------------
4  begin : January 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : blazek@itc.it
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgscomposermap.h"
19 #include "qgscomposermapgrid.h"
20 #include "qgscomposermapoverview.h"
21 #include "qgscomposition.h"
22 #include "qgscomposerutils.h"
23 #include "qgslogger.h"
24 #include "qgsmaprenderer.h"
26 #include "qgsmaplayerregistry.h"
28 #include "qgsmaptopixel.h"
29 #include "qgsproject.h"
30 #include "qgsrasterlayer.h"
31 #include "qgsrendercontext.h"
32 #include "qgsscalecalculator.h"
33 #include "qgsvectorlayer.h"
34 #include "qgspallabeling.h"
35 #include "qgsexpression.h"
37 #include "qgsannotation.h"
38 
39 #include "qgslabel.h"
40 #include "qgslabelattributes.h"
41 #include "qgssymbollayerv2utils.h" //for pointOnLineWithDistance
42 
43 #include <QGraphicsScene>
44 #include <QGraphicsView>
45 #include <QPainter>
46 #include <QSettings>
47 #include <cmath>
48 
49 QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
50  : QgsComposerItem( x, y, width, height, composition )
51  , mGridStack( nullptr )
52  , mOverviewStack( nullptr )
53  , mMapRotation( 0 )
54  , mEvaluatedMapRotation( 0 )
55  , mKeepLayerSet( false )
56  , mKeepLayerStyles( false )
57  , mUpdatesEnabled( true )
58  , mMapCanvas( nullptr )
59  , mDrawCanvasItems( true )
60  , mAtlasDriven( false )
61  , mAtlasScalingMode( Auto )
62  , mAtlasMargin( 0.10 )
63 {
65 
66  mId = 0;
67  assignFreeId();
68 
69  mPreviewMode = QgsComposerMap::Rectangle;
70  mCurrentRectangle = rect();
71 
72  // Cache
73  mCacheUpdated = false;
74  mDrawing = false;
75 
76  //Offset
77  mXOffset = 0.0;
78  mYOffset = 0.0;
79 
80  //get the color for map canvas background and set map background color accordingly
81  int bgRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 );
82  int bgGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 );
83  int bgBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 );
84  setBackgroundColor( QColor( bgRedInt, bgGreenInt, bgBlueInt ) );
85 
86  //calculate mExtent based on width/height ratio and map canvas extent
87  mExtent = mComposition->mapSettings().visibleExtent();
88 
89  init();
90 
91  setSceneRect( QRectF( x, y, width, height ) );
92 }
93 
95  : QgsComposerItem( 0, 0, 10, 10, composition )
96  , mGridStack( nullptr )
97  , mOverviewStack( nullptr )
98  , mMapRotation( 0 )
99  , mEvaluatedMapRotation( 0 )
100  , mKeepLayerSet( false )
101  , mKeepLayerStyles( false )
102  , mUpdatesEnabled( true )
103  , mMapCanvas( nullptr )
104  , mDrawCanvasItems( true )
105  , mAtlasDriven( false )
106  , mAtlasScalingMode( Auto )
107  , mAtlasMargin( 0.10 )
108 {
109  //Offset
110  mXOffset = 0.0;
111  mYOffset = 0.0;
112 
114  mId = mComposition->composerMapItems().size();
115  mPreviewMode = QgsComposerMap::Rectangle;
116  mCurrentRectangle = rect();
117 
118  init();
119  updateToolTip();
120 }
121 
122 void QgsComposerMap::init()
123 {
124  mGridStack = new QgsComposerMapGridStack( this );
125  mOverviewStack = new QgsComposerMapOverviewStack( this );
126  connectUpdateSlot();
127 
128  // data defined strings
129  mDataDefinedNames.insert( QgsComposerObject::MapRotation, QString( "dataDefinedMapRotation" ) );
130  mDataDefinedNames.insert( QgsComposerObject::MapScale, QString( "dataDefinedMapScale" ) );
131  mDataDefinedNames.insert( QgsComposerObject::MapXMin, QString( "dataDefinedMapXMin" ) );
132  mDataDefinedNames.insert( QgsComposerObject::MapYMin, QString( "dataDefinedMapYMin" ) );
133  mDataDefinedNames.insert( QgsComposerObject::MapXMax, QString( "dataDefinedMapXMax" ) );
134  mDataDefinedNames.insert( QgsComposerObject::MapYMax, QString( "dataDefinedMapYMax" ) );
135  mDataDefinedNames.insert( QgsComposerObject::MapAtlasMargin, QString( "dataDefinedMapAtlasMargin" ) );
136  mDataDefinedNames.insert( QgsComposerObject::MapLayers, QString( "dataDefinedMapLayers" ) );
137  mDataDefinedNames.insert( QgsComposerObject::MapStylePreset, QString( "dataDefinedMapStylePreset" ) );
138 }
139 
140 void QgsComposerMap::updateToolTip()
141 {
142  setToolTip( tr( "Map %1" ).arg( mId ) );
143 }
144 
145 void QgsComposerMap::adjustExtentToItemShape( double itemWidth, double itemHeight, QgsRectangle& extent ) const
146 {
147  double itemWidthHeightRatio = itemWidth / itemHeight;
148  double newWidthHeightRatio = extent.width() / extent.height();
149 
150  if ( itemWidthHeightRatio <= newWidthHeightRatio )
151  {
152  //enlarge height of new extent, ensuring the map center stays the same
153  double newHeight = extent.width() / itemWidthHeightRatio;
154  double deltaHeight = newHeight - extent.height();
155  extent.setYMinimum( extent.yMinimum() - deltaHeight / 2 );
156  extent.setYMaximum( extent.yMaximum() + deltaHeight / 2 );
157  }
158  else
159  {
160  //enlarge width of new extent, ensuring the map center stays the same
161  double newWidth = itemWidthHeightRatio * extent.height();
162  double deltaWidth = newWidth - extent.width();
163  extent.setXMinimum( extent.xMinimum() - deltaWidth / 2 );
164  extent.setXMaximum( extent.xMaximum() + deltaWidth / 2 );
165  }
166 }
167 
169 {
170  delete mOverviewStack;
171  delete mGridStack;
172 }
173 
174 /* This function is called by paint() and cache() to render the map. It does not override any functions
175 from QGraphicsItem. */
176 void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, QSizeF size, double dpi, double* forceWidthScale )
177 {
178  Q_UNUSED( forceWidthScale );
179 
180  if ( !painter )
181  {
182  return;
183  }
184  if ( qgsDoubleNear( size.width(), 0.0 ) || qgsDoubleNear( size.height(), 0.0 ) )
185  {
186  //don't attempt to draw if size is invalid
187  return;
188  }
189 
190  // render
191  QgsMapRendererCustomPainterJob job( mapSettings( extent, size, dpi ), painter );
192  // Render the map in this thread. This is done because of problems
193  // with printing to printer on Windows (printing to PDF is fine though).
194  // Raster images were not displayed - see #10599
195  job.renderSynchronously();
196 }
197 
198 QgsMapSettings QgsComposerMap::mapSettings( const QgsRectangle& extent, QSizeF size, int dpi ) const
199 {
200  const QgsMapSettings &ms = mComposition->mapSettings();
201 
203 
204  QgsMapSettings jobMapSettings;
205  jobMapSettings.setExtent( extent );
206  jobMapSettings.setOutputSize( size.toSize() );
207  jobMapSettings.setOutputDpi( dpi );
208  jobMapSettings.setMapUnits( ms.mapUnits() );
209  jobMapSettings.setBackgroundColor( Qt::transparent );
210  jobMapSettings.setOutputImageFormat( ms.outputImageFormat() );
211  jobMapSettings.setRotation( mEvaluatedMapRotation );
212 
213  //set layers to render
214  QStringList theLayerSet = layersToRender( expressionContext.data() );
215  if ( -1 != mCurrentExportLayer )
216  {
217  //exporting with separate layers (eg, to svg layers), so we only want to render a single map layer
218  const int layerIdx = mCurrentExportLayer - ( hasBackground() ? 1 : 0 );
219  theLayerSet =
220  ( layerIdx >= 0 && layerIdx < theLayerSet.length() )
221  ? QStringList( theLayerSet[ theLayerSet.length() - layerIdx - 1 ] )
222  : QStringList(); //exporting decorations such as map frame/grid/overview, so no map layers required
223  }
224  jobMapSettings.setLayers( theLayerSet );
225  jobMapSettings.setLayerStyleOverrides( layerStyleOverridesToRender( *expressionContext ) );
226  jobMapSettings.setDestinationCrs( ms.destinationCrs() );
227  jobMapSettings.setCrsTransformEnabled( ms.hasCrsTransformEnabled() );
228  jobMapSettings.setFlags( ms.flags() );
229  jobMapSettings.setFlag( QgsMapSettings::DrawSelection, false );
230 
233  {
234  //if outputing composer, disable optimisations like layer simplification
235  jobMapSettings.setFlag( QgsMapSettings::UseRenderingOptimization, false );
236  }
237 
239  jobMapSettings.setExpressionContext( *context );
240  delete context;
241 
242  // composer-specific overrides of flags
243  jobMapSettings.setFlag( QgsMapSettings::ForceVectorOutput ); // force vector output (no caching of marker images etc.)
244  jobMapSettings.setFlag( QgsMapSettings::DrawEditingInfo, false );
245  jobMapSettings.setFlag( QgsMapSettings::UseAdvancedEffects, mComposition->useAdvancedEffects() ); // respect the composition's useAdvancedEffects flag
246 
247  jobMapSettings.datumTransformStore() = ms.datumTransformStore();
248 
249  return jobMapSettings;
250 }
251 
253 {
254  if ( mPreviewMode == Rectangle )
255  {
256  return;
257  }
258 
259  if ( mDrawing )
260  {
261  return;
262  }
263 
264  mDrawing = true;
265 
266  double horizontalVScaleFactor = horizontalViewScaleFactor();
267  if ( horizontalVScaleFactor < 0 )
268  {
269  //make sure scale factor is positive
270  horizontalVScaleFactor = mLastValidViewScaleFactor > 0 ? mLastValidViewScaleFactor : 1;
271  }
272 
273  const QgsRectangle &ext = *currentMapExtent();
274  double widthMM = ext.width() * mapUnitsToMM();
275  double heightMM = ext.height() * mapUnitsToMM();
276 
277  int w = widthMM * horizontalVScaleFactor;
278  int h = heightMM * horizontalVScaleFactor;
279 
280  // limit size of image for better performance
281  if ( w > 5000 || h > 5000 )
282  {
283  if ( w > h )
284  {
285  w = 5000;
286  h = w * heightMM / widthMM;
287  }
288  else
289  {
290  h = 5000;
291  w = h * widthMM / heightMM;
292  }
293  }
294 
295  mCacheImage = QImage( w, h, QImage::Format_ARGB32 );
296 
297  // set DPI of the image
298  mCacheImage.setDotsPerMeterX( 1000 * w / widthMM );
299  mCacheImage.setDotsPerMeterY( 1000 * h / heightMM );
300 
301  if ( hasBackground() )
302  {
303  //Initially fill image with specified background color. This ensures that layers with blend modes will
304  //preview correctly
305  mCacheImage.fill( backgroundColor().rgba() );
306  }
307  else
308  {
309  //no background, but start with empty fill to avoid artifacts
310  mCacheImage.fill( QColor( 255, 255, 255, 0 ).rgba() );
311  }
312 
313  QPainter p( &mCacheImage );
314 
315  draw( &p, ext, QSizeF( w, h ), mCacheImage.logicalDpiX() );
316  p.end();
317  mCacheUpdated = true;
318 
319  mDrawing = false;
320 }
321 
322 void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
323 {
324  Q_UNUSED( pWidget );
325 
326  if ( !mComposition || !painter )
327  {
328  return;
329  }
330  if ( !shouldDrawItem() )
331  {
332  return;
333  }
334 
335  QRectF thisPaintRect = QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() );
336  painter->save();
337  painter->setClipRect( thisPaintRect );
338 
339  if ( mComposition->plotStyle() == QgsComposition::Preview && mPreviewMode == Rectangle )
340  {
341  // Fill with background color
342  drawBackground( painter );
343  QFont messageFont( "", 12 );
344  painter->setFont( messageFont );
345  painter->setPen( QColor( 0, 0, 0, 125 ) );
346  painter->drawText( thisPaintRect, tr( "Map will be printed here" ) );
347  }
349  {
350  //draw cached pixmap. This function does not call cache() any more because
351  //Qt 4.4.0 and 4.4.1 have problems with recursive paintings
352  //QgsComposerMap::cache() and QgsComposerMap::update() need to be called by
353  //client functions
354 
355  //Background color is already included in cached image, so no need to draw
356 
357  double imagePixelWidth = mCacheImage.width(); //how many pixels of the image are for the map extent?
358  double scale = rect().width() / imagePixelWidth;
359 
360  painter->save();
361 
362  painter->translate( mXOffset, mYOffset );
363  painter->scale( scale, scale );
364  painter->drawImage( 0, 0, mCacheImage );
365 
366  //restore rotation
367  painter->restore();
368 
369  //draw canvas items
370  drawCanvasItems( painter, itemStyle );
371  }
372  else if ( mComposition->plotStyle() == QgsComposition::Print ||
374  {
375  if ( mDrawing )
376  {
377  return;
378  }
379 
380  mDrawing = true;
381  QPaintDevice* thePaintDevice = painter->device();
382  if ( !thePaintDevice )
383  {
384  return;
385  }
386 
387  // Fill with background color
388  if ( shouldDrawPart( Background ) )
389  {
390  drawBackground( painter );
391  }
392 
393  QgsRectangle cExtent = *currentMapExtent();
394 
395  QSizeF theSize( cExtent.width() * mapUnitsToMM(), cExtent.height() * mapUnitsToMM() );
396 
397  painter->save();
398  painter->translate( mXOffset, mYOffset );
399 
400  double dotsPerMM = thePaintDevice->logicalDpiX() / 25.4;
401  theSize *= dotsPerMM; // output size will be in dots (pixels)
402  painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
403  draw( painter, cExtent, theSize, thePaintDevice->logicalDpiX() );
404 
405  //restore rotation
406  painter->restore();
407 
408  //draw canvas items
409  drawCanvasItems( painter, itemStyle );
410 
411  mDrawing = false;
412  }
413 
414  painter->setClipRect( thisPaintRect, Qt::NoClip );
415  if ( shouldDrawPart( OverviewMapExtent ) &&
416  ( mComposition->plotStyle() != QgsComposition::Preview || mPreviewMode != Rectangle ) )
417  {
418  mOverviewStack->drawItems( painter );
419  }
420  if ( shouldDrawPart( Grid ) &&
421  ( mComposition->plotStyle() != QgsComposition::Preview || mPreviewMode != Rectangle ) )
422  {
423  mGridStack->drawItems( painter );
424  }
425  if ( shouldDrawPart( Frame ) )
426  {
427  drawFrame( painter );
428  }
429  if ( isSelected() && shouldDrawPart( SelectionBoxes ) )
430  {
431  drawSelectionBoxes( painter );
432  }
433 
434  painter->restore();
435 }
436 
438 {
439  return
440  ( hasBackground() ? 1 : 0 )
441  + layersToRender().length()
442  + 1 // for grids, if they exist
443  + 1 // for overviews, if they exist
444  + ( hasFrame() ? 1 : 0 )
445  + ( isSelected() ? 1 : 0 )
446  ;
447 }
448 
449 bool QgsComposerMap::shouldDrawPart( PartType part ) const
450 {
451  if ( -1 == mCurrentExportLayer )
452  {
453  //all parts of the composer map are visible
454  return true;
455  }
456 
457  int idx = numberExportLayers();
458  if ( isSelected() )
459  {
460  --idx;
461  if ( SelectionBoxes == part )
462  {
463  return mCurrentExportLayer == idx;
464  }
465  }
466 
467  if ( hasFrame() )
468  {
469  --idx;
470  if ( Frame == part )
471  {
472  return mCurrentExportLayer == idx;
473  }
474  }
475  --idx;
476  if ( OverviewMapExtent == part )
477  {
478  return mCurrentExportLayer == idx;
479  }
480  --idx;
481  if ( Grid == part )
482  {
483  return mCurrentExportLayer == idx;
484  }
485  if ( hasBackground() )
486  {
487  if ( Background == part )
488  {
489  return mCurrentExportLayer == 0;
490  }
491  }
492 
493  return true; // for Layer
494 }
495 
497 {
498  mCacheUpdated = false;
499  cache();
501 }
502 
504 {
505  if ( mPreviewMode == Render )
506  {
508  }
509 }
510 
512 {
513  syncLayerSet();
515 }
516 
518 {
519  mCacheUpdated = u;
520 }
521 
523 {
525  return mComposition->mapRenderer();
527 }
528 
529 QStringList QgsComposerMap::layersToRender( const QgsExpressionContext* context ) const
530 {
531  const QgsExpressionContext* evalContext = context;
533  if ( !evalContext )
534  {
535  scopedContext.reset( createExpressionContext() );
536  evalContext = scopedContext.data();
537  }
538 
539  QStringList renderLayerSet;
540 
541  QVariant exprVal;
542  if ( dataDefinedEvaluate( QgsComposerObject::MapStylePreset, exprVal, *evalContext ) )
543  {
544  QString presetName = exprVal.toString();
545 
546  if ( QgsProject::instance()->visibilityPresetCollection()->hasPreset( presetName ) )
547  renderLayerSet = QgsProject::instance()->visibilityPresetCollection()->presetVisibleLayers( presetName );
548  }
549 
550  //use stored layer set or read current set from main canvas
551  if ( renderLayerSet.isEmpty() )
552  {
553  if ( mKeepLayerSet )
554  {
555  renderLayerSet = mLayerSet;
556  }
557  else
558  {
559  renderLayerSet = mComposition->mapSettings().layers();
560  }
561  }
562 
563  if ( dataDefinedEvaluate( QgsComposerObject::MapLayers, exprVal, *evalContext ) )
564  {
565  renderLayerSet.clear();
566 
567  QStringList layerNames = exprVal.toString().split( '|' );
568  //need to convert layer names to layer ids
569  Q_FOREACH ( const QString& name, layerNames )
570  {
572  Q_FOREACH ( QgsMapLayer* layer, matchingLayers )
573  {
574  renderLayerSet << layer->id();
575  }
576  }
577  }
578 
579  //remove atlas coverage layer if required
580  //TODO - move setting for hiding coverage layer to map item properties
582  {
584  {
585  //hiding coverage layer
586  int removeAt = renderLayerSet.indexOf( mComposition->atlasComposition().coverageLayer()->id() );
587  if ( removeAt != -1 )
588  {
589  renderLayerSet.removeAt( removeAt );
590  }
591  }
592  }
593 
594  return renderLayerSet;
595 }
596 
597 QMap<QString, QString> QgsComposerMap::layerStyleOverridesToRender( const QgsExpressionContext& context ) const
598 {
599  QVariant exprVal;
600  if ( dataDefinedEvaluate( QgsComposerObject::MapStylePreset, exprVal, context ) )
601  {
602  QString presetName = exprVal.toString();
603 
604  if ( QgsProject::instance()->visibilityPresetCollection()->hasPreset( presetName ) )
606 
607  }
608  return mLayerStyleOverrides;
609 }
610 
611 double QgsComposerMap::scale() const
612 {
613  QgsScaleCalculator calculator;
614  calculator.setMapUnits( mComposition->mapSettings().mapUnits() );
615  calculator.setDpi( 25.4 ); //QGraphicsView units are mm
616  return calculator.calculate( *currentMapExtent(), rect().width() );
617 }
618 
619 void QgsComposerMap::resize( double dx, double dy )
620 {
621  //setRect
622  QRectF currentRect = rect();
623  QRectF newSceneRect = QRectF( pos().x(), pos().y(), currentRect.width() + dx, currentRect.height() + dy );
624  setSceneRect( newSceneRect );
625  updateItem();
626 }
627 
628 void QgsComposerMap::moveContent( double dx, double dy )
629 {
630  if ( !mDrawing )
631  {
632  transformShift( dx, dy );
633  currentMapExtent()->setXMinimum( currentMapExtent()->xMinimum() + dx );
634  currentMapExtent()->setXMaximum( currentMapExtent()->xMaximum() + dx );
635  currentMapExtent()->setYMinimum( currentMapExtent()->yMinimum() + dy );
636  currentMapExtent()->setYMaximum( currentMapExtent()->yMaximum() + dy );
637 
638  //in case data defined extents are set, these override the calculated values
639  refreshMapExtents();
640 
641  cache();
642  update();
643  emit itemChanged();
644  emit extentChanged();
645  }
646 }
647 
648 void QgsComposerMap::zoomContent( int delta, double x, double y )
649 {
650  QSettings settings;
651 
652  //read zoom mode
653  QgsComposerItem::ZoomMode zoomMode = static_cast< QgsComposerItem::ZoomMode >( settings.value( "/qgis/wheel_action", 2 ).toInt() );
654  if ( zoomMode == QgsComposerItem::NoZoom )
655  {
656  //do nothing
657  return;
658  }
659 
660  double zoomFactor = settings.value( "/qgis/zoom_factor", 2.0 ).toDouble();
661  zoomFactor = delta > 0 ? zoomFactor : 1 / zoomFactor;
662 
663  zoomContent( zoomFactor, QPointF( x, y ), zoomMode );
664 }
665 
666 void QgsComposerMap::zoomContent( const double factor, const QPointF point, const ZoomMode mode )
667 {
668  if ( mDrawing )
669  {
670  return;
671  }
672 
673  if ( mode == QgsComposerItem::NoZoom )
674  {
675  //do nothing
676  return;
677  }
678 
679  //find out map coordinates of position
680  double mapX = currentMapExtent()->xMinimum() + ( point.x() / rect().width() ) * ( currentMapExtent()->xMaximum() - currentMapExtent()->xMinimum() );
681  double mapY = currentMapExtent()->yMinimum() + ( 1 - ( point.y() / rect().height() ) ) * ( currentMapExtent()->yMaximum() - currentMapExtent()->yMinimum() );
682 
683  //find out new center point
684  double centerX = ( currentMapExtent()->xMaximum() + currentMapExtent()->xMinimum() ) / 2;
685  double centerY = ( currentMapExtent()->yMaximum() + currentMapExtent()->yMinimum() ) / 2;
686 
687  if ( mode != QgsComposerItem::Zoom )
688  {
689  if ( mode == QgsComposerItem::ZoomRecenter )
690  {
691  centerX = mapX;
692  centerY = mapY;
693  }
694  else if ( mode == QgsComposerItem::ZoomToPoint )
695  {
696  centerX = mapX + ( centerX - mapX ) * ( 1.0 / factor );
697  centerY = mapY + ( centerY - mapY ) * ( 1.0 / factor );
698  }
699  }
700 
701  double newIntervalX, newIntervalY;
702 
703  if ( factor > 0 )
704  {
705  newIntervalX = ( currentMapExtent()->xMaximum() - currentMapExtent()->xMinimum() ) / factor;
706  newIntervalY = ( currentMapExtent()->yMaximum() - currentMapExtent()->yMinimum() ) / factor;
707  }
708  else //no need to zoom
709  {
710  return;
711  }
712 
713  currentMapExtent()->setXMaximum( centerX + newIntervalX / 2 );
714  currentMapExtent()->setXMinimum( centerX - newIntervalX / 2 );
715  currentMapExtent()->setYMaximum( centerY + newIntervalY / 2 );
716  currentMapExtent()->setYMinimum( centerY - newIntervalY / 2 );
717 
718  if ( mAtlasDriven && mAtlasScalingMode == Fixed && mComposition->atlasMode() != QgsComposition::AtlasOff )
719  {
720  //if map is atlas controlled and set to fixed scaling mode, then scale changes should be treated as permanant
721  //and also apply to the map's original extent (see #9602)
722  //we can't use the scaleRatio calculated earlier, as the scale can vary depending on extent for geographic coordinate systems
723  QgsScaleCalculator calculator;
724  calculator.setMapUnits( mComposition->mapSettings().mapUnits() );
725  calculator.setDpi( 25.4 ); //QGraphicsView units are mm
726  double scaleRatio = scale() / calculator.calculate( mExtent, rect().width() );
727  mExtent.scale( scaleRatio );
728  }
729 
730  //recalculate data defined scale and extents, since that may override zoom
731  refreshMapExtents();
732 
733  cache();
734  update();
735  emit itemChanged();
736  emit extentChanged();
737 }
738 
739 void QgsComposerMap::setSceneRect( const QRectF& rectangle )
740 {
741  double w = rectangle.width();
742  double h = rectangle.height();
743  //prepareGeometryChange();
744 
745  QgsComposerItem::setSceneRect( rectangle );
746 
747  //QGraphicsRectItem::update();
748  double newHeight = mExtent.width() * h / w;
749  mExtent = QgsRectangle( mExtent.xMinimum(), mExtent.yMinimum(), mExtent.xMaximum(), mExtent.yMinimum() + newHeight );
750 
751  //recalculate data defined scale and extents
752  refreshMapExtents();
753  mCacheUpdated = false;
754 
756  update();
757  emit itemChanged();
758  emit extentChanged();
759 }
760 
762 {
763  if ( *currentMapExtent() == extent )
764  {
765  return;
766  }
768 
769  //recalculate data defined scale and extents, since that may override extent
770  refreshMapExtents();
771 
772  //adjust height
773  QRectF currentRect = rect();
774 
775  double newHeight = currentRect.width() * currentMapExtent()->height() / currentMapExtent()->width();
776 
777  setSceneRect( QRectF( pos().x(), pos().y(), currentRect.width(), newHeight ) );
778  updateItem();
779 }
780 
782 {
783  QgsRectangle newExtent = extent;
784  //Make sure the width/height ratio is the same as the current composer map extent.
785  //This is to keep the map item frame size fixed
786  double currentWidthHeightRatio = currentMapExtent()->width() / currentMapExtent()->height();
787  double newWidthHeightRatio = newExtent.width() / newExtent.height();
788 
789  if ( currentWidthHeightRatio < newWidthHeightRatio )
790  {
791  //enlarge height of new extent, ensuring the map center stays the same
792  double newHeight = newExtent.width() / currentWidthHeightRatio;
793  double deltaHeight = newHeight - newExtent.height();
794  newExtent.setYMinimum( newExtent.yMinimum() - deltaHeight / 2 );
795  newExtent.setYMaximum( newExtent.yMaximum() + deltaHeight / 2 );
796  }
797  else
798  {
799  //enlarge width of new extent, ensuring the map center stays the same
800  double newWidth = currentWidthHeightRatio * newExtent.height();
801  double deltaWidth = newWidth - newExtent.width();
802  newExtent.setXMinimum( newExtent.xMinimum() - deltaWidth / 2 );
803  newExtent.setXMaximum( newExtent.xMaximum() + deltaWidth / 2 );
804  }
805 
806  if ( *currentMapExtent() == newExtent )
807  {
808  return;
809  }
810  *currentMapExtent() = newExtent;
811 
812  //recalculate data defined scale and extents, since that may override extent
813  refreshMapExtents();
814 
815  mCacheUpdated = false;
816  updateItem();
817  emit itemChanged();
818  emit extentChanged();
819 }
820 
822 {
823  if ( mAtlasFeatureExtent != extent )
824  {
825  //don't adjust size of item, instead adjust size of bounds to fit
826  QgsRectangle newExtent = extent;
827 
828  //Make sure the width/height ratio is the same as the map item size
829  double currentWidthHeightRatio = rect().width() / rect().height();
830  double newWidthHeightRatio = newExtent.width() / newExtent.height();
831 
832  if ( currentWidthHeightRatio < newWidthHeightRatio )
833  {
834  //enlarge height of new extent, ensuring the map center stays the same
835  double newHeight = newExtent.width() / currentWidthHeightRatio;
836  double deltaHeight = newHeight - newExtent.height();
837  newExtent.setYMinimum( extent.yMinimum() - deltaHeight / 2 );
838  newExtent.setYMaximum( extent.yMaximum() + deltaHeight / 2 );
839  }
840  else if ( currentWidthHeightRatio >= newWidthHeightRatio )
841  {
842  //enlarge width of new extent, ensuring the map center stays the same
843  double newWidth = currentWidthHeightRatio * newExtent.height();
844  double deltaWidth = newWidth - newExtent.width();
845  newExtent.setXMinimum( extent.xMinimum() - deltaWidth / 2 );
846  newExtent.setXMaximum( extent.xMaximum() + deltaWidth / 2 );
847  }
848 
849  mAtlasFeatureExtent = newExtent;
850  }
851 
852  //recalculate data defined scale and extents, since that may override extents
853  refreshMapExtents();
854 
855  mCacheUpdated = false;
856  emit preparedForAtlas();
857  updateItem();
858  emit itemChanged();
859  emit extentChanged();
860 }
861 
863 {
864  //non-const version
865  if ( mAtlasDriven && mComposition->atlasMode() != QgsComposition::AtlasOff )
866  {
867  //if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
868  //return the current temporary atlas feature extent
869  return &mAtlasFeatureExtent;
870  }
871  else
872  {
873  //otherwise return permenant user set extent
874  return &mExtent;
875  }
876 }
877 
879 {
880  //const version
881  if ( mAtlasDriven && mComposition->atlasMode() != QgsComposition::AtlasOff )
882  {
883  //if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
884  //return the current temporary atlas feature extent
885  return &mAtlasFeatureExtent;
886  }
887  else
888  {
889  //otherwise return permenant user set extent
890  return &mExtent;
891  }
892 }
893 
894 void QgsComposerMap::setNewScale( double scaleDenominator, bool forceUpdate )
895 {
896  double currentScaleDenominator = scale();
897 
898  if ( qgsDoubleNear( scaleDenominator, currentScaleDenominator ) || qgsDoubleNear( scaleDenominator, 0.0 ) )
899  {
900  return;
901  }
902 
903  double scaleRatio = scaleDenominator / currentScaleDenominator;
904  currentMapExtent()->scale( scaleRatio );
905 
906  if ( mAtlasDriven && mAtlasScalingMode == Fixed && mComposition->atlasMode() != QgsComposition::AtlasOff )
907  {
908  //if map is atlas controlled and set to fixed scaling mode, then scale changes should be treated as permanant
909  //and also apply to the map's original extent (see #9602)
910  //we can't use the scaleRatio calculated earlier, as the scale can vary depending on extent for geographic coordinate systems
911  QgsScaleCalculator calculator;
912  calculator.setMapUnits( mComposition->mapSettings().mapUnits() );
913  calculator.setDpi( 25.4 ); //QGraphicsView units are mm
914  scaleRatio = scaleDenominator / calculator.calculate( mExtent, rect().width() );
915  mExtent.scale( scaleRatio );
916  }
917 
918  mCacheUpdated = false;
919  if ( forceUpdate )
920  {
921  cache();
922  update();
923  emit itemChanged();
924  }
925  emit extentChanged();
926 }
927 
929 {
930  mPreviewMode = m;
931  emit itemChanged();
932 }
933 
934 void QgsComposerMap::setOffset( double xOffset, double yOffset )
935 {
936  mXOffset = xOffset;
937  mYOffset = yOffset;
938 }
939 
941 {
942  //kept for api compatibility with QGIS 2.0
943  setMapRotation( r );
944 }
945 
947 {
948  mMapRotation = r;
949  mEvaluatedMapRotation = mMapRotation;
950  emit mapRotationChanged( r );
951  emit itemChanged();
952  update();
953 }
954 
956 {
957  return valueType == QgsComposerObject::EvaluatedValue ? mEvaluatedMapRotation : mMapRotation;
958 }
959 
960 void QgsComposerMap::refreshMapExtents( const QgsExpressionContext* context )
961 {
962  const QgsExpressionContext* evalContext = context;
964  if ( !evalContext )
965  {
966  scopedContext.reset( createExpressionContext() );
967  evalContext = scopedContext.data();
968  }
969 
970  //data defined map extents set?
971  QVariant exprVal;
972 
973  QgsRectangle newExtent = *currentMapExtent();
974  bool useDdXMin = false;
975  bool useDdXMax = false;
976  bool useDdYMin = false;
977  bool useDdYMax = false;
978  double minXD = 0;
979  double minYD = 0;
980  double maxXD = 0;
981  double maxYD = 0;
982 
983  if ( dataDefinedEvaluate( QgsComposerObject::MapXMin, exprVal, *evalContext ) )
984  {
985  bool ok;
986  minXD = exprVal.toDouble( &ok );
987  QgsDebugMsg( QString( "exprVal Map XMin:%1" ).arg( minXD ) );
988  if ( ok && !exprVal.isNull() )
989  {
990  useDdXMin = true;
991  newExtent.setXMinimum( minXD );
992  }
993  }
994  if ( dataDefinedEvaluate( QgsComposerObject::MapYMin, exprVal, *evalContext ) )
995  {
996  bool ok;
997  minYD = exprVal.toDouble( &ok );
998  QgsDebugMsg( QString( "exprVal Map YMin:%1" ).arg( minYD ) );
999  if ( ok && !exprVal.isNull() )
1000  {
1001  useDdYMin = true;
1002  newExtent.setYMinimum( minYD );
1003  }
1004  }
1005  if ( dataDefinedEvaluate( QgsComposerObject::MapXMax, exprVal, *evalContext ) )
1006  {
1007  bool ok;
1008  maxXD = exprVal.toDouble( &ok );
1009  QgsDebugMsg( QString( "exprVal Map XMax:%1" ).arg( maxXD ) );
1010  if ( ok && !exprVal.isNull() )
1011  {
1012  useDdXMax = true;
1013  newExtent.setXMaximum( maxXD );
1014  }
1015  }
1016  if ( dataDefinedEvaluate( QgsComposerObject::MapYMax, exprVal, *evalContext ) )
1017  {
1018  bool ok;
1019  maxYD = exprVal.toDouble( &ok );
1020  QgsDebugMsg( QString( "exprVal Map YMax:%1" ).arg( maxYD ) );
1021  if ( ok && !exprVal.isNull() )
1022  {
1023  useDdYMax = true;
1024  newExtent.setYMaximum( maxYD );
1025  }
1026  }
1027 
1028  if ( newExtent != *currentMapExtent() )
1029  {
1030  //calculate new extents to fit data defined extents
1031 
1032  //Make sure the width/height ratio is the same as in current map extent.
1033  //This is to keep the map item frame and the page layout fixed
1034  double currentWidthHeightRatio = currentMapExtent()->width() / currentMapExtent()->height();
1035  double newWidthHeightRatio = newExtent.width() / newExtent.height();
1036 
1037  if ( currentWidthHeightRatio < newWidthHeightRatio )
1038  {
1039  //enlarge height of new extent, ensuring the map center stays the same
1040  double newHeight = newExtent.width() / currentWidthHeightRatio;
1041  double deltaHeight = newHeight - newExtent.height();
1042  newExtent.setYMinimum( newExtent.yMinimum() - deltaHeight / 2 );
1043  newExtent.setYMaximum( newExtent.yMaximum() + deltaHeight / 2 );
1044  }
1045  else
1046  {
1047  //enlarge width of new extent, ensuring the map center stays the same
1048  double newWidth = currentWidthHeightRatio * newExtent.height();
1049  double deltaWidth = newWidth - newExtent.width();
1050  newExtent.setXMinimum( newExtent.xMinimum() - deltaWidth / 2 );
1051  newExtent.setXMaximum( newExtent.xMaximum() + deltaWidth / 2 );
1052  }
1053 
1054  *currentMapExtent() = newExtent;
1055  }
1056 
1057  //now refresh scale, as this potentially overrides extents
1058 
1059  //data defined map scale set?
1060  if ( dataDefinedEvaluate( QgsComposerObject::MapScale, exprVal, *evalContext ) )
1061  {
1062  bool ok;
1063  double scaleD = exprVal.toDouble( &ok );
1064  QgsDebugMsg( QString( "exprVal Map Scale:%1" ).arg( scaleD ) );
1065  if ( ok && !exprVal.isNull() )
1066  {
1067  setNewScale( scaleD, false );
1068  newExtent = *currentMapExtent();
1069  }
1070  }
1071 
1072  if ( useDdXMax || useDdXMin || useDdYMax || useDdYMin )
1073  {
1074  //if only one of min/max was set for either x or y, then make sure our extent is locked on that value
1075  //as we can do this without altering the scale
1076  if ( useDdXMin && !useDdXMax )
1077  {
1078  double xMax = currentMapExtent()->xMaximum() - ( currentMapExtent()->xMinimum() - minXD );
1079  newExtent.setXMinimum( minXD );
1080  newExtent.setXMaximum( xMax );
1081  }
1082  else if ( !useDdXMin && useDdXMax )
1083  {
1084  double xMin = currentMapExtent()->xMinimum() - ( currentMapExtent()->xMaximum() - maxXD );
1085  newExtent.setXMinimum( xMin );
1086  newExtent.setXMaximum( maxXD );
1087  }
1088  if ( useDdYMin && !useDdYMax )
1089  {
1090  double yMax = currentMapExtent()->yMaximum() - ( currentMapExtent()->yMinimum() - minYD );
1091  newExtent.setYMinimum( minYD );
1092  newExtent.setYMaximum( yMax );
1093  }
1094  else if ( !useDdYMin && useDdYMax )
1095  {
1096  double yMin = currentMapExtent()->yMinimum() - ( currentMapExtent()->yMaximum() - maxYD );
1097  newExtent.setYMinimum( yMin );
1098  newExtent.setYMaximum( maxYD );
1099  }
1100 
1101  if ( newExtent != *currentMapExtent() )
1102  {
1103  *currentMapExtent() = newExtent;
1104  }
1105  }
1106 
1107  //lastly, map rotation overrides all
1108  double mapRotation = mMapRotation;
1109 
1110  //data defined map rotation set?
1111  if ( dataDefinedEvaluate( QgsComposerObject::MapRotation, exprVal, *evalContext ) )
1112  {
1113  bool ok;
1114  double rotationD = exprVal.toDouble( &ok );
1115  QgsDebugMsg( QString( "exprVal Map Rotation:%1" ).arg( rotationD ) );
1116  if ( ok && !exprVal.isNull() )
1117  {
1118  mapRotation = rotationD;
1119  }
1120  }
1121 
1122  if ( !qgsDoubleNear( mEvaluatedMapRotation, mapRotation ) )
1123  {
1124  mEvaluatedMapRotation = mapRotation;
1125  emit mapRotationChanged( mapRotation );
1126  }
1127 
1128 }
1129 
1131 {
1132  if ( !mUpdatesEnabled )
1133  {
1134  return;
1135  }
1136 
1137  if ( mPreviewMode != QgsComposerMap::Rectangle && !mCacheUpdated )
1138  {
1139  cache();
1140  }
1142 }
1143 
1145 {
1147 
1148  QStringList::const_iterator layer_it = layers.constBegin();
1149  QgsMapLayer* currentLayer = nullptr;
1150 
1151  for ( ; layer_it != layers.constEnd(); ++layer_it )
1152  {
1153  currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *layer_it );
1154  if ( currentLayer )
1155  {
1156  QgsRasterLayer* currentRasterLayer = qobject_cast<QgsRasterLayer *>( currentLayer );
1157  if ( currentRasterLayer )
1158  {
1159  const QgsRasterDataProvider* rasterProvider = nullptr;
1160  if (( rasterProvider = currentRasterLayer->dataProvider() ) )
1161  {
1162  if ( rasterProvider->name() == "wms" )
1163  {
1164  return true;
1165  }
1166  }
1167  }
1168  }
1169  }
1170  return false;
1171 }
1172 
1174 {
1175  //check easy things first
1176 
1177  //overviews
1178  if ( mOverviewStack->containsAdvancedEffects() )
1179  {
1180  return true;
1181  }
1182 
1183  //grids
1184  if ( mGridStack->containsAdvancedEffects() )
1185  {
1186  return true;
1187  }
1188 
1189  // check if map contains advanced effects like blend modes, or flattened layers for transparency
1190 
1192 
1193  QStringList::const_iterator layer_it = layers.constBegin();
1194  QgsMapLayer* currentLayer = nullptr;
1195 
1196  for ( ; layer_it != layers.constEnd(); ++layer_it )
1197  {
1198  currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *layer_it );
1199  if ( currentLayer )
1200  {
1201  if ( currentLayer->blendMode() != QPainter::CompositionMode_SourceOver )
1202  {
1203  return true;
1204  }
1205  // if vector layer, check labels and feature blend mode
1206  QgsVectorLayer* currentVectorLayer = qobject_cast<QgsVectorLayer *>( currentLayer );
1207  if ( currentVectorLayer )
1208  {
1209  if ( currentVectorLayer->layerTransparency() != 0 )
1210  {
1211  return true;
1212  }
1213  if ( currentVectorLayer->featureBlendMode() != QPainter::CompositionMode_SourceOver )
1214  {
1215  return true;
1216  }
1217  // check label blend modes
1218  if ( QgsPalLabeling::staticWillUseLayer( currentVectorLayer ) )
1219  {
1220  // Check all label blending properties
1221  QgsPalLayerSettings layerSettings = QgsPalLayerSettings::fromLayer( currentVectorLayer );
1222  if (( layerSettings.blendMode != QPainter::CompositionMode_SourceOver ) ||
1223  ( layerSettings.bufferDraw && layerSettings.bufferBlendMode != QPainter::CompositionMode_SourceOver ) ||
1224  ( layerSettings.shadowDraw && layerSettings.shadowBlendMode != QPainter::CompositionMode_SourceOver ) ||
1225  ( layerSettings.shapeDraw && layerSettings.shapeBlendMode != QPainter::CompositionMode_SourceOver ) )
1226  {
1227  return true;
1228  }
1229  }
1230  }
1231  }
1232  }
1233 
1234  return false;
1235 }
1236 
1237 void QgsComposerMap::connectUpdateSlot()
1238 {
1239  //connect signal from layer registry to update in case of new or deleted layers
1241  if ( layerRegistry )
1242  {
1243  connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( layersChanged() ) );
1244  connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( layersChanged() ) );
1245  }
1246 }
1247 
1249 {
1250  if ( elem.isNull() )
1251  {
1252  return false;
1253  }
1254 
1255  QDomElement composerMapElem = doc.createElement( "ComposerMap" );
1256  composerMapElem.setAttribute( "id", mId );
1257 
1258  //previewMode
1259  if ( mPreviewMode == Cache )
1260  {
1261  composerMapElem.setAttribute( "previewMode", "Cache" );
1262  }
1263  else if ( mPreviewMode == Render )
1264  {
1265  composerMapElem.setAttribute( "previewMode", "Render" );
1266  }
1267  else //rectangle
1268  {
1269  composerMapElem.setAttribute( "previewMode", "Rectangle" );
1270  }
1271 
1272  if ( mKeepLayerSet )
1273  {
1274  composerMapElem.setAttribute( "keepLayerSet", "true" );
1275  }
1276  else
1277  {
1278  composerMapElem.setAttribute( "keepLayerSet", "false" );
1279  }
1280 
1281  if ( mDrawCanvasItems )
1282  {
1283  composerMapElem.setAttribute( "drawCanvasItems", "true" );
1284  }
1285  else
1286  {
1287  composerMapElem.setAttribute( "drawCanvasItems", "false" );
1288  }
1289 
1290  //extent
1291  QDomElement extentElem = doc.createElement( "Extent" );
1292  extentElem.setAttribute( "xmin", qgsDoubleToString( mExtent.xMinimum() ) );
1293  extentElem.setAttribute( "xmax", qgsDoubleToString( mExtent.xMaximum() ) );
1294  extentElem.setAttribute( "ymin", qgsDoubleToString( mExtent.yMinimum() ) );
1295  extentElem.setAttribute( "ymax", qgsDoubleToString( mExtent.yMaximum() ) );
1296  composerMapElem.appendChild( extentElem );
1297 
1298  //map rotation
1299  composerMapElem.setAttribute( "mapRotation", QString::number( mMapRotation ) );
1300 
1301  //layer set
1302  QDomElement layerSetElem = doc.createElement( "LayerSet" );
1303  QStringList::const_iterator layerIt = mLayerSet.constBegin();
1304  for ( ; layerIt != mLayerSet.constEnd(); ++layerIt )
1305  {
1306  QDomElement layerElem = doc.createElement( "Layer" );
1307  QDomText layerIdText = doc.createTextNode( *layerIt );
1308  layerElem.appendChild( layerIdText );
1309  layerSetElem.appendChild( layerElem );
1310  }
1311  composerMapElem.appendChild( layerSetElem );
1312 
1313  // override styles
1314  if ( mKeepLayerStyles )
1315  {
1316  QDomElement stylesElem = doc.createElement( "LayerStyles" );
1317  QMap<QString, QString>::const_iterator styleIt = mLayerStyleOverrides.constBegin();
1318  for ( ; styleIt != mLayerStyleOverrides.constEnd(); ++styleIt )
1319  {
1320  QDomElement styleElem = doc.createElement( "LayerStyle" );
1321  styleElem.setAttribute( "layerid", styleIt.key() );
1322  QgsMapLayerStyle style( styleIt.value() );
1323  style.writeXml( styleElem );
1324  stylesElem.appendChild( styleElem );
1325  }
1326  composerMapElem.appendChild( stylesElem );
1327  }
1328 
1329  //write a dummy "Grid" element to prevent crashes on pre 2.5 versions (refs #10905)
1330  QDomElement gridElem = doc.createElement( "Grid" );
1331  composerMapElem.appendChild( gridElem );
1332 
1333  //grids
1334  mGridStack->writeXML( composerMapElem, doc );
1335 
1336  //overviews
1337  mOverviewStack->writeXML( composerMapElem, doc );
1338 
1339  //atlas
1340  QDomElement atlasElem = doc.createElement( "AtlasMap" );
1341  atlasElem.setAttribute( "atlasDriven", mAtlasDriven );
1342  atlasElem.setAttribute( "scalingMode", mAtlasScalingMode );
1343  atlasElem.setAttribute( "margin", qgsDoubleToString( mAtlasMargin ) );
1344  composerMapElem.appendChild( atlasElem );
1345 
1346  elem.appendChild( composerMapElem );
1347  return _writeXML( composerMapElem, doc );
1348 }
1349 
1350 bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& doc )
1351 {
1352  if ( itemElem.isNull() )
1353  {
1354  return false;
1355  }
1356 
1357  QString idRead = itemElem.attribute( "id", "not found" );
1358  if ( idRead != "not found" )
1359  {
1360  mId = idRead.toInt();
1361  updateToolTip();
1362  }
1363  mPreviewMode = Rectangle;
1364 
1365  //previewMode
1366  QString previewMode = itemElem.attribute( "previewMode" );
1367  if ( previewMode == "Cache" )
1368  {
1369  mPreviewMode = Cache;
1370  }
1371  else if ( previewMode == "Render" )
1372  {
1373  mPreviewMode = Render;
1374  }
1375  else
1376  {
1377  mPreviewMode = Rectangle;
1378  }
1379 
1380  //extent
1381  QDomNodeList extentNodeList = itemElem.elementsByTagName( "Extent" );
1382  if ( !extentNodeList.isEmpty() )
1383  {
1384  QDomElement extentElem = extentNodeList.at( 0 ).toElement();
1385  double xmin, xmax, ymin, ymax;
1386  xmin = extentElem.attribute( "xmin" ).toDouble();
1387  xmax = extentElem.attribute( "xmax" ).toDouble();
1388  ymin = extentElem.attribute( "ymin" ).toDouble();
1389  ymax = extentElem.attribute( "ymax" ).toDouble();
1390  setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
1391  }
1392 
1393  //map rotation
1394  if ( !qgsDoubleNear( itemElem.attribute( "mapRotation", "0" ).toDouble(), 0.0 ) )
1395  {
1396  mMapRotation = itemElem.attribute( "mapRotation", "0" ).toDouble();
1397  }
1398 
1399  //mKeepLayerSet flag
1400  QString keepLayerSetFlag = itemElem.attribute( "keepLayerSet" );
1401  if ( keepLayerSetFlag.compare( "true", Qt::CaseInsensitive ) == 0 )
1402  {
1403  mKeepLayerSet = true;
1404  }
1405  else
1406  {
1407  mKeepLayerSet = false;
1408  }
1409 
1410  QString drawCanvasItemsFlag = itemElem.attribute( "drawCanvasItems", "true" );
1411  if ( drawCanvasItemsFlag.compare( "true", Qt::CaseInsensitive ) == 0 )
1412  {
1413  mDrawCanvasItems = true;
1414  }
1415  else
1416  {
1417  mDrawCanvasItems = false;
1418  }
1419 
1420  mLayerStyleOverrides.clear();
1421 
1422  //mLayerSet
1423  QDomNodeList layerSetNodeList = itemElem.elementsByTagName( "LayerSet" );
1425  if ( !layerSetNodeList.isEmpty() )
1426  {
1427  QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
1428  QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( "Layer" );
1429  layerSet.reserve( layerIdNodeList.size() );
1430  for ( int i = 0; i < layerIdNodeList.size(); ++i )
1431  {
1432  const QDomElement& layerIdElement = layerIdNodeList.at( i ).toElement();
1433  layerSet << layerIdElement.text();
1434  }
1435  }
1436  mLayerSet = layerSet;
1437 
1438  // override styles
1439  QDomNodeList layerStylesNodeList = itemElem.elementsByTagName( "LayerStyles" );
1440  mKeepLayerStyles = !layerStylesNodeList.isEmpty();
1441  if ( mKeepLayerStyles )
1442  {
1443  QDomElement layerStylesElem = layerStylesNodeList.at( 0 ).toElement();
1444  QDomNodeList layerStyleNodeList = layerStylesElem.elementsByTagName( "LayerStyle" );
1445  for ( int i = 0; i < layerStyleNodeList.size(); ++i )
1446  {
1447  const QDomElement& layerStyleElement = layerStyleNodeList.at( i ).toElement();
1448  QString layerId = layerStyleElement.attribute( "layerid" );
1449  QgsMapLayerStyle style;
1450  style.readXml( layerStyleElement );
1451  mLayerStyleOverrides.insert( layerId, style.xmlData() );
1452  }
1453  }
1454 
1455  mDrawing = false;
1456  mNumCachedLayers = 0;
1457  mCacheUpdated = false;
1458 
1459  //overviews
1460  mOverviewStack->readXML( itemElem, doc );
1461 
1462  //grids
1463  mGridStack->readXML( itemElem, doc );
1464 
1465  //load grid / grid annotation in old xml format
1466  //only do this if the grid stack didn't load any grids, otherwise this will
1467  //be the dummy element created by QGIS >= 2.5 (refs #10905)
1468  QDomNodeList gridNodeList = itemElem.elementsByTagName( "Grid" );
1469  if ( mGridStack->size() == 0 && !gridNodeList.isEmpty() )
1470  {
1471  QDomElement gridElem = gridNodeList.at( 0 ).toElement();
1472  QgsComposerMapGrid* mapGrid = new QgsComposerMapGrid( tr( "Grid %1" ).arg( 1 ), this );
1473  mapGrid->setEnabled( gridElem.attribute( "show", "0" ) != "0" );
1474  mapGrid->setStyle( QgsComposerMapGrid::GridStyle( gridElem.attribute( "gridStyle", "0" ).toInt() ) );
1475  mapGrid->setIntervalX( gridElem.attribute( "intervalX", "0" ).toDouble() );
1476  mapGrid->setIntervalY( gridElem.attribute( "intervalY", "0" ).toDouble() );
1477  mapGrid->setOffsetX( gridElem.attribute( "offsetX", "0" ).toDouble() );
1478  mapGrid->setOffsetY( gridElem.attribute( "offsetY", "0" ).toDouble() );
1479  mapGrid->setCrossLength( gridElem.attribute( "crossLength", "3" ).toDouble() );
1480  mapGrid->setFrameStyle( static_cast< QgsComposerMapGrid::FrameStyle >( gridElem.attribute( "gridFrameStyle", "0" ).toInt() ) );
1481  mapGrid->setFrameWidth( gridElem.attribute( "gridFrameWidth", "2.0" ).toDouble() );
1482  mapGrid->setFramePenSize( gridElem.attribute( "gridFramePenThickness", "0.5" ).toDouble() );
1483  mapGrid->setFramePenColor( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "framePenColor", "0,0,0" ) ) );
1484  mapGrid->setFrameFillColor1( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "frameFillColor1", "255,255,255,255" ) ) );
1485  mapGrid->setFrameFillColor2( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "frameFillColor2", "0,0,0,255" ) ) );
1486  mapGrid->setBlendMode( QgsMapRenderer::getCompositionMode( static_cast< QgsMapRenderer::BlendMode >( itemElem.attribute( "gridBlendMode", "0" ).toUInt() ) ) );
1487  QDomElement gridSymbolElem = gridElem.firstChildElement( "symbol" );
1488  QgsLineSymbolV2* lineSymbol = nullptr;
1489  if ( gridSymbolElem.isNull() )
1490  {
1491  //old project file, read penWidth /penColorRed, penColorGreen, penColorBlue
1492  lineSymbol = QgsLineSymbolV2::createSimple( QgsStringMap() );
1493  lineSymbol->setWidth( gridElem.attribute( "penWidth", "0" ).toDouble() );
1494  lineSymbol->setColor( QColor( gridElem.attribute( "penColorRed", "0" ).toInt(),
1495  gridElem.attribute( "penColorGreen", "0" ).toInt(),
1496  gridElem.attribute( "penColorBlue", "0" ).toInt() ) );
1497  }
1498  else
1499  {
1500  lineSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsLineSymbolV2>( gridSymbolElem );
1501  }
1502  mapGrid->setLineSymbol( lineSymbol );
1503 
1504  //annotation
1505  QDomNodeList annotationNodeList = gridElem.elementsByTagName( "Annotation" );
1506  if ( !annotationNodeList.isEmpty() )
1507  {
1508  QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
1509  mapGrid->setAnnotationEnabled( annotationElem.attribute( "show", "0" ) != "0" );
1510  mapGrid->setAnnotationFormat( QgsComposerMapGrid::AnnotationFormat( annotationElem.attribute( "format", "0" ).toInt() ) );
1511  mapGrid->setAnnotationPosition( QgsComposerMapGrid::AnnotationPosition( annotationElem.attribute( "leftPosition", "0" ).toInt() ), QgsComposerMapGrid::Left );
1512  mapGrid->setAnnotationPosition( QgsComposerMapGrid::AnnotationPosition( annotationElem.attribute( "rightPosition", "0" ).toInt() ), QgsComposerMapGrid::Right );
1513  mapGrid->setAnnotationPosition( QgsComposerMapGrid::AnnotationPosition( annotationElem.attribute( "topPosition", "0" ).toInt() ), QgsComposerMapGrid::Top );
1514  mapGrid->setAnnotationPosition( QgsComposerMapGrid::AnnotationPosition( annotationElem.attribute( "bottomPosition", "0" ).toInt() ), QgsComposerMapGrid::Bottom );
1515  mapGrid->setAnnotationDirection( QgsComposerMapGrid::AnnotationDirection( annotationElem.attribute( "leftDirection", "0" ).toInt() ), QgsComposerMapGrid::Left );
1516  mapGrid->setAnnotationDirection( QgsComposerMapGrid::AnnotationDirection( annotationElem.attribute( "rightDirection", "0" ).toInt() ), QgsComposerMapGrid::Right );
1517  mapGrid->setAnnotationDirection( QgsComposerMapGrid::AnnotationDirection( annotationElem.attribute( "topDirection", "0" ).toInt() ), QgsComposerMapGrid::Top );
1518  mapGrid->setAnnotationDirection( QgsComposerMapGrid::AnnotationDirection( annotationElem.attribute( "bottomDirection", "0" ).toInt() ), QgsComposerMapGrid::Bottom );
1519  mapGrid->setAnnotationFrameDistance( annotationElem.attribute( "frameDistance", "0" ).toDouble() );
1520  QFont annotationFont;
1521  annotationFont.fromString( annotationElem.attribute( "font", "" ) );
1522  mapGrid->setAnnotationFont( annotationFont );
1523  mapGrid->setAnnotationFontColor( QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "fontColor", "0,0,0,255" ) ) );
1524 
1525  mapGrid->setAnnotationPrecision( annotationElem.attribute( "precision", "3" ).toInt() );
1526  }
1527  mGridStack->addGrid( mapGrid );
1528  }
1529 
1530  //load overview in old xml format
1531  QDomElement overviewFrameElem = itemElem.firstChildElement( "overviewFrame" );
1532  if ( !overviewFrameElem.isNull() )
1533  {
1534  QgsComposerMapOverview* mapOverview = new QgsComposerMapOverview( tr( "Overview %1" ).arg( mOverviewStack->size() + 1 ), this );
1535 
1536  mapOverview->setFrameMap( overviewFrameElem.attribute( "overviewFrameMap", "-1" ).toInt() );
1537  mapOverview->setBlendMode( QgsMapRenderer::getCompositionMode( static_cast< QgsMapRenderer::BlendMode >( overviewFrameElem.attribute( "overviewBlendMode", "0" ).toUInt() ) ) );
1538  mapOverview->setInverted( overviewFrameElem.attribute( "overviewInverted" ).compare( "true", Qt::CaseInsensitive ) == 0 );
1539  mapOverview->setCentered( overviewFrameElem.attribute( "overviewCentered" ).compare( "true", Qt::CaseInsensitive ) == 0 );
1540 
1541  QgsFillSymbolV2* fillSymbol = nullptr;
1542  QDomElement overviewFrameSymbolElem = overviewFrameElem.firstChildElement( "symbol" );
1543  if ( !overviewFrameSymbolElem.isNull() )
1544  {
1545  fillSymbol = QgsSymbolLayerV2Utils::loadSymbol<QgsFillSymbolV2>( overviewFrameSymbolElem );
1546  mapOverview->setFrameSymbol( fillSymbol );
1547  }
1548  mOverviewStack->addOverview( mapOverview );
1549  }
1550 
1551  //atlas
1552  QDomNodeList atlasNodeList = itemElem.elementsByTagName( "AtlasMap" );
1553  if ( !atlasNodeList.isEmpty() )
1554  {
1555  QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1556  mAtlasDriven = ( atlasElem.attribute( "atlasDriven", "0" ) != "0" );
1557  if ( atlasElem.hasAttribute( "fixedScale" ) ) // deprecated XML
1558  {
1559  mAtlasScalingMode = ( atlasElem.attribute( "fixedScale", "0" ) != "0" ) ? Fixed : Auto;
1560  }
1561  else if ( atlasElem.hasAttribute( "scalingMode" ) )
1562  {
1563  mAtlasScalingMode = static_cast<AtlasScalingMode>( atlasElem.attribute( "scalingMode" ).toInt() );
1564  }
1565  mAtlasMargin = atlasElem.attribute( "margin", "0.1" ).toDouble();
1566  }
1567 
1568  //restore general composer item properties
1569  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
1570  if ( !composerItemList.isEmpty() )
1571  {
1572  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
1573 
1574  if ( !qgsDoubleNear( composerItemElem.attribute( "rotation", "0" ).toDouble(), 0.0 ) )
1575  {
1576  //in versions prior to 2.1 map rotation was stored in the rotation attribute
1577  mMapRotation = composerItemElem.attribute( "rotation", "0" ).toDouble();
1578  }
1579 
1580  _readXML( composerItemElem, doc );
1581  }
1582 
1584  emit itemChanged();
1585  return true;
1586 }
1587 
1589 {
1590  mLayerSet = mComposition->mapSettings().layers();
1591 
1592  if ( mKeepLayerStyles )
1593  {
1594  // also store styles associated with the layers
1596  }
1597 }
1598 
1599 
1601 {
1602  if ( overrides == mLayerStyleOverrides )
1603  return;
1604 
1605  mLayerStyleOverrides = overrides;
1606  emit layerStyleOverridesChanged(); // associated legends may listen to this
1607 }
1608 
1609 
1611 {
1612  mLayerStyleOverrides.clear();
1613  Q_FOREACH ( const QString& layerID, mLayerSet )
1614  {
1615  if ( QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( layerID ) )
1616  {
1617  QgsMapLayerStyle style;
1618  style.readFromLayer( layer );
1619  mLayerStyleOverrides.insert( layerID, style.xmlData() );
1620  }
1621  }
1622 }
1623 
1624 void QgsComposerMap::syncLayerSet()
1625 {
1626  if ( mLayerSet.size() < 1 )
1627  {
1628  return;
1629  }
1630 
1631  //if layer set is fixed, do a lookup in the layer registry to also find the non-visible layers
1632  QStringList currentLayerSet;
1633  if ( mKeepLayerSet )
1634  {
1635  currentLayerSet = QgsMapLayerRegistry::instance()->mapLayers().uniqueKeys();
1636  }
1637  else //only consider layers visible in the map
1638  {
1639  currentLayerSet = mComposition->mapSettings().layers();
1640  }
1641 
1642  for ( int i = mLayerSet.size() - 1; i >= 0; --i )
1643  {
1644  if ( !currentLayerSet.contains( mLayerSet.at( i ) ) )
1645  {
1646  mLayerStyleOverrides.remove( mLayerSet.at( i ) );
1647  mLayerSet.removeAt( i );
1648  }
1649  }
1650 }
1651 
1653 {
1654  if ( mGridStack->size() < 1 )
1655  {
1656  QgsComposerMapGrid* grid = new QgsComposerMapGrid( tr( "Grid %1" ).arg( 1 ), this );
1657  mGridStack->addGrid( grid );
1658  }
1659  return mGridStack->grid( 0 );
1660 }
1661 
1662 const QgsComposerMapGrid* QgsComposerMap::constFirstMapGrid() const
1663 {
1664  return const_cast<QgsComposerMap*>( this )->grid();
1665 }
1666 
1668 {
1669  QgsComposerMapGrid* g = grid();
1670  g->setStyle( QgsComposerMapGrid::GridStyle( style ) );
1671 }
1672 
1674 {
1675  const QgsComposerMapGrid* g = constFirstMapGrid();
1676  return static_cast< QgsComposerMap::GridStyle >( g->style() );
1677 }
1678 
1679 void QgsComposerMap::setGridIntervalX( double interval )
1680 {
1681  QgsComposerMapGrid* g = grid();
1682  g->setIntervalX( interval );
1683 }
1684 
1686 {
1687  const QgsComposerMapGrid* g = constFirstMapGrid();
1688  return g->intervalX();
1689 }
1690 
1691 void QgsComposerMap::setGridIntervalY( double interval )
1692 {
1693  QgsComposerMapGrid* g = grid();
1694  g->setIntervalY( interval );
1695 }
1696 
1698 {
1699  const QgsComposerMapGrid* g = constFirstMapGrid();
1700  return g->intervalY();
1701 }
1702 
1703 void QgsComposerMap::setGridOffsetX( double offset )
1704 {
1705  QgsComposerMapGrid* g = grid();
1706  g->setOffsetX( offset );
1707 }
1708 
1710 {
1711  const QgsComposerMapGrid* g = constFirstMapGrid();
1712  return g->offsetX();
1713 }
1714 
1715 void QgsComposerMap::setGridOffsetY( double offset )
1716 {
1717  QgsComposerMapGrid* g = grid();
1718  g->setOffsetY( offset );
1719 }
1720 
1722 {
1723  const QgsComposerMapGrid* g = constFirstMapGrid();
1724  return g->offsetY();
1725 }
1726 
1728 {
1729  QgsComposerMapGrid* g = grid();
1730  g->setGridLineWidth( w );
1731 }
1732 
1734 {
1735  QgsComposerMapGrid* g = grid();
1736  g->setGridLineColor( c );
1737 }
1738 
1740 {
1741  QgsComposerMapGrid* g = grid();
1742  g->setGridLineWidth( p.widthF() );
1743  g->setGridLineColor( p.color() );
1744 }
1745 
1747 {
1748  const QgsComposerMapGrid* g = constFirstMapGrid();
1749  QPen p;
1750  if ( g->lineSymbol() )
1751  {
1752  QgsLineSymbolV2* line = g->lineSymbol()->clone();
1753  if ( !line )
1754  {
1755  return p;
1756  }
1757  p.setWidthF( line->width() );
1758  p.setColor( line->color() );
1759  p.setCapStyle( Qt::FlatCap );
1760  delete line;
1761  }
1762  return p;
1763 }
1764 
1766 {
1767  QgsComposerMapGrid* g = grid();
1768  g->setAnnotationFont( f );
1769 }
1770 
1772 {
1773  const QgsComposerMapGrid* g = constFirstMapGrid();
1774  return g->annotationFont();
1775 }
1776 
1778 {
1779  QgsComposerMapGrid* g = grid();
1780  g->setAnnotationFontColor( c );
1781 }
1782 
1784 {
1785  const QgsComposerMapGrid* g = constFirstMapGrid();
1786  return g->annotationFontColor();
1787 }
1788 
1790 {
1791  QgsComposerMapGrid* g = grid();
1792  g->setAnnotationPrecision( p );
1793 }
1794 
1796 {
1797  const QgsComposerMapGrid* g = constFirstMapGrid();
1798  return g->annotationPrecision();
1799 }
1800 
1802 {
1803  QgsComposerMapGrid* g = grid();
1804  g->setAnnotationEnabled( show );
1805 }
1806 
1808 {
1809  const QgsComposerMapGrid* g = constFirstMapGrid();
1810  return g->annotationEnabled();
1811 }
1812 
1814 {
1815  QgsComposerMapGrid* g = grid();
1816  if ( p != QgsComposerMap::Disabled )
1817  {
1818  g->setAnnotationPosition( static_cast< QgsComposerMapGrid::AnnotationPosition >( p ), static_cast< QgsComposerMapGrid::BorderSide >( border ) );
1819  }
1820  else
1821  {
1822  g->setAnnotationDisplay( QgsComposerMapGrid::HideAll, static_cast< QgsComposerMapGrid::BorderSide >( border ) );
1823  }
1824 }
1825 
1827 {
1828  const QgsComposerMapGrid* g = constFirstMapGrid();
1829  return static_cast< QgsComposerMap::GridAnnotationPosition >( g->annotationPosition( static_cast< QgsComposerMapGrid::BorderSide >( border ) ) );
1830 }
1831 
1833 {
1834  QgsComposerMapGrid* g = grid();
1836 }
1837 
1839 {
1840  const QgsComposerMapGrid* g = constFirstMapGrid();
1841  return g->annotationFrameDistance();
1842 }
1843 
1845 {
1846  QgsComposerMapGrid* g = grid();
1847  //map grid direction to QgsComposerMapGrid direction (values are different)
1849  switch ( d )
1850  {
1852  gridDirection = QgsComposerMapGrid::Horizontal;
1853  break;
1855  gridDirection = QgsComposerMapGrid::Vertical;
1856  break;
1858  gridDirection = QgsComposerMapGrid::BoundaryDirection;
1859  break;
1860  default:
1861  gridDirection = QgsComposerMapGrid::Horizontal;
1862  }
1863  g->setAnnotationDirection( gridDirection, static_cast< QgsComposerMapGrid::BorderSide >( border ) );
1864 
1865 }
1866 
1868 {
1869  const QgsComposerMapGrid* g = constFirstMapGrid();
1870  return static_cast< QgsComposerMap::GridAnnotationDirection >( g->annotationDirection( static_cast< QgsComposerMapGrid::BorderSide >( border ) ) );
1871 }
1872 
1874 {
1875  QgsComposerMapGrid* g = grid();
1876  g->setAnnotationFormat( static_cast< QgsComposerMapGrid::AnnotationFormat >( f ) );
1877 }
1878 
1880 {
1881  const QgsComposerMapGrid* g = constFirstMapGrid();
1882  return static_cast< QgsComposerMap::GridAnnotationFormat >( g->annotationFormat() );
1883 }
1884 
1886 {
1887  QgsComposerMapGrid* g = grid();
1888  g->setFrameStyle( static_cast< QgsComposerMapGrid::FrameStyle >( style ) );
1889 }
1890 
1892 {
1893  const QgsComposerMapGrid* g = constFirstMapGrid();
1894  return static_cast< QgsComposerMap::GridFrameStyle >( g->frameStyle() );
1895 }
1896 
1898 {
1899  QgsComposerMapGrid* g = grid();
1900  g->setFrameWidth( w );
1901 }
1902 
1904 {
1905  const QgsComposerMapGrid* g = constFirstMapGrid();
1906  return g->frameWidth();
1907 }
1908 
1910 {
1911  QgsComposerMapGrid* g = grid();
1912  g->setFramePenSize( w );
1913 }
1914 
1916 {
1917  const QgsComposerMapGrid* g = constFirstMapGrid();
1918  return g->framePenSize();
1919 }
1920 
1922 {
1923  QgsComposerMapGrid* g = grid();
1924  g->setFramePenColor( c );
1925 }
1926 
1928 {
1929  const QgsComposerMapGrid* g = constFirstMapGrid();
1930  return g->framePenColor();
1931 }
1932 
1934 {
1935  QgsComposerMapGrid* g = grid();
1936  g->setFrameFillColor1( c );
1937 }
1938 
1940 {
1941  const QgsComposerMapGrid* g = constFirstMapGrid();
1942  return g->frameFillColor1();
1943 }
1944 
1946 {
1947  QgsComposerMapGrid* g = grid();
1948  g->setFrameFillColor2( c );
1949 }
1950 
1952 {
1953  const QgsComposerMapGrid* g = constFirstMapGrid();
1954  return g->frameFillColor2();
1955 }
1956 
1958 {
1959  QgsComposerMapGrid* g = grid();
1960  g->setCrossLength( l );
1961 }
1962 
1964 {
1965  const QgsComposerMapGrid* g = constFirstMapGrid();
1966  return g->crossLength();
1967 }
1968 
1970 {
1971  if ( mOverviewStack->size() < 1 )
1972  {
1973  QgsComposerMapOverview* overview = new QgsComposerMapOverview( tr( "Overview %1" ).arg( 1 ), this );
1974  mOverviewStack->addOverview( overview );
1975  }
1976  return mOverviewStack->overview( 0 );
1977 }
1978 
1979 const QgsComposerMapOverview *QgsComposerMap::constFirstMapOverview() const
1980 {
1981  return const_cast<QgsComposerMap*>( this )->overview();
1982 }
1983 
1984 void QgsComposerMap::setGridBlendMode( QPainter::CompositionMode blendMode )
1985 {
1986  QgsComposerMapGrid* g = grid();
1987  g->setBlendMode( blendMode );
1988 }
1989 
1990 QPainter::CompositionMode QgsComposerMap::gridBlendMode() const
1991 {
1992  const QgsComposerMapGrid* g = constFirstMapGrid();
1993  return g->blendMode();
1994 }
1995 
1997 {
1998  return mCurrentRectangle;
1999 }
2000 
2002 {
2003  QRectF rectangle = rect();
2004  double frameExtension = mFrame ? pen().widthF() / 2.0 : 0.0;
2005 
2006  double topExtension = 0.0;
2007  double rightExtension = 0.0;
2008  double bottomExtension = 0.0;
2009  double leftExtension = 0.0;
2010 
2011  if ( mGridStack )
2012  mGridStack->calculateMaxGridExtension( topExtension, rightExtension, bottomExtension, leftExtension );
2013 
2014  topExtension = qMax( topExtension, frameExtension );
2015  rightExtension = qMax( rightExtension, frameExtension );
2016  bottomExtension = qMax( bottomExtension, frameExtension );
2017  leftExtension = qMax( leftExtension, frameExtension );
2018 
2019  rectangle.setLeft( rectangle.left() - leftExtension );
2020  rectangle.setRight( rectangle.right() + rightExtension );
2021  rectangle.setTop( rectangle.top() - topExtension );
2022  rectangle.setBottom( rectangle.bottom() + bottomExtension );
2023  if ( rectangle != mCurrentRectangle )
2024  {
2026  mCurrentRectangle = rectangle;
2027  }
2028 }
2029 
2030 void QgsComposerMap::setFrameOutlineWidth( const double outlineWidth )
2031 {
2032  QgsComposerItem::setFrameOutlineWidth( outlineWidth );
2034 }
2035 
2036 QgsRectangle QgsComposerMap::transformedExtent() const
2037 {
2038  double dx = mXOffset;
2039  double dy = mYOffset;
2040  transformShift( dx, dy );
2041  return QgsRectangle( currentMapExtent()->xMinimum() - dx, currentMapExtent()->yMinimum() - dy, currentMapExtent()->xMaximum() - dx, currentMapExtent()->yMaximum() - dy );
2042 }
2043 
2045 {
2046  double dx = mXOffset;
2047  double dy = mYOffset;
2048  //qWarning("offset");
2049  //qWarning(QString::number(dx).toLocal8Bit().data());
2050  //qWarning(QString::number(dy).toLocal8Bit().data());
2051  transformShift( dx, dy );
2052  //qWarning("transformed:");
2053  //qWarning(QString::number(dx).toLocal8Bit().data());
2054  //qWarning(QString::number(dy).toLocal8Bit().data());
2056  poly.translate( -dx, -dy );
2057  return poly;
2058 }
2059 
2060 void QgsComposerMap::mapPolygon( const QgsRectangle& extent, QPolygonF& poly ) const
2061 {
2062  poly.clear();
2063  if ( qgsDoubleNear( mEvaluatedMapRotation, 0.0 ) )
2064  {
2065  poly << QPointF( extent.xMinimum(), extent.yMaximum() );
2066  poly << QPointF( extent.xMaximum(), extent.yMaximum() );
2067  poly << QPointF( extent.xMaximum(), extent.yMinimum() );
2068  poly << QPointF( extent.xMinimum(), extent.yMinimum() );
2069  //ensure polygon is closed by readding first point
2070  poly << QPointF( poly.at( 0 ) );
2071  return;
2072  }
2073 
2074  //there is rotation
2075  QgsPoint rotationPoint(( extent.xMaximum() + extent.xMinimum() ) / 2.0, ( extent.yMaximum() + extent.yMinimum() ) / 2.0 );
2076  double dx, dy; //x-, y- shift from rotation point to corner point
2077 
2078  //top left point
2079  dx = rotationPoint.x() - extent.xMinimum();
2080  dy = rotationPoint.y() - extent.yMaximum();
2081  QgsComposerUtils::rotate( mEvaluatedMapRotation, dx, dy );
2082  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2083 
2084  //top right point
2085  dx = rotationPoint.x() - extent.xMaximum();
2086  dy = rotationPoint.y() - extent.yMaximum();
2087  QgsComposerUtils::rotate( mEvaluatedMapRotation, dx, dy );
2088  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2089 
2090  //bottom right point
2091  dx = rotationPoint.x() - extent.xMaximum();
2092  dy = rotationPoint.y() - extent.yMinimum();
2093  QgsComposerUtils::rotate( mEvaluatedMapRotation, dx, dy );
2094  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2095 
2096  //bottom left point
2097  dx = rotationPoint.x() - extent.xMinimum();
2098  dy = rotationPoint.y() - extent.yMinimum();
2099  QgsComposerUtils::rotate( mEvaluatedMapRotation, dx, dy );
2100  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
2101 
2102  //ensure polygon is closed by readding first point
2103  poly << QPointF( poly.at( 0 ) );
2104 }
2105 
2107 {
2108  QPolygonF poly;
2109  mapPolygon( *currentMapExtent(), poly );
2110  return poly;
2111 }
2112 
2114 {
2115  if ( !QgsComposerItem::id().isEmpty() )
2116  {
2117  return QgsComposerItem::id();
2118  }
2119 
2120  return tr( "Map %1" ).arg( mId );
2121 }
2122 
2124 {
2125  QgsRectangle newExtent = *currentMapExtent();
2126  if ( qgsDoubleNear( mEvaluatedMapRotation, 0.0 ) )
2127  {
2128  extent = newExtent;
2129  }
2130  else
2131  {
2132  QPolygonF poly;
2133  mapPolygon( newExtent, poly );
2134  QRectF bRect = poly.boundingRect();
2135  extent.setXMinimum( bRect.left() );
2136  extent.setXMaximum( bRect.right() );
2137  extent.setYMinimum( bRect.top() );
2138  extent.setYMaximum( bRect.bottom() );
2139  }
2140 }
2141 
2143 {
2145 
2146  //Can't utilise QgsExpressionContextUtils::mapSettingsScope as we don't always
2147  //have a QgsMapSettings object available when the context is required, so we manually
2148  //add the same variables here
2149  QgsExpressionContextScope* scope = new QgsExpressionContextScope( tr( "Map Settings" ) );
2150 
2151  //use QgsComposerItem's id, not map item's ID, since that is user-definable
2153  scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_rotation", mMapRotation, true ) );
2154  scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_scale", scale(), true ) );
2155 
2157  scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_extent_width", extent.width(), true ) );
2158  scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_extent_height", extent.height(), true ) );
2159  QgsGeometry* centerPoint = QgsGeometry::fromPoint( extent.center() );
2160  scope->addVariable( QgsExpressionContextScope::StaticVariable( "map_extent_center", QVariant::fromValue( *centerPoint ), true ) );
2161  delete centerPoint;
2162 
2163  context->appendScope( scope );
2164 
2165  return context;
2166 }
2167 
2169 {
2170  double extentWidth = currentMapExtent()->width();
2171  if ( extentWidth <= 0 )
2172  {
2173  return 1;
2174  }
2175  return rect().width() / extentWidth;
2176 }
2177 
2179 {
2181  o->setFrameMap( mapId );
2182 }
2183 
2185 {
2186  const QgsComposerMapOverview* o = constFirstMapOverview();
2187  return o->frameMapId();
2188 }
2189 
2191 {
2192  const QgsExpressionContext* evalContext = context;
2194  if ( !evalContext )
2195  {
2196  scopedContext.reset( createExpressionContext() );
2197  evalContext = scopedContext.data();
2198  }
2199 
2200  //updates data defined properties and redraws item to match
2201  if ( property == QgsComposerObject::MapRotation || property == QgsComposerObject::MapScale ||
2202  property == QgsComposerObject::MapXMin || property == QgsComposerObject::MapYMin ||
2203  property == QgsComposerObject::MapXMax || property == QgsComposerObject::MapYMax ||
2204  property == QgsComposerObject::MapAtlasMargin ||
2205  property == QgsComposerObject::AllProperties )
2206  {
2207  QgsRectangle beforeExtent = *currentMapExtent();
2208  refreshMapExtents( evalContext );
2209  emit itemChanged();
2210  if ( *currentMapExtent() != beforeExtent )
2211  {
2212  emit extentChanged();
2213  }
2214  }
2215 
2216  //force redraw
2217  mCacheUpdated = false;
2218 
2219  QgsComposerItem::refreshDataDefinedProperty( property, evalContext );
2220 }
2221 
2223 {
2225  o->setFrameSymbol( symbol );
2226 }
2227 
2229 {
2231  return o->frameSymbol();
2232 }
2233 
2234 QPainter::CompositionMode QgsComposerMap::overviewBlendMode() const
2235 {
2236  const QgsComposerMapOverview* o = constFirstMapOverview();
2237  return o->blendMode();
2238 }
2239 
2240 void QgsComposerMap::setOverviewBlendMode( QPainter::CompositionMode blendMode )
2241 {
2243  o->setBlendMode( blendMode );
2244 }
2245 
2247 {
2248  const QgsComposerMapOverview* o = constFirstMapOverview();
2249  return o->inverted();
2250 }
2251 
2253 {
2255  o->setInverted( inverted );
2256 }
2257 
2259 {
2260  const QgsComposerMapOverview* o = constFirstMapOverview();
2261  return o->centered();
2262 }
2263 
2265 {
2267  o->setCentered( centered );
2268  //overviewExtentChanged();
2269 }
2270 
2272 {
2273  QgsComposerMapGrid* g = grid();
2274  g->setLineSymbol( symbol );
2275 }
2276 
2278 {
2279  QgsComposerMapGrid* g = grid();
2280  return g->lineSymbol();
2281 }
2282 
2284 {
2285  QgsComposerMapGrid* g = grid();
2286  g->setEnabled( enabled );
2287 }
2288 
2290 {
2291  const QgsComposerMapGrid* g = constFirstMapGrid();
2292  return g->enabled();
2293 }
2294 
2295 void QgsComposerMap::transformShift( double& xShift, double& yShift ) const
2296 {
2297  double mmToMapUnits = 1.0 / mapUnitsToMM();
2298  double dxScaled = xShift * mmToMapUnits;
2299  double dyScaled = - yShift * mmToMapUnits;
2300 
2301  QgsComposerUtils::rotate( mEvaluatedMapRotation, dxScaled, dyScaled );
2302 
2303  xShift = dxScaled;
2304  yShift = dyScaled;
2305 }
2306 
2308 {
2309  QPolygonF mapPoly = transformedMapPolygon();
2310  if ( mapPoly.size() < 1 )
2311  {
2312  return QPointF( 0, 0 );
2313  }
2314 
2315  QgsRectangle tExtent = transformedExtent();
2316  QgsPoint rotationPoint(( tExtent.xMaximum() + tExtent.xMinimum() ) / 2.0, ( tExtent.yMaximum() + tExtent.yMinimum() ) / 2.0 );
2317  double dx = mapCoords.x() - rotationPoint.x();
2318  double dy = mapCoords.y() - rotationPoint.y();
2319  QgsComposerUtils::rotate( -mEvaluatedMapRotation, dx, dy );
2320  QgsPoint backRotatedCoords( rotationPoint.x() + dx, rotationPoint.y() + dy );
2321 
2322  QgsRectangle unrotatedExtent = transformedExtent();
2323  double xItem = rect().width() * ( backRotatedCoords.x() - unrotatedExtent.xMinimum() ) / unrotatedExtent.width();
2324  double yItem = rect().height() * ( 1 - ( backRotatedCoords.y() - unrotatedExtent.yMinimum() ) / unrotatedExtent.height() );
2325  return QPointF( xItem, yItem );
2326 }
2327 
2329 {
2330 
2331 }
2332 
2333 void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
2334 {
2335  if ( !mMapCanvas || !mDrawCanvasItems )
2336  {
2337  return;
2338  }
2339 
2340  QList<QGraphicsItem*> itemList = mMapCanvas->items();
2341  if ( itemList.size() < 1 )
2342  {
2343  return;
2344  }
2345  QGraphicsItem* currentItem = nullptr;
2346 
2347  for ( int i = itemList.size() - 1; i >= 0; --i )
2348  {
2349  currentItem = itemList.at( i );
2350 
2351  const QgsAnnotation* annotation = dynamic_cast< const QgsAnnotation* >( currentItem );
2352  if ( !annotation )
2353  {
2354  continue;
2355  }
2356  drawCanvasItem( annotation, painter, itemStyle );
2357  }
2358 }
2359 
2360 void QgsComposerMap::drawCanvasItem( const QgsAnnotation* annotation, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
2361 {
2362  if ( !annotation || !annotation->showItem() )
2363  {
2364  return;
2365  }
2366 
2367  painter->save();
2368  painter->setRenderHint( QPainter::Antialiasing );
2369 
2370  double scaleFactor = annotation->scaleFactor();
2371 
2372  double itemX, itemY;
2373  if ( annotation->mapPositionFixed() )
2374  {
2375  QPointF mapPos = composerMapPosForItem( annotation );
2376  itemX = mapPos.x();
2377  itemY = mapPos.y();
2378  }
2379  else
2380  {
2381  itemX = annotation->relativePosition().x() * rect().width();
2382  itemY = annotation->relativePosition().y() * rect().height();
2383  }
2384 
2385  painter->translate( itemX, itemY );
2386  painter->scale( scaleFactor, scaleFactor );
2387 
2388  //a little trick to let the item know that the paint request comes from the composer
2389  const_cast< QgsAnnotation* >( annotation )->setItemData( 1, "composer" );
2390  const_cast< QgsAnnotation* >( annotation )->paint( painter, itemStyle, nullptr );
2391  const_cast< QgsAnnotation* >( annotation )->setItemData( 1, "" );
2392 
2393  painter->restore();
2394 }
2395 
2396 QPointF QgsComposerMap::composerMapPosForItem( const QgsAnnotation* annotation ) const
2397 {
2398  if ( !annotation )
2399  return QPointF( 0, 0 );
2400 
2401  double mapX = 0.0;
2402  double mapY = 0.0;
2403 
2404  mapX = annotation->mapPosition().x();
2405  mapY = annotation->mapPosition().y();
2406  QgsCoordinateReferenceSystem crs = annotation->mapPositionCrs();
2407 
2408  if ( crs != mComposition->mapSettings().destinationCrs() )
2409  {
2410  //need to reproject
2412  double z = 0.0;
2413  t.transformInPlace( mapX, mapY, z );
2414  }
2415 
2416  return mapToItemCoords( QPointF( mapX, mapY ) );
2417 }
2418 
2420 {
2421  if ( !mComposition )
2422  {
2423  return;
2424  }
2425 
2426  const QgsComposerMap* existingMap = mComposition->getComposerMapById( mId );
2427  if ( !existingMap )
2428  {
2429  return; //keep mId as it is still available
2430  }
2431 
2432  int maxId = -1;
2435  for ( ; mapIt != mapList.constEnd(); ++mapIt )
2436  {
2437  if (( *mapIt )->id() > maxId )
2438  {
2439  maxId = ( *mapIt )->id();
2440  }
2441  }
2442  mId = maxId + 1;
2443  updateToolTip();
2444 }
2445 
2446 bool QgsComposerMap::imageSizeConsideringRotation( double& width, double& height ) const
2447 {
2448  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2450  return QgsComposerItem::imageSizeConsideringRotation( width, height, mEvaluatedMapRotation );
2452 }
2453 
2454 bool QgsComposerMap::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const
2455 {
2456  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2458  return QgsComposerItem::cornerPointOnRotatedAndScaledRect( x, y, width, height, mEvaluatedMapRotation );
2460 }
2461 
2462 void QgsComposerMap::sizeChangedByRotation( double& width, double& height )
2463 {
2464  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2466  return QgsComposerItem::sizeChangedByRotation( width, height, mEvaluatedMapRotation );
2468 }
2469 
2471 {
2472  mAtlasDriven = enabled;
2473 
2474  if ( !enabled )
2475  {
2476  //if not enabling the atlas, we still need to refresh the map extents
2477  //so that data defined extents and scale are recalculated
2478  refreshMapExtents();
2479  }
2480 }
2481 
2483 {
2484  return mAtlasScalingMode == Fixed;
2485 }
2486 
2488 {
2489  // implicit : if set to false => auto scaling
2490  mAtlasScalingMode = fixed ? Fixed : Auto;
2491 }
2492 
2494 {
2495  if ( valueType == QgsComposerObject::EvaluatedValue )
2496  {
2497  //evaluate data defined atlas margin
2498 
2499  //start with user specified margin
2500  double margin = mAtlasMargin;
2501  QVariant exprVal;
2503  if ( dataDefinedEvaluate( QgsComposerObject::MapAtlasMargin, exprVal, *context.data() ) )
2504  {
2505  bool ok;
2506  double ddMargin = exprVal.toDouble( &ok );
2507  QgsDebugMsg( QString( "exprVal Map Atlas Margin:%1" ).arg( ddMargin ) );
2508  if ( ok && !exprVal.isNull() )
2509  {
2510  //divide by 100 to convert to 0 -> 1.0 range
2511  margin = ddMargin / 100;
2512  }
2513  }
2514  return margin;
2515  }
2516  else
2517  {
2518  return mAtlasMargin;
2519  }
2520 }
2521 
Q_DECL_DEPRECATED void setGridFrameWidth(double w)
Set grid frame width.
Q_DECL_DEPRECATED int overviewFrameMapId() const
Returns id of overview frame (or -1 if no overfiew frame)
double scale() const
Scale.
virtual QgsPoint mapPosition() const
Returns the map position of the annotation, if it is attached to a fixed map position.
Definition: qgsannotation.h:61
void setMapUnits(QGis::UnitType mapUnits)
Set the map units.
void setStyle(const GridStyle style)
Sets the grid style, which controls how the grid is drawn over the map&#39;s contents.
bool centered() const
Returns whether the extent of the map is forced to center on the overview.
Q_DECL_DEPRECATED QFont gridAnnotationFont() const
void preparedForAtlas()
Is emitted when the map has been prepared for atlas rendering, just before actual rendering...
void updateItem() override
Updates item, with the possibility to do custom update for subclasses.
void clear()
void addGrid(QgsComposerMapGrid *grid)
Adds a new map grid to the stack and takes ownership of the grid.
AtlasScalingMode
Scaling modes used for the serial rendering (atlas)
QDomNodeList elementsByTagName(const QString &tagname) const
QgsMapSettings mapSettings(const QgsRectangle &extent, QSizeF size, int dpi) const
Return map settings that would be used for drawing of the map.
Single variable definition for use within a QgsExpressionContextScope.
qreal x() const
qreal y() const
void setDestinationCrs(const QgsCoordinateReferenceSystem &crs)
sets destination coordinate reference system
QColor annotationFontColor() const
Gets the font color used for drawing grid annotations.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void calculateMaxGridExtension(double &top, double &right, double &bottom, double &left) const
Calculates the maximum distance grids within the stack extend beyond the QgsComposerMap&#39;s item rect...
Base class for all map layer types.
Definition: qgsmaplayer.h:49
void setDotsPerMeterX(int x)
void setDotsPerMeterY(int y)
QFont annotationFont() const
Gets the font used for drawing grid annotations.
Job implementation that renders everything sequentially using a custom painter.
double horizontalViewScaleFactor() const
Returns the zoom factor of the graphics view.
double mapUnitsToMM() const
Returns the conversion factor map units -> mm.
QgsPoint center() const
Center point of the rectangle.
Definition: qgsrectangle.h:217
const QgsLineSymbolV2 * lineSymbol() const
Gets the line symbol used for drawing grid lines.
void setAnnotationDirection(const AnnotationDirection direction, const BorderSide border)
Sets the direction for drawing frame annotations.
QColor frameFillColor2() const
Retrieves the second fill color for the grid frame.
const QgsComposerMap * getComposerMapById(const int id) const
Returns the composer map with specified id.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blending mode used for drawing the grid.
Q_DECL_DEPRECATED QgsLineSymbolV2 * gridLineSymbol()
double atlasMargin(const QgsComposerObject::PropertyValueType valueType=QgsComposerObject::EvaluatedValue)
Returns the margin size (percentage) used when the map is in atlas mode.
Q_DECL_DEPRECATED void setGridIntervalY(double interval)
Sets coordinate interval in y-direction for composergrid.
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the item&#39;s current state.
Q_DECL_DEPRECATED void setOverviewCentered(bool centered)
Set the overview&#39;s centering mode.
bool end()
double intervalY() const
Gets the interval between grid lines in the y-direction.
bool shouldDrawItem() const
Returns whether the item should be drawn in the current context.
void setLineSymbol(QgsLineSymbolV2 *symbol)
Sets the line symbol used for drawing grid lines.
bool drawCanvasItems() const
GridStyle
Grid drawing style.
QList< QGraphicsItem * > items() const
virtual QgsLineSymbolV2 * clone() const override
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the grid.
Q_DECL_DEPRECATED void setGridAnnotationFormat(GridAnnotationFormat f)
Q_DECL_DEPRECATED void setGridFrameFillColor1(const QColor &c)
Sets first fill color for grid zebra frame.
void setRenderHint(RenderHint hint, bool on)
void setOffsetY(const double offset)
Sets the offset for grid lines in the y-direction.
QDomNode appendChild(const QDomNode &newChild)
void setExpressionContext(const QgsExpressionContext &context)
Sets the expression context.
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:172
Q_DECL_DEPRECATED void setGridEnabled(bool enabled)
Enables a coordinate grid that is shown on top of this composermap.
void setFramePenSize(const double width)
Sets the width of the outline drawn in the grid frame.
void assignFreeId()
Sets mId to a number not yet used in the composition.
QString xmlData() const
Return XML content of the style.
QStringList layerSet() const
Getter for stored layer set that is used if mKeepLayerSet is true.
Q_DECL_DEPRECATED double gridFrameWidth() const
void setNewAtlasFeatureExtent(const QgsRectangle &extent)
Sets new Extent for the current atlas preview and changes width, height (and implicitely also scale)...
void readXml(const QDomElement &styleElement)
Read style configuration (for project file reading)
QString attribute(const QString &name, const QString &defValue) const
int length() const
void setOffset(double xOffset, double yOffset)
Sets offset values to shift image (useful for live updates when moving item content) ...
Q_DECL_DEPRECATED QgsMapRenderer * mapRenderer()
Returns pointer to map renderer of qgis map canvas.
#define QgsDebugMsg(str)
Definition: qgslogger.h:33
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
void setOutputDpi(int dpi)
Set DPI used for conversion between real world units (e.g. mm) and pixels.
void itemChanged()
Emitted when the item changes.
Q_DECL_DEPRECATED QColor gridFramePenColor() const
Get pen color for grid frame.
void setRight(qreal x)
QMap< QString, QString > presetStyleOverrides(const QString &name)
Get layer style overrides (for QgsMapSettings) of the visible layers for given preset.
void addOverview(QgsComposerMapOverview *overview)
Adds a new map overview to the stack and takes ownership of the overview.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
void reserve(int alloc)
Q_DECL_DEPRECATED void connectMapOverviewSignals()
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation...
QPainter::CompositionMode bufferBlendMode
QgsRectangle extent() const
ZoomMode
Modes for zooming item content.
A collection of grids which is drawn above the map content in a QgsComposerMap.
Q_DECL_DEPRECATED void setAnnotationFontColor(const QColor &c)
Sets font color for grid annotations.
Q_DECL_DEPRECATED bool gridEnabled() const
void scale(qreal sx, qreal sy)
void cache()
Create cache image.
const_iterator constBegin() const
Q_DECL_DEPRECATED GridAnnotationPosition gridAnnotationPosition(QgsComposerMap::Border border) const
const T & at(int i) const
Q_DECL_DEPRECATED void setGridStyle(GridStyle style)
Sets coordinate grid style to solid or cross.
QMap< QgsComposerObject::DataDefinedProperty, QString > mDataDefinedNames
Map of data defined properties for the item to string name to use when exporting item to xml...
A item that forms part of a map composition.
void scale(double scaleFactor, const QgsPoint *c=nullptr)
Scale the rectangle around its center point.
void removeAt(int i)
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:415
bool contains(const QString &str, Qt::CaseSensitivity cs) const
Border
Enum for different frame borders.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
void save()
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
const QgsDatumTransformStore & datumTransformStore() const
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
QGis::UnitType mapUnits() const
Get units of map&#39;s geographical coordinates - used for scale calculation.
virtual bool mapPositionFixed() const =0
Returns true if the annotation is attached to a fixed map position, or false if the annotation uses a...
void drawItems(QPainter *painter)
Draws the items from the stack on a specified painter.
QColor frameFillColor1() const
Retrieves the first fill color for the grid frame.
void mapRotationChanged(double newRotation)
Is emitted on rotation change to notify north arrow pictures.
static QgsPalLayerSettings fromLayer(QgsVectorLayer *layer)
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
double intervalX() const
Gets the interval between grid lines in the x-direction.
Q_DECL_DEPRECATED QColor gridFrameFillColor1() const
Get first fill color for grid zebra frame.
qreal top() const
QColor backgroundColor() const
Gets the background color for this item.
Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height, double rotation) const
Calculates corner point after rotation and scaling.
Q_DECL_DEPRECATED double annotationFrameDistance() const
virtual void drawFrame(QPainter *p)
Draw black frame around item.
void updateCachedImage()
Forces an update of the cached map image.
void setAnnotationFont(const QFont &font)
Sets the font used for drawing grid annotations.
Q_DECL_DEPRECATED QPen gridPen() const
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Set map of map layer style overrides (key: layer ID, value: style name) where a different style shoul...
Q_DECL_DEPRECATED const QgsMapRenderer * mapRenderer() const
A non GUI class for rendering a map layer set onto a QPainter.
AnnotationDirection
Direction of grid annotations.
bool _writeXML(QDomElement &itemElem, QDomDocument &doc) const
Writes parameter that are not subclass specific in document.
void setLayers(const QStringList &layers)
Set list of layer IDs for map rendering.
void clear()
Enable layer transparency and blending effects.
AnnotationPosition annotationPosition(const BorderSide border) const
Gets the position for the grid annotations on a specified side of the map frame.
virtual double scaleFactor() const =0
Returns a scaling factor which should be applied to painters before rendering the item...
QColor framePenColor() const
Retrieves the color of the outline drawn in the grid frame.
double toDouble(bool *ok) const
virtual QgsExpressionContext * createExpressionContext() const override
Creates an expression context relating to the item&#39;s current state.
Q_DECL_DEPRECATED bool overviewCentered() const
Returns true if the extent is forced to center on the overview.
void setGridLineColor(const QColor &color)
Sets color of grid lines.
double crossLength() const
Retrieves the length of the cross segments drawn for the grid.
Q_DECL_DEPRECATED GridAnnotationDirection gridAnnotationDirection(QgsComposerMap::Border border) const
QString tr(const char *sourceText, const char *disambiguation, int n)
QMap< QString, QString > QgsStringMap
Definition: qgis.h:392
void setAnnotationDisplay(const DisplayMode display, const BorderSide border)
Sets what types of grid annotations should be drawn for a specified side of the map frame...
QList< const QgsComposerMap * > composerMapItems() const
Returns pointers to all composer maps in the scene.
AnnotationFormat
Format for displaying grid annotations.
qreal left() const
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Definition: qgis.h:285
Q_DECL_DEPRECATED void zoomContent(int delta, double x, double y) override
Zoom content of map.
void addVariable(const QgsExpressionContextScope::StaticVariable &variable)
Adds a variable into the context scope.
void update(const QRectF &rect)
QgsComposition::AtlasMode atlasMode() const
Returns the current atlas mode of the composition.
DataDefinedProperty
Data defined properties for different item types.
Q_DECL_DEPRECATED void setGridPenColor(const QColor &c)
Sets the color of the grid pen.
virtual QString name() const =0
Return a provider name.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=nullptr) const
void setWidth(double width)
void setCrossLength(const double length)
Sets the length of the cross segments drawn for the grid.
void setLeft(qreal x)
int size() const
Vector graphics should not be cached and drawn as raster images.
double y() const
Get the y value of the point.
Definition: qgspoint.h:136
QgsMapLayer * mapLayer(const QString &theLayerId)
Retrieve a pointer to a loaded layer by id.
void setFlag(Flag flag, bool on=true)
Enable or disable a particular flag (other flags are not affected)
Q_DECL_DEPRECATED QColor annotationFontColor() const
Get font color for grid annotations.
An interface for annotation items which are drawn over a map.
Definition: qgsannotation.h:40
QgsComposition::PlotStyle plotStyle() const
Q_DECL_DEPRECATED void setGridAnnotationPrecision(int p)
Sets coordinate precision for grid annotations.
void reset(T *other)
Q_DECL_DEPRECATED QPainter::CompositionMode gridBlendMode() const
Returns the grid&#39;s blending mode.
Q_DECL_DEPRECATED GridFrameStyle gridFrameStyle() const
The QgsMapSettings class contains configuration for rendering of the map.
virtual bool enabled() const
Returns whether the item will be drawn.
bool _readXML(const QDomElement &itemElem, const QDomDocument &doc)
Reads parameter that are not subclass specific in document.
Q_DECL_DEPRECATED GridAnnotationFormat gridAnnotationFormat() const
static bool staticWillUseLayer(QgsVectorLayer *layer)
called to find out whether the layer is used for labeling
QDomElement toElement() const
void readFromLayer(QgsMapLayer *layer)
Store layer&#39;s active style information in the instance.
void zoomToExtent(const QgsRectangle &extent)
Zooms the map so that the specified extent is fully visible within the map item.
void setCapStyle(Qt::PenCapStyle style)
qreal bottom() const
bool isEmpty() const
bool containsAdvancedEffects() const
Returns whether any items within the stack contain advanced effects, such as blending modes...
void storeCurrentLayerSet()
Stores the current layer set of the qgis mapcanvas in mLayerSet.
virtual void setFrameOutlineWidth(const double outlineWidth) override
Sets frame outline width.
void setColor(const QColor &color)
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores the state of the item stack in a DOM node.
Stores style information (renderer, transparency, labeling, diagrams etc.) applicable to a map layer...
const char * name() const
QColor color() const
void clear()
Q_DECL_DEPRECATED bool showGridAnnotation() const
void setFont(const QFont &font)
QPointF pos() const
QString number(int n, int base)
qreal x() const
qreal y() const
void setOutputSize(QSize size)
Set the size of the resulting map image.
An individual overview which is drawn above the map content in a QgsComposerMap, and shows the extent...
QString id() const
Get this layer&#39;s unique ID, this ID is used to access this layer from map layer registry.
void setFrameSymbol(QgsFillSymbolV2 *symbol)
Sets the fill symbol used for drawing the overview extent.
double calculate(const QgsRectangle &mapExtent, int canvasWidth)
Calculate the scale denominator.
QgsFillSymbolV2 * frameSymbol()
Gets the fill symbol used for drawing the overview extent.
QVariant property(const char *name) const
void updateBoundingRect()
Updates the bounding rect of this item.
Q_DECL_DEPRECATED void setGridAnnotationFont(const QFont &f)
Sets font for grid annotations.
QString text() const
bool fromString(const QString &descrip)
int toInt(bool *ok) const
bool isNull() const
Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height) const
Calculates corner point after rotation and scaling.
void fill(uint pixelValue)
bool hasAttribute(const QString &name) const
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses.
virtual void drawSelectionBoxes(QPainter *p)
Draws additional graphics on selected items.
void setRotation(double degrees)
Set the rotation of the resulting map image Units are clockwise degrees.
static QgsLineSymbolV2 * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
QPainter::CompositionMode blendMode
friend class QgsComposerMapOverview
void setPen(const QColor &color)
void setNewScale(double scaleDenominator, bool forceUpdate=true)
Sets new scale and changes only mExtent.
int width() const
bool mFrame
True if item fram needs to be painted.
Whether vector selections should be shown in the rendered map.
void setAttribute(const QString &name, const QString &value)
bool isSelected() const
QSize toSize() const
void setMapUnits(QGis::UnitType u)
Set units of map&#39;s geographical coordinates - used for scale calculation.
double offsetY() const
Gets the offset for grid lines in the y-direction.
void layersChanged()
Called when layers are added or removed from the layer registry.
FrameStyle frameStyle() const
Gets the grid frame style.
double width() const
Width of the rectangle.
Definition: qgsrectangle.h:207
void setCacheUpdated(bool u=false)
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:177
bool useAdvancedEffects() const
Returns true if a composition should use advanced effects such as blend modes.
virtual void setEnabled(const bool enabled)
Controls whether the item will be drawn.
bool isEmpty() const
Q_DECL_DEPRECATED void setAnnotationFrameDistance(double d)
Sets distance between map frame and annotations.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void setToolTip(const QString &toolTip)
void setAnnotationFormat(const AnnotationFormat format)
Sets the format for drawing grid annotations.
bool readXML(const QDomElement &elem, const QDomDocument &doc) override
Sets the grid stack&#39;s state from a DOM document.
bool hideCoverage() const
Returns true if the atlas is set to hide the coverage layer.
bool containsWMSLayer() const
True if composer map renders a WMS layer.
Q_DECL_DEPRECATED GridStyle gridStyle() const
AnnotationPosition
Position for grid annotations.
const_iterator constEnd() const
double frameWidth() const
Gets the grid frame width.
void setCentered(const bool centered)
Sets whether the extent of the map is forced to center on the overview.
Q_DECL_DEPRECATED double gridIntervalY() const
Q_DECL_DEPRECATED bool atlasFixedScale() const
Returns true if the map uses a fixed scale when in atlas mode.
bool dataDefinedEvaluate(const QgsComposerObject::DataDefinedProperty property, QVariant &expressionValue, const QgsExpressionContext &context=QgsExpressionContext()) const
Evaluate a data defined property and return the calculated value.
QImage::Format outputImageFormat() const
format of internal QImage, default QImage::Format_ARGB32_Premultiplied
QPaintDevice * device() const
void setAnnotationEnabled(const bool enabled)
Sets whether annotations should be shown for the grid.
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties, const QgsExpressionContext *context=nullptr) override
Refreshes a data defined property for the item by reevaluating the property&#39;s value and redrawing the...
GridStyle style() const
Gets the grid&#39;s style, which controls how the grid is drawn over the map&#39;s contents.
void setNewExtent(const QgsRectangle &extent)
Sets new extent for the map.
void translate(qreal dx, qreal dy)
Q_DECL_DEPRECATED void setGridPen(const QPen &p)
Sets the pen to draw composer grid.
void setWidthF(qreal width)
Q_DECL_DEPRECATED void setGridFrameFillColor2(const QColor &c)
Sets second fill color for grid zebra frame.
Q_DECL_DEPRECATED void setGridIntervalX(double interval)
Sets coordinate interval in x-direction for composergrid.
void drawText(const QPointF &position, const QString &text)
bool hasBackground() const
Whether this item has a Background or not.
int layerTransparency() const
Returns the current transparency for the vector layer.
Q_DECL_DEPRECATED double gridOffsetY() const
Q_DECL_DEPRECATED bool imageSizeConsideringRotation(double &width, double &height) const
Calculates width and hight of the picture (in mm) such that it fits into the item frame with the give...
void moveContent(double dx, double dy) override
Move content of map.
An individual grid which is drawn above the map content in a QgsComposerMap.
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
QPainter::CompositionMode shapeBlendMode
AnnotationDirection annotationDirection(const BorderSide border) const
Gets the direction for drawing frame annotations.
void setOutputImageFormat(QImage::Format format)
sets format of internal QImage
Q_DECL_DEPRECATED void sizeChangedByRotation(double &width, double &height)
Calculates width / height of the bounding box of a rotated rectangle.
void setColor(const QColor &color)
Single scope for storing variables and functions for use within a QgsExpressionContext.
Q_DECL_DEPRECATED void setOverviewFrameMapSymbol(QgsFillSymbolV2 *symbol)
Q_DECL_DEPRECATED void setGridFramePenSize(double w)
Set grid frame pen thickness.
void setGridLineWidth(const double width)
Sets width of grid lines.
virtual QPointF relativePosition() const
Returns the relative position of the annotation, if it is not attached to a fixed map position...
Definition: qgsannotation.h:73
static QPainter::CompositionMode getCompositionMode(BlendMode blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode.
PreviewMode
Preview style.
A class to represent a point.
Definition: qgspoint.h:65
void setFrameWidth(const double width)
Sets the grid frame width.
bool annotationEnabled() const
Gets whether annotations are shown for the grid.
void setAnnotationFontColor(const QColor &color)
Sets the font color used for drawing grid annotations.
void prepareGeometryChange()
Graphics scene for map printing.
int annotationPrecision() const
Returns the coordinate precision for grid annotations.
QPainter::CompositionMode featureBlendMode() const
Returns the current blending mode for features.
This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a m...
const QgsMapSettings & mapSettings() const
Return setting of QGIS map canvas.
QList< QgsMapLayer * > mapLayersByName(const QString &layerName)
Retrieve a pointer to a loaded layer by name.
static QgsGeometry * fromPoint(const QgsPoint &point)
Creates a new geometry from a QgsPoint object.
Object representing map window.
Enable drawing of vertex markers for layers in editing mode.
int logicalDpiX() const
QDomText createTextNode(const QString &value)
T * data() const
static void rotate(const double angle, double &x, double &y)
Rotates a point / vector around the origin.
qreal right() const
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget) override
Reimplementation of QCanvasItem::paint - draw on canvas.
void renderModeUpdateCachedImage()
Updates the cached map image if the map is set to Render mode.
void draw(QPainter *painter, const QgsRectangle &extent, QSizeF size, double dpi, double *forceWidthScale=nullptr)
Draw to paint device.
void setFrameFillColor1(const QColor &color)
Sets the first fill color used for the grid frame.
void setFramePenColor(const QColor &color)
Sets the color of the outline drawn in the grid frame.
void setAnnotationPosition(const AnnotationPosition position, const BorderSide border)
Sets the position for the grid annotations on a specified side of the map frame.
virtual ~QgsComposerMap()
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:202
Q_DECL_DEPRECATED void setGridAnnotationDirection(GridAnnotationDirection d, QgsComposerMap::Border border)
bool readXML(const QDomElement &itemElem, const QDomDocument &doc) override
Sets state from Dom document.
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
QVariant fromValue(const T &value)
Q_DECL_DEPRECATED void setCrossLength(double l)
Sets length of the cross segments (if grid style is cross)
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:187
bool isNull() const
double annotationFrameDistance() const
Gets the distance between the map frame and annotations.
virtual void setFrameOutlineWidth(const double outlineWidth)
Sets frame outline width.
QPointF mapToItemCoords(QPointF mapCoords) const
Transforms map coordinates to item coordinates (considering rotation and move offset) ...
QgsComposerMapOverview * overview(const QString &overviewId) const
Returns a reference to an overview within the stack.
double offsetX() const
Gets the offset for grid lines in the x-direction.
void restore()
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:416
const Key key(const T &value) const
QgsComposition * mComposition
void layerStyleOverridesChanged()
Emitted when layer style overrides are changed...
void setBackgroundColor(const QColor &color)
Set the background color of the map.
const T & at(int i) const
QVariant value(const QString &key, const QVariant &defaultValue) const
AnnotationFormat annotationFormat() const
Gets the format for drawing grid annotations.
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties, const QgsExpressionContext *context=nullptr) override
virtual QgsCoordinateReferenceSystem mapPositionCrs() const
Returns the CRS of the map position, or an invalid CRS if the annotation does not have a fixed map po...
Definition: qgsannotation.h:66
QRectF boundingRect() const
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)
qreal width() const
void setClipRect(const QRectF &rectangle, Qt::ClipOperation operation)
int numberExportLayers() const override
Get the number of layers that this item requires for exporting as layers.
void setBackgroundColor(const QColor &backgroundColor)
Sets the background color for this item.
Q_DECL_DEPRECATED void setOverviewInverted(bool inverted)
Sets the overview&#39;s inversion mode.
int mCurrentExportLayer
The layer that needs to be exported.
void setFlags(const QgsMapSettings::Flags &flags)
Set combination of flags that will be used for rendering.
const QgsComposition * composition() const
Returns the composition the item is attached to.
void setBottom(qreal y)
virtual QString displayName() const override
Get item display name.
virtual bool showItem() const =0
Returns true if the annotation should be shown.
void writeXml(QDomElement &styleElement) const
Write style configuration (for project file writing)
PreviewMode previewMode() const
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:182
void setTop(qreal y)
virtual void drawBackground(QPainter *p)
Draw background.
bool inverted() const
Returns whether the overview frame is inverted, ie, whether the shaded area is drawn outside the exte...
QColor color() const
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Q_DECL_DEPRECATED void setShowGridAnnotation(bool show)
Sets flag if grid annotation should be shown.
static QgsProject * instance()
access to canonical QgsProject instance
Definition: qgsproject.cpp:381
QDomElement firstChildElement(const QString &tagName) const
void requestedExtent(QgsRectangle &extent) const
Calculates the extent to request and the yShift of the top-left point in case of rotation.
Q_DECL_DEPRECATED QColor gridFrameFillColor2() const
Get second fill color for grid zebra frame.
Class for storing a coordinate reference system (CRS)
void setExtent(const QgsRectangle &rect)
Set coordinates of the rectangle which should be rendered.
void setMapRotation(double r)
Sets rotation for the map - this does not affect the composer item shape, only the way the map is dra...
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
void setAnnotationPrecision(const int precision)
Sets the coordinate precision for grid annotations.
Q_DECL_DEPRECATED void setGridAnnotationPosition(GridAnnotationPosition p, QgsComposerMap::Border border)
void setIntervalY(const double interval)
Sets the interval between grid lines in the y-direction.
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
Class for doing transforms between two map coordinate systems.
QgsComposerMap(QgsComposition *composition, int x, int y, int width, int height)
Constructor.
qreal widthF() const
Flags flags() const
Return combination of flags used for rendering.
void translate(const QPointF &offset)
void setInverted(const bool inverted)
Sets whether the overview frame is inverted, ie, whether the shaded area is drawn outside the extent ...
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:192
int frameMapId() const
Returns id of source map.
Q_DECL_DEPRECATED void setAtlasFixedScale(bool fixed)
Set to true if the map should use a fixed scale when in atlas mode.
void setFrameMap(const int mapId)
Sets overview frame map.
void resize(double dx, double dy)
Resizes an item in x- and y direction (canvas coordinates)
void setSceneRect(const QRectF &rectangle) override
Sets new scene rectangle bounds and recalculates hight and extent.
Q_DECL_DEPRECATED void setRotation(double r) override
Sets rotation for the map - this does not affect the composer item shape, only the way the map is dra...
QgsVectorLayer * coverageLayer() const
Returns the coverage layer used for the atlas features.
qreal height() const
QgsAtlasComposition & atlasComposition()
Q_DECL_DEPRECATED double crossLength()
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:197
int indexOf(const QRegExp &rx, int from) const
double toDouble(bool *ok) const
static QColor decodeColor(const QString &str)
Q_DECL_DEPRECATED void setGridOffsetX(double offset)
Sets x-coordinate offset for composer grid.
Q_DECL_DEPRECATED bool overviewInverted() const
Returns true if the overview frame is inverted.
iterator insert(const Key &key, const T &value)
Enable vector simplification and other rendering optimizations.
QPainter::CompositionMode shadowBlendMode
QStringList presetVisibleLayers(const QString &name) const
Returns the list of layer IDs that should be visible for the specified preset.
QgsRasterDataProvider * dataProvider()
Returns the data provider.
Q_DECL_DEPRECATED QgsFillSymbolV2 * overviewFrameMapSymbol()
bool hasFrame() const
Whether this item has a frame or not.
bool containsAdvancedEffects() const
True if composer map contains layers with blend modes or flattened layers for vectors.
Q_DECL_DEPRECATED void setOverviewBlendMode(QPainter::CompositionMode blendMode)
Sets the overview&#39;s blending mode.
Q_DECL_DEPRECATED void setGridLineSymbol(QgsLineSymbolV2 *symbol)
void extentChanged()
double width() const
Q_DECL_DEPRECATED void setGridPenWidth(double w)
Sets width of grid pen.
int size() const
void setAtlasDriven(bool enabled)
Sets whether the map extent will follow the current atlas feature.
const_iterator constEnd() const
QDomElement createElement(const QString &tagName)
void setFrameFillColor2(const QColor &color)
Sets the second fill color used for the grid frame.
const_iterator constBegin() const
QStringList layers() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
void setLayerStyleOverrides(const QMap< QString, QString > &overrides)
Setter for stored overrides of styles for layers.
void setFrameStyle(const FrameStyle style)
Sets the grid frame style.
double mapRotation(QgsComposerObject::PropertyValueType valueType=QgsComposerObject::EvaluatedValue) const
Returns the rotation used for drawing the map within the composer item.
Q_DECL_DEPRECATED void setGridOffsetY(double offset)
Sets y-coordinate offset for composer grid.
qreal height() const
void setPreviewMode(PreviewMode m)
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QRectF boundingRect() const override
In case of annotations, the bounding rectangle can be larger than the map item rectangle.
void transformInPlace(double &x, double &y, double &z, TransformDirection direction=ForwardTransform) const
int size() const
QgsVisibilityPresetCollection * visibilityPresetCollection()
Returns pointer to the project&#39;s visibility preset collection.
bool writeXML(QDomElement &elem, QDomDocument &doc) const override
Stores state in Dom node.
Represents a vector layer which manages a vector based data sets.
void storeCurrentLayerStyles()
Stores the current layer styles into style overrides.
Q_DECL_DEPRECATED int gridAnnotationPrecision() const
int compare(const QString &other) const
Q_DECL_DEPRECATED void setGridFrameStyle(GridFrameStyle style)
Set grid frame style (NoGridFrame or Zebra)
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QString toString() const
QPainter::CompositionMode blendMode() const
Returns the item&#39;s composition blending mode.
Q_DECL_DEPRECATED QPainter::CompositionMode overviewBlendMode() const
Returns the overview&#39;s blending mode.
void renderSynchronously()
Render the map synchronously in this thread.
void setIntervalX(const double interval)
Sets the interval between grid lines in the x-direction.
QString id() const
Get item&#39;s id (which is not necessarly unique)
const QgsRectangle * currentMapExtent() const
Returns a pointer to the current map extent, which is either the original user specified extent or th...
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
QgsComposerMapGrid * grid(const QString &gridId) const
Returns a reference to a grid within the stack.
qreal width() const
QPolygonF transformedMapPolygon() const
Returns extent that considers rotation and shift with mOffsetX / mOffsetY.
Q_DECL_DEPRECATED double gridIntervalX() const
bool readXML(const QDomElement &elem, const QDomDocument &doc) override
Sets the overview stack&#39;s state from a DOM document.
void setOffsetX(const double offset)
Sets the offset for grid lines in the x-direction.
Q_DECL_DEPRECATED bool imageSizeConsideringRotation(double &width, double &height, double rotation) const
Calculates width and hight of the picture (in mm) such that it fits into the item frame with the give...
Q_DECL_DEPRECATED void setGridBlendMode(QPainter::CompositionMode blendMode)
Sets the grid&#39;s blending mode.
double x() const
Get the x value of the point.
Definition: qgspoint.h:128
Q_DECL_DEPRECATED void setOverviewFrameMap(int mapId)
Sets overview frame map.
void setBlendMode(const QPainter::CompositionMode blendMode)
Sets the blending mode used for drawing the overview.
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:167
double framePenSize() const
Retrieves the width of the outline drawn in the grid frame.
QPainter::CompositionMode blendMode() const
Retrieves the blending mode used for drawing the overview.
QgsComposerMapGrid * grid()
Returns the map item&#39;s first grid.
Q_DECL_DEPRECATED void setGridFramePenColor(const QColor &c)
Sets pen color for grid frame.
void setAnnotationFrameDistance(const double distance)
Sets the distance between the map frame and annotations.
Q_DECL_DEPRECATED void sizeChangedByRotation(double &width, double &height, double rotation)
Calculates width / height of the bounding box of a rotated rectangle.
QPainter::CompositionMode blendMode() const
Returns the current blending mode for a layer.
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:212
int size() const
Returns the number of items in the stack.
void setCrsTransformEnabled(bool enabled)
sets whether to use projections for this layer set
QDomNode at(int index) const
QRectF rect() const
const T value(const Key &key) const
Base class for raster data providers.
uint toUInt(bool *ok, int base) const
int remove(const Key &key)
Q_DECL_DEPRECATED double gridOffsetX() const
QList< Key > uniqueKeys() const
QgsComposerMapOverview * overview()
Returns the map item&#39;s first overview.
Q_DECL_DEPRECATED double gridFramePenSize() const
A collection of overviews which are drawn above the map content in a QgsComposerMap.