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 
869  {
870  bool ok;
871  double minXD = exprVal.toDouble( &ok );
872  QgsDebugMsg( QString( "exprVal Map XMin:%1" ).arg( minXD ) );
873  if ( ok )
874  {
875  newExtent.setXMinimum( minXD );
876  }
877  }
879  {
880  bool ok;
881  double minYD = exprVal.toDouble( &ok );
882  QgsDebugMsg( QString( "exprVal Map YMin:%1" ).arg( minYD ) );
883  if ( ok )
884  {
885  newExtent.setYMinimum( minYD );
886  }
887  }
889  {
890  bool ok;
891  double maxXD = exprVal.toDouble( &ok );
892  QgsDebugMsg( QString( "exprVal Map XMax:%1" ).arg( maxXD ) );
893  if ( ok )
894  {
895  newExtent.setXMaximum( maxXD );
896  }
897  }
899  {
900  bool ok;
901  double maxYD = exprVal.toDouble( &ok );
902  QgsDebugMsg( QString( "exprVal Map YMax:%1" ).arg( maxYD ) );
903  if ( ok )
904  {
905  newExtent.setYMaximum( maxYD );
906  }
907  }
908 
909  if ( newExtent != *currentMapExtent() )
910  {
911  //calculate new extents to fit data defined extents
912 
913  //Make sure the width/height ratio is the same as in current map extent.
914  //This is to keep the map item frame and the page layout fixed
915  double currentWidthHeightRatio = currentMapExtent()->width() / currentMapExtent()->height();
916  double newWidthHeightRatio = newExtent.width() / newExtent.height();
917 
918  if ( currentWidthHeightRatio < newWidthHeightRatio )
919  {
920  //enlarge height of new extent, ensuring the map center stays the same
921  double newHeight = newExtent.width() / currentWidthHeightRatio;
922  double deltaHeight = newHeight - newExtent.height();
923  newExtent.setYMinimum( newExtent.yMinimum() - deltaHeight / 2 );
924  newExtent.setYMaximum( newExtent.yMaximum() + deltaHeight / 2 );
925  }
926  else
927  {
928  //enlarge width of new extent, ensuring the map center stays the same
929  double newWidth = currentWidthHeightRatio * newExtent.height();
930  double deltaWidth = newWidth - newExtent.width();
931  newExtent.setXMinimum( newExtent.xMinimum() - deltaWidth / 2 );
932  newExtent.setXMaximum( newExtent.xMaximum() + deltaWidth / 2 );
933  }
934 
935  *currentMapExtent() = newExtent;
936  }
937 
938  //now refresh scale, as this potentially overrides extents
939 
940  //data defined map scale set?
942  {
943  bool ok;
944  double scaleD = exprVal.toDouble( &ok );
945  QgsDebugMsg( QString( "exprVal Map Scale:%1" ).arg( scaleD ) );
946  if ( ok )
947  {
948  setNewScale( scaleD, false );
949  }
950  }
951 
952  //lastly, map rotation overrides all
953  double mapRotation = mMapRotation;
954 
955  //data defined map rotation set?
957  {
958  bool ok;
959  double rotationD = exprVal.toDouble( &ok );
960  QgsDebugMsg( QString( "exprVal Map Rotation:%1" ).arg( rotationD ) );
961  if ( ok )
962  {
963  mapRotation = rotationD;
964  }
965  }
966 
967  if ( mEvaluatedMapRotation != mapRotation )
968  {
970  emit mapRotationChanged( mapRotation );
971  }
972 
973 }
974 
976 {
977  if ( !mUpdatesEnabled )
978  {
979  return;
980  }
981 
983  {
984  cache();
985  }
987 }
988 
990 {
991  QStringList layers = mComposition->mapSettings().layers();
992 
993  QStringList::const_iterator layer_it = layers.constBegin();
994  QgsMapLayer* currentLayer = 0;
995 
996  for ( ; layer_it != layers.constEnd(); ++layer_it )
997  {
998  currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *layer_it );
999  if ( currentLayer )
1000  {
1001  QgsRasterLayer* currentRasterLayer = qobject_cast<QgsRasterLayer *>( currentLayer );
1002  if ( currentRasterLayer )
1003  {
1004  const QgsRasterDataProvider* rasterProvider = 0;
1005  if (( rasterProvider = currentRasterLayer->dataProvider() ) )
1006  {
1007  if ( rasterProvider->name() == "wms" )
1008  {
1009  return true;
1010  }
1011  }
1012  }
1013  }
1014  }
1015  return false;
1016 }
1017 
1019 {
1020  // check if map contains advanced effects like blend modes, or flattened layers for transparency
1021 
1022  QStringList layers = mComposition->mapSettings().layers();
1023 
1024  QStringList::const_iterator layer_it = layers.constBegin();
1025  QgsMapLayer* currentLayer = 0;
1026 
1027  for ( ; layer_it != layers.constEnd(); ++layer_it )
1028  {
1029  currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *layer_it );
1030  if ( currentLayer )
1031  {
1032  if ( currentLayer->blendMode() != QPainter::CompositionMode_SourceOver )
1033  {
1034  return true;
1035  }
1036  // if vector layer, check labels and feature blend mode
1037  QgsVectorLayer* currentVectorLayer = qobject_cast<QgsVectorLayer *>( currentLayer );
1038  if ( currentVectorLayer )
1039  {
1040  if ( currentVectorLayer->layerTransparency() != 0 )
1041  {
1042  return true;
1043  }
1044  if ( currentVectorLayer->featureBlendMode() != QPainter::CompositionMode_SourceOver )
1045  {
1046  return true;
1047  }
1048  // check label blend modes
1049  if ( QgsPalLabeling::staticWillUseLayer( currentVectorLayer ) )
1050  {
1051  // Check all label blending properties
1052  QgsPalLayerSettings layerSettings = QgsPalLayerSettings::fromLayer( currentVectorLayer );
1053  if (( layerSettings.blendMode != QPainter::CompositionMode_SourceOver ) ||
1054  ( layerSettings.bufferSize != 0 && layerSettings.bufferBlendMode != QPainter::CompositionMode_SourceOver ) ||
1055  ( layerSettings.shadowDraw && layerSettings.shadowBlendMode != QPainter::CompositionMode_SourceOver ) ||
1056  ( layerSettings.shapeDraw && layerSettings.shapeBlendMode != QPainter::CompositionMode_SourceOver ) )
1057  {
1058  return true;
1059  }
1060  }
1061  }
1062  }
1063  }
1064 
1065  return false;
1066 }
1067 
1069 {
1070  //connect signal from layer registry to update in case of new or deleted layers
1072  if ( layerRegistry )
1073  {
1074  connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( updateCachedImage() ) );
1075  connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( updateCachedImage() ) );
1076  }
1077 }
1078 
1079 bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
1080 {
1081  if ( elem.isNull() )
1082  {
1083  return false;
1084  }
1085 
1086  QDomElement composerMapElem = doc.createElement( "ComposerMap" );
1087  composerMapElem.setAttribute( "id", mId );
1088 
1089  //previewMode
1090  if ( mPreviewMode == Cache )
1091  {
1092  composerMapElem.setAttribute( "previewMode", "Cache" );
1093  }
1094  else if ( mPreviewMode == Render )
1095  {
1096  composerMapElem.setAttribute( "previewMode", "Render" );
1097  }
1098  else //rectangle
1099  {
1100  composerMapElem.setAttribute( "previewMode", "Rectangle" );
1101  }
1102 
1103  if ( mKeepLayerSet )
1104  {
1105  composerMapElem.setAttribute( "keepLayerSet", "true" );
1106  }
1107  else
1108  {
1109  composerMapElem.setAttribute( "keepLayerSet", "false" );
1110  }
1111 
1112  if ( mDrawCanvasItems )
1113  {
1114  composerMapElem.setAttribute( "drawCanvasItems", "true" );
1115  }
1116  else
1117  {
1118  composerMapElem.setAttribute( "drawCanvasItems", "false" );
1119  }
1120 
1121  //extent
1122  QDomElement extentElem = doc.createElement( "Extent" );
1123  extentElem.setAttribute( "xmin", qgsDoubleToString( mExtent.xMinimum() ) );
1124  extentElem.setAttribute( "xmax", qgsDoubleToString( mExtent.xMaximum() ) );
1125  extentElem.setAttribute( "ymin", qgsDoubleToString( mExtent.yMinimum() ) );
1126  extentElem.setAttribute( "ymax", qgsDoubleToString( mExtent.yMaximum() ) );
1127  composerMapElem.appendChild( extentElem );
1128 
1129  //map rotation
1130  composerMapElem.setAttribute( "mapRotation", QString::number( mMapRotation ) );
1131 
1132  //layer set
1133  QDomElement layerSetElem = doc.createElement( "LayerSet" );
1134  QStringList::const_iterator layerIt = mLayerSet.constBegin();
1135  for ( ; layerIt != mLayerSet.constEnd(); ++layerIt )
1136  {
1137  QDomElement layerElem = doc.createElement( "Layer" );
1138  QDomText layerIdText = doc.createTextNode( *layerIt );
1139  layerElem.appendChild( layerIdText );
1140  layerSetElem.appendChild( layerElem );
1141  }
1142  composerMapElem.appendChild( layerSetElem );
1143 
1144  //write a dummy "Grid" element to prevent crashes on pre 2.5 versions (refs #10905)
1145  QDomElement gridElem = doc.createElement( "Grid" );
1146  composerMapElem.appendChild( gridElem );
1147 
1148  //grids
1149  QList< QgsComposerMapGrid* >::const_iterator gridIt = mGrids.constBegin();
1150  for ( ; gridIt != mGrids.constEnd(); ++gridIt )
1151  {
1152  ( *gridIt )->writeXML( composerMapElem, doc );
1153  }
1154 
1155  //overviews
1156  QList< QgsComposerMapOverview* >::const_iterator overviewIt = mOverviews.constBegin();
1157  for ( ; overviewIt != mOverviews.constEnd(); ++overviewIt )
1158  {
1159  ( *overviewIt )->writeXML( composerMapElem, doc );
1160  }
1161 
1162  //atlas
1163  QDomElement atlasElem = doc.createElement( "AtlasMap" );
1164  atlasElem.setAttribute( "atlasDriven", mAtlasDriven );
1165  atlasElem.setAttribute( "scalingMode", mAtlasScalingMode );
1166  atlasElem.setAttribute( "margin", qgsDoubleToString( mAtlasMargin ) );
1167  composerMapElem.appendChild( atlasElem );
1168 
1169  elem.appendChild( composerMapElem );
1170  return _writeXML( composerMapElem, doc );
1171 }
1172 
1173 bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& doc )
1174 {
1175  if ( itemElem.isNull() )
1176  {
1177  return false;
1178  }
1179 
1180  removeGrids();
1181  removeOverviews();
1182 
1183  QString idRead = itemElem.attribute( "id", "not found" );
1184  if ( idRead != "not found" )
1185  {
1186  mId = idRead.toInt();
1187  }
1189 
1190  //previewMode
1191  QString previewMode = itemElem.attribute( "previewMode" );
1192  if ( previewMode == "Cache" )
1193  {
1194  mPreviewMode = Cache;
1195  }
1196  else if ( previewMode == "Render" )
1197  {
1198  mPreviewMode = Render;
1199  }
1200  else
1201  {
1203  }
1204 
1205  //extent
1206  QDomNodeList extentNodeList = itemElem.elementsByTagName( "Extent" );
1207  if ( extentNodeList.size() > 0 )
1208  {
1209  QDomElement extentElem = extentNodeList.at( 0 ).toElement();
1210  double xmin, xmax, ymin, ymax;
1211  xmin = extentElem.attribute( "xmin" ).toDouble();
1212  xmax = extentElem.attribute( "xmax" ).toDouble();
1213  ymin = extentElem.attribute( "ymin" ).toDouble();
1214  ymax = extentElem.attribute( "ymax" ).toDouble();
1215  setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
1216  }
1217 
1218  //map rotation
1219  if ( itemElem.attribute( "mapRotation", "0" ).toDouble() != 0 )
1220  {
1221  mMapRotation = itemElem.attribute( "mapRotation", "0" ).toDouble();
1222  }
1223 
1224  //mKeepLayerSet flag
1225  QString keepLayerSetFlag = itemElem.attribute( "keepLayerSet" );
1226  if ( keepLayerSetFlag.compare( "true", Qt::CaseInsensitive ) == 0 )
1227  {
1228  mKeepLayerSet = true;
1229  }
1230  else
1231  {
1232  mKeepLayerSet = false;
1233  }
1234 
1235  QString drawCanvasItemsFlag = itemElem.attribute( "drawCanvasItems", "true" );
1236  if ( drawCanvasItemsFlag.compare( "true", Qt::CaseInsensitive ) == 0 )
1237  {
1238  mDrawCanvasItems = true;
1239  }
1240  else
1241  {
1242  mDrawCanvasItems = false;
1243  }
1244 
1245  //mLayerSet
1246  QDomNodeList layerSetNodeList = itemElem.elementsByTagName( "LayerSet" );
1247  QStringList layerSet;
1248  if ( layerSetNodeList.size() > 0 )
1249  {
1250  QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
1251  QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( "Layer" );
1252  for ( int i = 0; i < layerIdNodeList.size(); ++i )
1253  {
1254  layerSet << layerIdNodeList.at( i ).toElement().text();
1255  }
1256  }
1257  mLayerSet = layerSet;
1258 
1259  mDrawing = false;
1260  mNumCachedLayers = 0;
1261  mCacheUpdated = false;
1262 
1263  //grids
1264  QDomNodeList mapGridNodeList = itemElem.elementsByTagName( "ComposerMapGrid" );
1265  for ( int i = 0; i < mapGridNodeList.size(); ++i )
1266  {
1267  QDomElement mapGridElem = mapGridNodeList.at( i ).toElement();
1268  QgsComposerMapGrid* mapGrid = new QgsComposerMapGrid( mapGridElem.attribute( "name" ), this );
1269  mapGrid->readXML( mapGridElem, doc );
1270  mGrids.append( mapGrid );
1271  }
1272 
1273  //load grid / grid annotation in old xml format
1274  //only do this if we don't have the newer ComposerMapGrid element, otherwise this will
1275  //be the dummy element created by QGIS >= 2.5 (refs #10905)
1276  QDomNodeList gridNodeList = itemElem.elementsByTagName( "Grid" );
1277  if ( mapGridNodeList.size() == 0 && gridNodeList.size() > 0 )
1278  {
1279  QDomElement gridElem = gridNodeList.at( 0 ).toElement();
1280  QgsComposerMapGrid* mapGrid = new QgsComposerMapGrid( tr( "Grid %1" ).arg( gridCount() + 1 ), this );
1281  mapGrid->setGridEnabled( gridElem.attribute( "show", "0" ) != "0" );
1282  mapGrid->setGridStyle( QgsComposerMap::GridStyle( gridElem.attribute( "gridStyle", "0" ).toInt() ) );
1283  mapGrid->setGridIntervalX( gridElem.attribute( "intervalX", "0" ).toDouble() );
1284  mapGrid->setGridIntervalY( gridElem.attribute( "intervalY", "0" ).toDouble() );
1285  mapGrid->setGridOffsetX( gridElem.attribute( "offsetX", "0" ).toDouble() );
1286  mapGrid->setGridOffsetY( gridElem.attribute( "offsetY", "0" ).toDouble() );
1287  mapGrid->setCrossLength( gridElem.attribute( "crossLength", "3" ).toDouble() );
1288  mapGrid->setGridFrameStyle(( QgsComposerMap::GridFrameStyle )gridElem.attribute( "gridFrameStyle", "0" ).toInt() );
1289  mapGrid->setGridFrameWidth( gridElem.attribute( "gridFrameWidth", "2.0" ).toDouble() );
1290  mapGrid->setGridFramePenSize( gridElem.attribute( "gridFramePenThickness", "0.5" ).toDouble() );
1291  mapGrid->setGridFramePenColor( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "framePenColor", "0,0,0" ) ) );
1292  mapGrid->setGridFrameFillColor1( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "frameFillColor1", "255,255,255,255" ) ) );
1293  mapGrid->setGridFrameFillColor2( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "frameFillColor2", "0,0,0,255" ) ) );
1294  mapGrid->setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) itemElem.attribute( "gridBlendMode", "0" ).toUInt() ) );
1295  QDomElement gridSymbolElem = gridElem.firstChildElement( "symbol" );
1296  QgsLineSymbolV2* lineSymbol = 0;
1297  if ( gridSymbolElem.isNull( ) )
1298  {
1299  //old project file, read penWidth /penColorRed, penColorGreen, penColorBlue
1300  lineSymbol = QgsLineSymbolV2::createSimple( QgsStringMap() );
1301  lineSymbol->setWidth( gridElem.attribute( "penWidth", "0" ).toDouble() );
1302  lineSymbol->setColor( QColor( gridElem.attribute( "penColorRed", "0" ).toInt(),
1303  gridElem.attribute( "penColorGreen", "0" ).toInt(),
1304  gridElem.attribute( "penColorBlue", "0" ).toInt() ) );
1305  }
1306  else
1307  {
1308  lineSymbol = dynamic_cast<QgsLineSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( gridSymbolElem ) );
1309  }
1310  mapGrid->setGridLineSymbol( lineSymbol );
1311 
1312  //annotation
1313  QDomNodeList annotationNodeList = gridElem.elementsByTagName( "Annotation" );
1314  if ( annotationNodeList.size() > 0 )
1315  {
1316  QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
1317  mapGrid->setShowGridAnnotation( annotationElem.attribute( "show", "0" ) != "0" );
1318  mapGrid->setGridAnnotationFormat( QgsComposerMap::GridAnnotationFormat( annotationElem.attribute( "format", "0" ).toInt() ) );
1319  mapGrid->setGridAnnotationPosition( QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "leftPosition", "0" ).toInt() ), QgsComposerMap::Left );
1320  mapGrid->setGridAnnotationPosition( QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "rightPosition", "0" ).toInt() ), QgsComposerMap::Right );
1321  mapGrid->setGridAnnotationPosition( QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "topPosition", "0" ).toInt() ), QgsComposerMap::Top );
1322  mapGrid->setGridAnnotationPosition( QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "bottomPosition", "0" ).toInt() ), QgsComposerMap::Bottom );
1323  mapGrid->setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "leftDirection", "0" ).toInt() ), QgsComposerMap::Left );
1324  mapGrid->setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "rightDirection", "0" ).toInt() ), QgsComposerMap::Right );
1325  mapGrid->setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "topDirection", "0" ).toInt() ), QgsComposerMap::Top );
1326  mapGrid->setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "bottomDirection", "0" ).toInt() ), QgsComposerMap::Bottom );
1327  mapGrid->setAnnotationFrameDistance( annotationElem.attribute( "frameDistance", "0" ).toDouble() );
1328  QFont annotationFont;
1329  annotationFont.fromString( annotationElem.attribute( "font", "" ) );
1330  mapGrid->setGridAnnotationFont( annotationFont );
1331  mapGrid->setGridAnnotationFontColor( QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "fontColor", "0,0,0,255" ) ) );
1332 
1333  mapGrid->setGridAnnotationPrecision( annotationElem.attribute( "precision", "3" ).toInt() );
1334  }
1335  mGrids.append( mapGrid );
1336  }
1337 
1338  //load overview in old xml format
1339  QDomElement overviewFrameElem = itemElem.firstChildElement( "overviewFrame" );
1340  if ( !overviewFrameElem.isNull() )
1341  {
1342  QgsComposerMapOverview* mapOverview = new QgsComposerMapOverview( tr( "Overview %1" ).arg( overviewCount() + 1 ), this );
1343 
1344  mapOverview->setFrameMap( overviewFrameElem.attribute( "overviewFrameMap", "-1" ).toInt() );
1345  mapOverview->setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) overviewFrameElem.attribute( "overviewBlendMode", "0" ).toUInt() ) );
1346  mapOverview->setInverted( overviewFrameElem.attribute( "overviewInverted" ).compare( "true", Qt::CaseInsensitive ) == 0 );
1347  mapOverview->setCentered( overviewFrameElem.attribute( "overviewCentered" ).compare( "true", Qt::CaseInsensitive ) == 0 );
1348 
1349  QgsFillSymbolV2* fillSymbol = 0;
1350  QDomElement overviewFrameSymbolElem = overviewFrameElem.firstChildElement( "symbol" );
1351  if ( !overviewFrameSymbolElem.isNull() )
1352  {
1353  fillSymbol = dynamic_cast<QgsFillSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( overviewFrameSymbolElem ) );
1354  mapOverview->setFrameSymbol( fillSymbol );
1355  }
1356  }
1357 
1358  //overviews
1359  QDomNodeList mapOverviewNodeList = itemElem.elementsByTagName( "ComposerMapOverview" );
1360  for ( int i = 0; i < mapOverviewNodeList.size(); ++i )
1361  {
1362  QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
1363  QgsComposerMapOverview* mapOverview = new QgsComposerMapOverview( mapOverviewElem.attribute( "name" ), this );
1364  mapOverview->readXML( mapOverviewElem, doc );
1365  mOverviews.append( mapOverview );
1366  }
1367 
1368  //atlas
1369  QDomNodeList atlasNodeList = itemElem.elementsByTagName( "AtlasMap" );
1370  if ( atlasNodeList.size() > 0 )
1371  {
1372  QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1373  mAtlasDriven = ( atlasElem.attribute( "atlasDriven", "0" ) != "0" );
1374  if ( atlasElem.hasAttribute( "fixedScale" ) ) // deprecated XML
1375  {
1376  mAtlasScalingMode = ( atlasElem.attribute( "fixedScale", "0" ) != "0" ) ? Fixed : Auto;
1377  }
1378  else if ( atlasElem.hasAttribute( "scalingMode" ) )
1379  {
1380  mAtlasScalingMode = static_cast<AtlasScalingMode>( atlasElem.attribute( "scalingMode" ).toInt() );
1381  }
1382  mAtlasMargin = atlasElem.attribute( "margin", "0.1" ).toDouble();
1383  }
1384 
1385  //restore general composer item properties
1386  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
1387  if ( composerItemList.size() > 0 )
1388  {
1389  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
1390 
1391  if ( composerItemElem.attribute( "rotation", "0" ).toDouble() != 0 )
1392  {
1393  //in versions prior to 2.1 map rotation was stored in the rotation attribute
1394  mMapRotation = composerItemElem.attribute( "rotation", "0" ).toDouble();
1395  }
1396 
1397  _readXML( composerItemElem, doc );
1398  }
1399 
1401  emit itemChanged();
1402  return true;
1403 }
1404 
1406 {
1408 }
1409 
1411 {
1412  if ( mLayerSet.size() < 1 )
1413  {
1414  return;
1415  }
1416 
1417  //if layer set is fixed, do a lookup in the layer registry to also find the non-visible layers
1418  QStringList currentLayerSet;
1419  if ( mKeepLayerSet )
1420  {
1421  currentLayerSet = QgsMapLayerRegistry::instance()->mapLayers().uniqueKeys();
1422  }
1423  else //only consider layers visible in the map
1424  {
1425  currentLayerSet = mComposition->mapSettings().layers();
1426  }
1427 
1428  for ( int i = mLayerSet.size() - 1; i >= 0; --i )
1429  {
1430  if ( !currentLayerSet.contains( mLayerSet.at( i ) ) )
1431  {
1432  mLayerSet.removeAt( i );
1433  }
1434  }
1435 }
1436 
1438 {
1439  if ( mGrids.size() < 1 )
1440  {
1441  QgsComposerMapGrid* grid = new QgsComposerMapGrid( tr( "Grid %1" ).arg( 1 ), this );
1442  mGrids.push_back( grid );
1443  }
1444  return mGrids.at( 0 );
1445 }
1446 
1448 {
1449  return const_cast<QgsComposerMap*>( this )->firstMapGrid();
1450 }
1451 
1453 {
1455  g->setGridStyle( style );
1456 }
1457 
1459 {
1461  return g->gridStyle();
1462 }
1463 
1464 void QgsComposerMap::setGridIntervalX( double interval )
1465 {
1467  g->setGridIntervalX( interval );
1468 }
1469 
1471 {
1473  return g->gridIntervalX();
1474 }
1475 
1476 void QgsComposerMap::setGridIntervalY( double interval )
1477 {
1479  g->setGridIntervalY( interval );
1480 }
1481 
1483 {
1485  return g->gridIntervalY();
1486 }
1487 
1488 void QgsComposerMap::setGridOffsetX( double offset )
1489 {
1491  g->setGridOffsetX( offset );
1492 }
1493 
1495 {
1497  return g->gridOffsetX();
1498 }
1499 
1500 void QgsComposerMap::setGridOffsetY( double offset )
1501 {
1503  g->setGridOffsetY( offset );
1504 }
1505 
1507 {
1509  return g->gridOffsetY();
1510 }
1511 
1513 {
1515  g->setGridPenWidth( w );
1516 }
1517 
1518 void QgsComposerMap::setGridPenColor( const QColor& c )
1519 {
1521  g->setGridPenColor( c );
1522 }
1523 
1524 void QgsComposerMap::setGridPen( const QPen& p )
1525 {
1527  g->setGridPen( p );
1528 }
1529 
1531 {
1533  return g->gridPen();
1534 }
1535 
1537 {
1539  g->setGridAnnotationFont( f );
1540 }
1541 
1543 {
1545  return g->gridAnnotationFont();
1546 }
1547 
1549 {
1552 }
1553 
1555 {
1557  return g->gridAnnotationFontColor();
1558 }
1559 
1561 {
1564 }
1565 
1567 {
1569  return g->gridAnnotationPrecision();
1570 }
1571 
1573 {
1575  g->setShowGridAnnotation( show );
1576 }
1577 
1579 {
1581  return g->showGridAnnotation();
1582 }
1583 
1585 {
1587  g->setGridAnnotationPosition( p, border );
1588 }
1589 
1591 {
1593  return g->gridAnnotationPosition( border );
1594 }
1595 
1597 {
1600 }
1601 
1603 {
1605  return g->annotationFrameDistance();
1606 }
1607 
1609 {
1611  g->setGridAnnotationDirection( d, border );
1612 }
1613 
1615 {
1617  return g->gridAnnotationDirection( border );
1618 }
1619 
1621 {
1623  g->setGridAnnotationFormat( f );
1624 }
1625 
1627 {
1629  return g->gridAnnotationFormat();
1630 }
1631 
1633 {
1635  g->setGridFrameStyle( style );
1636 }
1637 
1639 {
1641  return g->gridFrameStyle();
1642 }
1643 
1645 {
1647  g->setGridFrameWidth( w );
1648 }
1649 
1651 {
1653  return g->gridFrameWidth();
1654 }
1655 
1657 {
1659  g->setGridFramePenSize( w );
1660 }
1661 
1663 {
1665  return g->gridFramePenSize();
1666 }
1667 
1669 {
1671  g->setGridFramePenColor( c );
1672 }
1673 
1675 {
1677  return g->gridFramePenColor();
1678 }
1679 
1681 {
1683  g->setGridFrameFillColor1( c );
1684 }
1685 
1687 {
1689  return g->gridFrameFillColor1();
1690 }
1691 
1693 {
1695  g->setGridFrameFillColor2( c );
1696 }
1697 
1699 {
1701  return g->gridFrameFillColor2();
1702 }
1703 
1705 {
1707  g->setCrossLength( l );
1708 }
1709 
1711 {
1713  return g->crossLength();
1714 }
1715 
1717 {
1718  qDeleteAll( mGrids );
1719  mGrids.clear();
1720 }
1721 
1722 void QgsComposerMap::drawGrids( QPainter* p )
1723 {
1724  QList< QgsComposerMapGrid* >::const_iterator gridIt = mGrids.constBegin();
1725  for ( ; gridIt != mGrids.constEnd(); ++gridIt )
1726  {
1727  ( *gridIt )->drawGrid( p );
1728  }
1729 }
1730 
1732 {
1733  if ( mOverviews.size() < 1 )
1734  {
1735  QgsComposerMapOverview* overview = new QgsComposerMapOverview( tr( "Overview %1" ).arg( 1 ), this );
1736  mOverviews.push_back( overview );
1737  }
1738  return mOverviews.at( 0 );
1739 }
1740 
1742 {
1743  return const_cast<QgsComposerMap*>( this )->firstMapOverview();
1744 }
1745 
1747 {
1748  qDeleteAll( mOverviews );
1749  mOverviews.clear();
1750 }
1751 
1753 {
1754  QList< QgsComposerMapOverview* >::const_iterator overviewIt = mOverviews.constBegin();
1755  for ( ; overviewIt != mOverviews.constEnd(); ++overviewIt )
1756  {
1757  ( *overviewIt )->drawOverview( p );
1758  }
1759 }
1760 
1761 /*QString QgsComposerMap::gridAnnotationString( double value, AnnotationCoordinate coord ) const
1762 {
1763  if ( mGridAnnotationFormat == Decimal )
1764  {
1765  return QString::number( value, 'f', mGridAnnotationPrecision );
1766  }
1767 
1768  QgsPoint p;
1769  p.setX( coord == Longitude ? value : 0 );
1770  p.setY( coord == Longitude ? 0 : value );
1771 
1772  QString annotationString;
1773  if ( mGridAnnotationFormat == DegreeMinute )
1774  {
1775  annotationString = p.toDegreesMinutes( mGridAnnotationPrecision );
1776  }
1777  else //DegreeMinuteSecond
1778  {
1779  annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision );
1780  }
1781 
1782  QStringList split = annotationString.split( "," );
1783  if ( coord == Longitude )
1784  {
1785  return split.at( 0 );
1786  }
1787  else
1788  {
1789  if ( split.size() < 2 )
1790  {
1791  return "";
1792  }
1793  return split.at( 1 );
1794  }
1795 }*/
1796 
1797 void QgsComposerMap::setGridBlendMode( QPainter::CompositionMode blendMode )
1798 {
1800  g->setBlendMode( blendMode );
1801 }
1802 
1803 QPainter::CompositionMode QgsComposerMap::gridBlendMode() const
1804 {
1806  return g->blendMode();
1807 }
1808 
1810 {
1811  return mCurrentRectangle;
1812 }
1813 
1815 {
1816  QRectF rectangle = rect();
1817  double frameExtension = mFrame ? pen().widthF() / 2.0 : 0.0;
1818  double maxGridExtension = 0;
1819 
1820  QList< QgsComposerMapGrid* >::const_iterator it = mGrids.constBegin();
1821  for ( ; it != mGrids.constEnd(); ++it )
1822  {
1823  maxGridExtension = qMax( maxGridExtension, ( *it )->maxExtension() );
1824  }
1825  double maxExtension = qMax( frameExtension, maxGridExtension );
1826 
1827  rectangle.setLeft( rectangle.left() - maxExtension );
1828  rectangle.setRight( rectangle.right() + maxExtension );
1829  rectangle.setTop( rectangle.top() - maxExtension );
1830  rectangle.setBottom( rectangle.bottom() + maxExtension );
1831  if ( rectangle != mCurrentRectangle )
1832  {
1833  prepareGeometryChange();
1834  mCurrentRectangle = rectangle;
1835  }
1836 }
1837 
1839 {
1840  QgsComposerItem::setFrameOutlineWidth( outlineWidth );
1842 }
1843 
1845 {
1846  double dx = mXOffset;
1847  double dy = mYOffset;
1848  transformShift( dx, dy );
1849  return QgsRectangle( currentMapExtent()->xMinimum() - dx, currentMapExtent()->yMinimum() - dy, currentMapExtent()->xMaximum() - dx, currentMapExtent()->yMaximum() - dy );
1850 }
1851 
1853 {
1854  double dx = mXOffset;
1855  double dy = mYOffset;
1856  //qWarning("offset");
1857  //qWarning(QString::number(dx).toLocal8Bit().data());
1858  //qWarning(QString::number(dy).toLocal8Bit().data());
1859  transformShift( dx, dy );
1860  //qWarning("transformed:");
1861  //qWarning(QString::number(dx).toLocal8Bit().data());
1862  //qWarning(QString::number(dy).toLocal8Bit().data());
1863  QPolygonF poly = visibleExtentPolygon();
1864  poly.translate( -dx, -dy );
1865  return poly;
1866 }
1867 
1868 void QgsComposerMap::mapPolygon( const QgsRectangle& extent, QPolygonF& poly ) const
1869 {
1870  poly.clear();
1871  if ( mEvaluatedMapRotation == 0 )
1872  {
1873  poly << QPointF( extent.xMinimum(), extent.yMaximum() );
1874  poly << QPointF( extent.xMaximum(), extent.yMaximum() );
1875  poly << QPointF( extent.xMaximum(), extent.yMinimum() );
1876  poly << QPointF( extent.xMinimum(), extent.yMinimum() );
1877  return;
1878  }
1879 
1880  //there is rotation
1881  QgsPoint rotationPoint(( extent.xMaximum() + extent.xMinimum() ) / 2.0, ( extent.yMaximum() + extent.yMinimum() ) / 2.0 );
1882  double dx, dy; //x-, y- shift from rotation point to corner point
1883 
1884  //top left point
1885  dx = rotationPoint.x() - extent.xMinimum();
1886  dy = rotationPoint.y() - extent.yMaximum();
1888  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1889 
1890  //top right point
1891  dx = rotationPoint.x() - extent.xMaximum();
1892  dy = rotationPoint.y() - extent.yMaximum();
1894  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1895 
1896  //bottom right point
1897  dx = rotationPoint.x() - extent.xMaximum();
1898  dy = rotationPoint.y() - extent.yMinimum();
1900  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1901 
1902  //bottom left point
1903  dx = rotationPoint.x() - extent.xMinimum();
1904  dy = rotationPoint.y() - extent.yMinimum();
1906  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1907 }
1908 
1910 {
1911  QPolygonF poly;
1912  mapPolygon( *currentMapExtent(), poly );
1913  return poly;
1914 }
1915 
1917 {
1918  mGrids.append( grid );
1920 }
1921 
1922 void QgsComposerMap::removeGrid( const QString& name )
1923 {
1924  for ( int i = mGrids.size() - 1; i >= 0; --i )
1925  {
1926  if ( mGrids.at( i )->name() == name )
1927  {
1928  delete mGrids.takeAt( i );
1929  }
1930  }
1931 }
1932 
1933 void QgsComposerMap::moveGridUp( const QString& name )
1934 {
1935  QgsComposerMapGrid* grid = mapGrid( name );
1936  if ( !grid )
1937  {
1938  return;
1939  }
1940 
1941  int index = mGrids.indexOf( grid );
1942  if ( index >= mGrids.size() - 1 )
1943  {
1944  return;
1945  }
1946  mGrids.swap( index, index + 1 );
1947  update();
1948 }
1949 
1950 void QgsComposerMap::moveGridDown( const QString& name )
1951 {
1952  QgsComposerMapGrid* grid = mapGrid( name );
1953  if ( !grid )
1954  {
1955  return;
1956  }
1957 
1958  int index = mGrids.indexOf( grid );
1959  if ( index < 1 )
1960  {
1961  return;
1962  }
1963  mGrids.swap( index, index - 1 );
1964  update();
1965 }
1966 
1967 const QgsComposerMapGrid* QgsComposerMap::constMapGrid( const QString& id ) const
1968 {
1969  QList< QgsComposerMapGrid* >::const_iterator it = mGrids.constBegin();
1970  for ( ; it != mGrids.constEnd(); ++it )
1971  {
1972  if (( *it )->id() == id )
1973  {
1974  return ( *it );
1975  }
1976  }
1977 
1978  return 0;
1979 }
1980 
1981 QgsComposerMapGrid* QgsComposerMap::mapGrid( const QString& id ) const
1982 {
1983  QList< QgsComposerMapGrid* >::const_iterator it = mGrids.begin();
1984  for ( ; it != mGrids.end(); ++it )
1985  {
1986  if (( *it )->id() == id )
1987  {
1988  return ( *it );
1989  }
1990  }
1991 
1992  return 0;
1993 }
1994 
1995 QList< const QgsComposerMapGrid* > QgsComposerMap::mapGrids() const
1996 {
1997  QList< const QgsComposerMapGrid* > list;
1998  QList< QgsComposerMapGrid* >::const_iterator it = mGrids.begin();
1999  for ( ; it != mGrids.end(); ++it )
2000  {
2001  list.append( *it );
2002  }
2003  return list;
2004 }
2005 
2007 {
2008  mOverviews.append( overview );
2009 }
2010 
2011 void QgsComposerMap::removeOverview( const QString &name )
2012 {
2013  for ( int i = mOverviews.size() - 1; i >= 0; --i )
2014  {
2015  if ( mOverviews.at( i )->name() == name )
2016  {
2017  delete mOverviews.takeAt( i );
2018  }
2019  }
2020 }
2021 
2022 void QgsComposerMap::moveOverviewUp( const QString &name )
2023 {
2024  QgsComposerMapOverview* overview = mapOverview( name );
2025  if ( !overview )
2026  {
2027  return;
2028  }
2029 
2030  int index = mOverviews.indexOf( overview );
2031  if ( index >= mOverviews.size() - 1 )
2032  {
2033  return;
2034  }
2035  mOverviews.swap( index, index + 1 );
2036  update();
2037 }
2038 
2039 void QgsComposerMap::moveOverviewDown( const QString &name )
2040 {
2041  QgsComposerMapOverview* overview = mapOverview( name );
2042  if ( !overview )
2043  {
2044  return;
2045  }
2046 
2047  int index = mOverviews.indexOf( overview );
2048  if ( index < 1 )
2049  {
2050  return;
2051  }
2052  mOverviews.swap( index, index - 1 );
2053  update();
2054 }
2055 
2057 {
2058  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.constBegin();
2059  for ( ; it != mOverviews.constEnd(); ++it )
2060  {
2061  if (( *it )->id() == id )
2062  {
2063  return ( *it );
2064  }
2065  }
2066 
2067  return 0;
2068 }
2069 
2071 {
2072  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.begin();
2073  for ( ; it != mOverviews.end(); ++it )
2074  {
2075  if (( *it )->id() == id )
2076  {
2077  return ( *it );
2078  }
2079  }
2080 
2081  return 0;
2082 }
2083 
2084 QList<QgsComposerMapOverview *> QgsComposerMap::mapOverviews() const
2085 {
2086  QList< QgsComposerMapOverview* > list;
2087  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.begin();
2088  for ( ; it != mOverviews.end(); ++it )
2089  {
2090  list.append( *it );
2091  }
2092  return list;
2093 }
2094 
2096 {
2097  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.begin();
2098  for ( ; it != mOverviews.end(); ++it )
2099  {
2100  (*it)->connectSignals();
2101  }
2102 }
2103 
2105 {
2106  QgsRectangle newExtent = *currentMapExtent();
2107  if ( mEvaluatedMapRotation == 0 )
2108  {
2109  extent = newExtent;
2110  }
2111  else
2112  {
2113  QPolygonF poly;
2114  mapPolygon( newExtent, poly );
2115  QRectF bRect = poly.boundingRect();
2116  extent.setXMinimum( bRect.left() );
2117  extent.setXMaximum( bRect.right() );
2118  extent.setYMinimum( bRect.top() );
2119  extent.setYMaximum( bRect.bottom() );
2120  }
2121 }
2122 
2124 {
2125  double extentWidth = currentMapExtent()->width();
2126  if ( extentWidth <= 0 )
2127  {
2128  return 1;
2129  }
2130  return rect().width() / extentWidth;
2131 }
2132 
2134 {
2136  overview->setFrameMap( mapId );
2137 }
2138 
2140 {
2141  const QgsComposerMapOverview* overview = constFirstMapOverview();
2142  return overview->frameMapId();
2143 }
2144 
2146 {
2147  //updates data defined properties and redraws item to match
2148  if ( property == QgsComposerObject::MapRotation || property == QgsComposerObject::MapScale ||
2149  property == QgsComposerObject::MapXMin || property == QgsComposerObject::MapYMin ||
2150  property == QgsComposerObject::MapXMax || property == QgsComposerObject::MapYMax ||
2151  property == QgsComposerObject::AllProperties )
2152  {
2154  emit itemChanged();
2155  emit extentChanged();
2156  }
2157 
2158  //force redraw
2159  cache();
2160 
2162 }
2163 
2165 {
2167  overview->setFrameSymbol( symbol );
2168 }
2169 
2171 {
2173  return overview->frameSymbol();
2174 }
2175 
2176 QPainter::CompositionMode QgsComposerMap::overviewBlendMode() const
2177 {
2178  const QgsComposerMapOverview* overview = constFirstMapOverview();
2179  return overview->blendMode();
2180 }
2181 
2182 void QgsComposerMap::setOverviewBlendMode( QPainter::CompositionMode blendMode )
2183 {
2185  overview->setBlendMode( blendMode );
2186 }
2187 
2189 {
2190  const QgsComposerMapOverview* overview = constFirstMapOverview();
2191  return overview->inverted();
2192 }
2193 
2195 {
2197  overview->setInverted( inverted );
2198 }
2199 
2201 {
2202  const QgsComposerMapOverview* overview = constFirstMapOverview();
2203  return overview->centered();
2204 }
2205 
2207 {
2209  overview->setCentered( centered );
2210  //overviewExtentChanged();
2211 }
2212 
2214 {
2216  g->setGridLineSymbol( symbol );
2217 }
2218 
2220 {
2222  return g->gridLineSymbol();
2223 }
2224 
2226 {
2228  g->setGridEnabled( enabled );
2229 }
2230 
2232 {
2234  return g->gridEnabled();
2235 }
2236 
2237 void QgsComposerMap::transformShift( double& xShift, double& yShift ) const
2238 {
2239  double mmToMapUnits = 1.0 / mapUnitsToMM();
2240  double dxScaled = xShift * mmToMapUnits;
2241  double dyScaled = - yShift * mmToMapUnits;
2242 
2243  QgsComposerUtils::rotate( mEvaluatedMapRotation, dxScaled, dyScaled );
2244 
2245  xShift = dxScaled;
2246  yShift = dyScaled;
2247 }
2248 
2249 QPointF QgsComposerMap::mapToItemCoords( const QPointF& mapCoords ) const
2250 {
2251  QPolygonF mapPoly = transformedMapPolygon();
2252  if ( mapPoly.size() < 1 )
2253  {
2254  return QPointF( 0, 0 );
2255  }
2256 
2257  QgsRectangle tExtent = transformedExtent();
2258  QgsPoint rotationPoint(( tExtent.xMaximum() + tExtent.xMinimum() ) / 2.0, ( tExtent.yMaximum() + tExtent.yMinimum() ) / 2.0 );
2259  double dx = mapCoords.x() - rotationPoint.x();
2260  double dy = mapCoords.y() - rotationPoint.y();
2262  QgsPoint backRotatedCoords( rotationPoint.x() + dx, rotationPoint.y() + dy );
2263 
2264  QgsRectangle unrotatedExtent = transformedExtent();
2265  double xItem = rect().width() * ( backRotatedCoords.x() - unrotatedExtent.xMinimum() ) / unrotatedExtent.width();
2266  double yItem = rect().height() * ( 1 - ( backRotatedCoords.y() - unrotatedExtent.yMinimum() ) / unrotatedExtent.height() );
2267  return QPointF( xItem, yItem );
2268 }
2269 
2271 {
2272  if ( p.x() <= pen().widthF() )
2273  {
2274  return Left;
2275  }
2276  else if ( p.x() >= ( rect().width() - pen().widthF() ) )
2277  {
2278  return Right;
2279  }
2280  else if ( p.y() <= pen().widthF() )
2281  {
2282  return Top;
2283  }
2284  else
2285  {
2286  return Bottom;
2287  }
2288 }
2289 
2290 void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
2291 {
2292  if ( !mMapCanvas || !mDrawCanvasItems )
2293  {
2294  return;
2295  }
2296 
2297  QList<QGraphicsItem*> itemList = mMapCanvas->items();
2298  if ( itemList.size() < 1 )
2299  {
2300  return;
2301  }
2302  QGraphicsItem* currentItem = 0;
2303 
2304  for ( int i = itemList.size() - 1; i >= 0; --i )
2305  {
2306  currentItem = itemList.at( i );
2307  //don't draw mapcanvasmap (has z value -10)
2308  if ( !currentItem || currentItem->data( 0 ).toString() != "AnnotationItem" )
2309  {
2310  continue;
2311  }
2312  drawCanvasItem( currentItem, painter, itemStyle );
2313  }
2314 }
2315 
2316 void QgsComposerMap::drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
2317 {
2318  if ( !item || !mMapCanvas || !item->isVisible() )
2319  {
2320  return;
2321  }
2322 
2323  painter->save();
2324  painter->setRenderHint( QPainter::Antialiasing );
2325 
2326  //determine scale factor according to graphics view dpi
2327  double scaleFactor = 1.0 / mMapCanvas->logicalDpiX() * 25.4;
2328 
2329  double itemX, itemY;
2330  QGraphicsItem* parent = item->parentItem();
2331  if ( !parent )
2332  {
2333  QPointF mapPos = composerMapPosForItem( item );
2334  itemX = mapPos.x();
2335  itemY = mapPos.y();
2336  }
2337  else //place item relative to the parent item
2338  {
2339  QPointF itemScenePos = item->scenePos();
2340  QPointF parentScenePos = parent->scenePos();
2341 
2342  QPointF mapPos = composerMapPosForItem( parent );
2343 
2344  itemX = mapPos.x() + ( itemScenePos.x() - parentScenePos.x() ) * scaleFactor;
2345  itemY = mapPos.y() + ( itemScenePos.y() - parentScenePos.y() ) * scaleFactor;
2346  }
2347  painter->translate( itemX, itemY );
2348 
2349  painter->scale( scaleFactor, scaleFactor );
2350 
2351  //a little trick to let the item know that the paint request comes from the composer
2352  item->setData( 1, "composer" );
2353  item->paint( painter, itemStyle, 0 );
2354  item->setData( 1, "" );
2355  painter->restore();
2356 }
2357 
2358 QPointF QgsComposerMap::composerMapPosForItem( const QGraphicsItem* item ) const
2359 {
2360  if ( !item || !mMapCanvas )
2361  {
2362  return QPointF( 0, 0 );
2363  }
2364 
2365  if ( currentMapExtent()->height() <= 0 || currentMapExtent()->width() <= 0 || mMapCanvas->width() <= 0 || mMapCanvas->height() <= 0 )
2366  {
2367  return QPointF( 0, 0 );
2368  }
2369 
2370  QRectF graphicsSceneRect = mMapCanvas->sceneRect();
2371  QPointF itemScenePos = item->scenePos();
2372  QgsRectangle mapRendererExtent = mComposition->mapSettings().visibleExtent();
2373 
2374  double mapX = itemScenePos.x() / graphicsSceneRect.width() * mapRendererExtent.width() + mapRendererExtent.xMinimum();
2375  double mapY = mapRendererExtent.yMaximum() - itemScenePos.y() / graphicsSceneRect.height() * mapRendererExtent.height();
2376  return mapToItemCoords( QPointF( mapX, mapY ) );
2377 }
2378 
2379 /*void QgsComposerMap::initGridAnnotationFormatFromProject()
2380 {
2381  QString format = QgsProject::instance()->readEntry( "PositionPrecision", "/DegreeFormat", "D" );
2382 
2383  bool degreeUnits = ( mComposition->mapSettings().mapUnits() == QGis::Degrees );
2384 
2385  if ( format == "DM" && degreeUnits )
2386  {
2387  mGridAnnotationFormat = DegreeMinute;
2388  }
2389  else if ( format == "DMS" && degreeUnits )
2390  {
2391  mGridAnnotationFormat = DegreeMinuteSecond;
2392  }
2393  else
2394  {
2395  mGridAnnotationFormat = Decimal;
2396  }
2397 }*/
2398 
2400 {
2401  if ( !mComposition )
2402  {
2403  return;
2404  }
2405 
2406  const QgsComposerMap* existingMap = mComposition->getComposerMapById( mId );
2407  if ( !existingMap )
2408  {
2409  return; //keep mId as it is still available
2410  }
2411 
2412  int maxId = -1;
2413  QList<const QgsComposerMap*> mapList = mComposition->composerMapItems();
2414  QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin();
2415  for ( ; mapIt != mapList.constEnd(); ++mapIt )
2416  {
2417  if (( *mapIt )->id() > maxId )
2418  {
2419  maxId = ( *mapIt )->id();
2420  }
2421  }
2422  mId = maxId + 1;
2423 }
2424 
2425 bool QgsComposerMap::imageSizeConsideringRotation( double& width, double& height ) const
2426 {
2427  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2431 }
2432 
2433 bool QgsComposerMap::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const
2434 {
2435  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2439 }
2440 
2441 void QgsComposerMap::sizeChangedByRotation( double& width, double& height )
2442 {
2443  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2447 }
2448 
2450 {
2451  mAtlasDriven = enabled;
2452 
2453  if ( !enabled )
2454  {
2455  //if not enabling the atlas, we still need to refresh the map extents
2456  //so that data defined extents and scale are recalculated
2458  }
2459 }
2460 
2462 {
2463  return mAtlasScalingMode == Fixed;
2464 }
2465 
2467 {
2468  // implicit : if set to false => auto scaling
2469  mAtlasScalingMode = fixed ? Fixed : Auto;
2470 }
2471 
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
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)