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