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