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