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