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