QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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  QgsRectangle newExtent = extent;
716  //Make sure the width/height ratio is the same as the current composer map extent.
717  //This is to keep the map item frame size fixed
718  double currentWidthHeightRatio = currentMapExtent()->width() / currentMapExtent()->height();
719  double newWidthHeightRatio = newExtent.width() / newExtent.height();
720 
721  if ( currentWidthHeightRatio < newWidthHeightRatio )
722  {
723  //enlarge height of new extent, ensuring the map center stays the same
724  double newHeight = newExtent.width() / currentWidthHeightRatio;
725  double deltaHeight = newHeight - newExtent.height();
726  newExtent.setYMinimum( newExtent.yMinimum() - deltaHeight / 2 );
727  newExtent.setYMaximum( newExtent.yMaximum() + deltaHeight / 2 );
728  }
729  else
730  {
731  //enlarge width of new extent, ensuring the map center stays the same
732  double newWidth = currentWidthHeightRatio * newExtent.height();
733  double deltaWidth = newWidth - newExtent.width();
734  newExtent.setXMinimum( newExtent.xMinimum() - deltaWidth / 2 );
735  newExtent.setXMaximum( newExtent.xMaximum() + deltaWidth / 2 );
736  }
737 
738  if ( *currentMapExtent() == newExtent )
739  {
740  return;
741  }
742  *currentMapExtent() = newExtent;
743 
744  //recalculate data defined scale and extents, since that may override extent
746 
747  mCacheUpdated = false;
748  updateItem();
749  emit itemChanged();
750  emit extentChanged();
751 }
752 
754 {
755  if ( mAtlasFeatureExtent != extent )
756  {
757  //don't adjust size of item, instead adjust size of bounds to fit
758  QgsRectangle newExtent = extent;
759 
760  //Make sure the width/height ratio is the same as the map item size
761  double currentWidthHeightRatio = rect().width() / rect().height();
762  double newWidthHeightRatio = newExtent.width() / newExtent.height();
763 
764  if ( currentWidthHeightRatio < newWidthHeightRatio )
765  {
766  //enlarge height of new extent, ensuring the map center stays the same
767  double newHeight = newExtent.width() / currentWidthHeightRatio;
768  double deltaHeight = newHeight - newExtent.height();
769  newExtent.setYMinimum( extent.yMinimum() - deltaHeight / 2 );
770  newExtent.setYMaximum( extent.yMaximum() + deltaHeight / 2 );
771  }
772  else if ( currentWidthHeightRatio >= newWidthHeightRatio )
773  {
774  //enlarge width of new extent, ensuring the map center stays the same
775  double newWidth = currentWidthHeightRatio * newExtent.height();
776  double deltaWidth = newWidth - newExtent.width();
777  newExtent.setXMinimum( extent.xMinimum() - deltaWidth / 2 );
778  newExtent.setXMaximum( extent.xMaximum() + deltaWidth / 2 );
779  }
780 
781  mAtlasFeatureExtent = newExtent;
782  }
783 
784  //recalculate data defined scale and extents, since that may override extents
786 
787  mCacheUpdated = false;
788  emit preparedForAtlas();
789  updateItem();
790  emit itemChanged();
791  emit extentChanged();
792 }
793 
795 {
796  //atlas preview has been toggled, so update item and extents
797  mCacheUpdated = false;
798  updateItem();
799  emit itemChanged();
800  emit extentChanged();
801 }
802 
804 {
805  //non-const version
807  {
808  //if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
809  //return the current temporary atlas feature extent
810  return &mAtlasFeatureExtent;
811  }
812  else
813  {
814  //otherwise return permenant user set extent
815  return &mExtent;
816  }
817 }
818 
820 {
821  //const version
823  {
824  //if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
825  //return the current temporary atlas feature extent
826  return &mAtlasFeatureExtent;
827  }
828  else
829  {
830  //otherwise return permenant user set extent
831  return &mExtent;
832  }
833 }
834 
835 void QgsComposerMap::setNewScale( double scaleDenominator, bool forceUpdate )
836 {
837  double currentScaleDenominator = scale();
838 
839  if ( scaleDenominator == currentScaleDenominator || scaleDenominator == 0 )
840  {
841  return;
842  }
843 
844  double scaleRatio = scaleDenominator / currentScaleDenominator;
845  currentMapExtent()->scale( scaleRatio );
846 
848  {
849  //if map is atlas controlled and set to fixed scaling mode, then scale changes should be treated as permanant
850  //and also apply to the map's original extent (see #9602)
851  //we can't use the scaleRatio calculated earlier, as the scale can vary depending on extent for geographic coordinate systems
852  QgsScaleCalculator calculator;
853  calculator.setMapUnits( mComposition->mapSettings().mapUnits() );
854  calculator.setDpi( 25.4 ); //QGraphicsView units are mm
855  scaleRatio = scaleDenominator / calculator.calculate( mExtent, rect().width() );
856  mExtent.scale( scaleRatio );
857  }
858 
859  mCacheUpdated = false;
860  if ( forceUpdate )
861  {
862  cache();
863  update();
864  emit itemChanged();
865  }
866  emit extentChanged();
867 }
868 
870 {
871  mPreviewMode = m;
872  emit itemChanged();
873 }
874 
875 void QgsComposerMap::setOffset( double xOffset, double yOffset )
876 {
877  mXOffset = xOffset;
878  mYOffset = yOffset;
879 }
880 
882 {
883  //kept for api compatibility with QGIS 2.0
884  setMapRotation( r );
885 }
886 
888 {
889  mMapRotation = r;
891  emit mapRotationChanged( r );
892  emit itemChanged();
893  update();
894 }
895 
897 {
899 }
900 
902 {
903  //data defined map extents set?
904  QVariant exprVal;
905 
906  QgsRectangle newExtent = *currentMapExtent();
907  bool useDdXMin = false;
908  bool useDdXMax = false;
909  bool useDdYMin = false;
910  bool useDdYMax = false;
911  double minXD = 0;
912  double minYD = 0;
913  double maxXD = 0;
914  double maxYD = 0;
915 
917  {
918  bool ok;
919  minXD = exprVal.toDouble( &ok );
920  QgsDebugMsg( QString( "exprVal Map XMin:%1" ).arg( minXD ) );
921  if ( ok )
922  {
923  useDdXMin = true;
924  newExtent.setXMinimum( minXD );
925  }
926  }
928  {
929  bool ok;
930  minYD = exprVal.toDouble( &ok );
931  QgsDebugMsg( QString( "exprVal Map YMin:%1" ).arg( minYD ) );
932  if ( ok )
933  {
934  useDdYMin = true;
935  newExtent.setYMinimum( minYD );
936  }
937  }
939  {
940  bool ok;
941  maxXD = exprVal.toDouble( &ok );
942  QgsDebugMsg( QString( "exprVal Map XMax:%1" ).arg( maxXD ) );
943  if ( ok )
944  {
945  useDdXMax = true;
946  newExtent.setXMaximum( maxXD );
947  }
948  }
950  {
951  bool ok;
952  maxYD = exprVal.toDouble( &ok );
953  QgsDebugMsg( QString( "exprVal Map YMax:%1" ).arg( maxYD ) );
954  if ( ok )
955  {
956  useDdYMax = true;
957  newExtent.setYMaximum( maxYD );
958  }
959  }
960 
961  if ( newExtent != *currentMapExtent() )
962  {
963  //calculate new extents to fit data defined extents
964 
965  //Make sure the width/height ratio is the same as in current map extent.
966  //This is to keep the map item frame and the page layout fixed
967  double currentWidthHeightRatio = currentMapExtent()->width() / currentMapExtent()->height();
968  double newWidthHeightRatio = newExtent.width() / newExtent.height();
969 
970  if ( currentWidthHeightRatio < newWidthHeightRatio )
971  {
972  //enlarge height of new extent, ensuring the map center stays the same
973  double newHeight = newExtent.width() / currentWidthHeightRatio;
974  double deltaHeight = newHeight - newExtent.height();
975  newExtent.setYMinimum( newExtent.yMinimum() - deltaHeight / 2 );
976  newExtent.setYMaximum( newExtent.yMaximum() + deltaHeight / 2 );
977  }
978  else
979  {
980  //enlarge width of new extent, ensuring the map center stays the same
981  double newWidth = currentWidthHeightRatio * newExtent.height();
982  double deltaWidth = newWidth - newExtent.width();
983  newExtent.setXMinimum( newExtent.xMinimum() - deltaWidth / 2 );
984  newExtent.setXMaximum( newExtent.xMaximum() + deltaWidth / 2 );
985  }
986 
987  *currentMapExtent() = newExtent;
988  }
989 
990  //now refresh scale, as this potentially overrides extents
991 
992  //data defined map scale set?
994  {
995  bool ok;
996  double scaleD = exprVal.toDouble( &ok );
997  QgsDebugMsg( QString( "exprVal Map Scale:%1" ).arg( scaleD ) );
998  if ( ok )
999  {
1000  setNewScale( scaleD, false );
1001  newExtent = *currentMapExtent();
1002  }
1003  }
1004 
1005  if ( useDdXMax || useDdXMin || useDdYMax || useDdYMin )
1006  {
1007  //if only one of min/max was set for either x or y, then make sure our extent is locked on that value
1008  //as we can do this without altering the scale
1009  if ( useDdXMin && !useDdXMax )
1010  {
1011  double xMax = currentMapExtent()->xMaximum() - ( currentMapExtent()->xMinimum() - minXD );
1012  newExtent.setXMinimum( minXD );
1013  newExtent.setXMaximum( xMax );
1014  }
1015  else if ( !useDdXMin && useDdXMax )
1016  {
1017  double xMin = currentMapExtent()->xMinimum() - ( currentMapExtent()->xMaximum() - maxXD );
1018  newExtent.setXMinimum( xMin );
1019  newExtent.setXMaximum( maxXD );
1020  }
1021  if ( useDdYMin && !useDdYMax )
1022  {
1023  double yMax = currentMapExtent()->yMaximum() - ( currentMapExtent()->yMinimum() - minYD );
1024  newExtent.setYMinimum( minYD );
1025  newExtent.setYMaximum( yMax );
1026  }
1027  else if ( !useDdYMin && useDdYMax )
1028  {
1029  double yMin = currentMapExtent()->yMinimum() - ( currentMapExtent()->yMaximum() - maxYD );
1030  newExtent.setYMinimum( yMin );
1031  newExtent.setYMaximum( maxYD );
1032  }
1033 
1034  if ( newExtent != *currentMapExtent() )
1035  {
1036  *currentMapExtent() = newExtent;
1037  }
1038  }
1039 
1040  //lastly, map rotation overrides all
1041  double mapRotation = mMapRotation;
1042 
1043  //data defined map rotation set?
1045  {
1046  bool ok;
1047  double rotationD = exprVal.toDouble( &ok );
1048  QgsDebugMsg( QString( "exprVal Map Rotation:%1" ).arg( rotationD ) );
1049  if ( ok )
1050  {
1051  mapRotation = rotationD;
1052  }
1053  }
1054 
1055  if ( mEvaluatedMapRotation != mapRotation )
1056  {
1058  emit mapRotationChanged( mapRotation );
1059  }
1060 
1061 }
1062 
1064 {
1065  if ( !mUpdatesEnabled )
1066  {
1067  return;
1068  }
1069 
1071  {
1072  cache();
1073  }
1075 }
1076 
1078 {
1079  QStringList layers = mComposition->mapSettings().layers();
1080 
1081  QStringList::const_iterator layer_it = layers.constBegin();
1082  QgsMapLayer* currentLayer = 0;
1083 
1084  for ( ; layer_it != layers.constEnd(); ++layer_it )
1085  {
1086  currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *layer_it );
1087  if ( currentLayer )
1088  {
1089  QgsRasterLayer* currentRasterLayer = qobject_cast<QgsRasterLayer *>( currentLayer );
1090  if ( currentRasterLayer )
1091  {
1092  const QgsRasterDataProvider* rasterProvider = 0;
1093  if (( rasterProvider = currentRasterLayer->dataProvider() ) )
1094  {
1095  if ( rasterProvider->name() == "wms" )
1096  {
1097  return true;
1098  }
1099  }
1100  }
1101  }
1102  }
1103  return false;
1104 }
1105 
1107 {
1108  // check if map contains advanced effects like blend modes, or flattened layers for transparency
1109 
1110  QStringList layers = mComposition->mapSettings().layers();
1111 
1112  QStringList::const_iterator layer_it = layers.constBegin();
1113  QgsMapLayer* currentLayer = 0;
1114 
1115  for ( ; layer_it != layers.constEnd(); ++layer_it )
1116  {
1117  currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *layer_it );
1118  if ( currentLayer )
1119  {
1120  if ( currentLayer->blendMode() != QPainter::CompositionMode_SourceOver )
1121  {
1122  return true;
1123  }
1124  // if vector layer, check labels and feature blend mode
1125  QgsVectorLayer* currentVectorLayer = qobject_cast<QgsVectorLayer *>( currentLayer );
1126  if ( currentVectorLayer )
1127  {
1128  if ( currentVectorLayer->layerTransparency() != 0 )
1129  {
1130  return true;
1131  }
1132  if ( currentVectorLayer->featureBlendMode() != QPainter::CompositionMode_SourceOver )
1133  {
1134  return true;
1135  }
1136  // check label blend modes
1137  if ( QgsPalLabeling::staticWillUseLayer( currentVectorLayer ) )
1138  {
1139  // Check all label blending properties
1140  QgsPalLayerSettings layerSettings = QgsPalLayerSettings::fromLayer( currentVectorLayer );
1141  if (( layerSettings.blendMode != QPainter::CompositionMode_SourceOver ) ||
1142  ( layerSettings.bufferSize != 0 && layerSettings.bufferBlendMode != QPainter::CompositionMode_SourceOver ) ||
1143  ( layerSettings.shadowDraw && layerSettings.shadowBlendMode != QPainter::CompositionMode_SourceOver ) ||
1144  ( layerSettings.shapeDraw && layerSettings.shapeBlendMode != QPainter::CompositionMode_SourceOver ) )
1145  {
1146  return true;
1147  }
1148  }
1149  }
1150  }
1151  }
1152 
1153  return false;
1154 }
1155 
1157 {
1158  //connect signal from layer registry to update in case of new or deleted layers
1160  if ( layerRegistry )
1161  {
1162  connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( updateCachedImage() ) );
1163  connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( updateCachedImage() ) );
1164  }
1165 }
1166 
1167 bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
1168 {
1169  if ( elem.isNull() )
1170  {
1171  return false;
1172  }
1173 
1174  QDomElement composerMapElem = doc.createElement( "ComposerMap" );
1175  composerMapElem.setAttribute( "id", mId );
1176 
1177  //previewMode
1178  if ( mPreviewMode == Cache )
1179  {
1180  composerMapElem.setAttribute( "previewMode", "Cache" );
1181  }
1182  else if ( mPreviewMode == Render )
1183  {
1184  composerMapElem.setAttribute( "previewMode", "Render" );
1185  }
1186  else //rectangle
1187  {
1188  composerMapElem.setAttribute( "previewMode", "Rectangle" );
1189  }
1190 
1191  if ( mKeepLayerSet )
1192  {
1193  composerMapElem.setAttribute( "keepLayerSet", "true" );
1194  }
1195  else
1196  {
1197  composerMapElem.setAttribute( "keepLayerSet", "false" );
1198  }
1199 
1200  if ( mDrawCanvasItems )
1201  {
1202  composerMapElem.setAttribute( "drawCanvasItems", "true" );
1203  }
1204  else
1205  {
1206  composerMapElem.setAttribute( "drawCanvasItems", "false" );
1207  }
1208 
1209  //extent
1210  QDomElement extentElem = doc.createElement( "Extent" );
1211  extentElem.setAttribute( "xmin", qgsDoubleToString( mExtent.xMinimum() ) );
1212  extentElem.setAttribute( "xmax", qgsDoubleToString( mExtent.xMaximum() ) );
1213  extentElem.setAttribute( "ymin", qgsDoubleToString( mExtent.yMinimum() ) );
1214  extentElem.setAttribute( "ymax", qgsDoubleToString( mExtent.yMaximum() ) );
1215  composerMapElem.appendChild( extentElem );
1216 
1217  //map rotation
1218  composerMapElem.setAttribute( "mapRotation", QString::number( mMapRotation ) );
1219 
1220  //layer set
1221  QDomElement layerSetElem = doc.createElement( "LayerSet" );
1222  QStringList::const_iterator layerIt = mLayerSet.constBegin();
1223  for ( ; layerIt != mLayerSet.constEnd(); ++layerIt )
1224  {
1225  QDomElement layerElem = doc.createElement( "Layer" );
1226  QDomText layerIdText = doc.createTextNode( *layerIt );
1227  layerElem.appendChild( layerIdText );
1228  layerSetElem.appendChild( layerElem );
1229  }
1230  composerMapElem.appendChild( layerSetElem );
1231 
1232  //write a dummy "Grid" element to prevent crashes on pre 2.5 versions (refs #10905)
1233  QDomElement gridElem = doc.createElement( "Grid" );
1234  composerMapElem.appendChild( gridElem );
1235 
1236  //grids
1237  QList< QgsComposerMapGrid* >::const_iterator gridIt = mGrids.constBegin();
1238  for ( ; gridIt != mGrids.constEnd(); ++gridIt )
1239  {
1240  ( *gridIt )->writeXML( composerMapElem, doc );
1241  }
1242 
1243  //overviews
1244  QList< QgsComposerMapOverview* >::const_iterator overviewIt = mOverviews.constBegin();
1245  for ( ; overviewIt != mOverviews.constEnd(); ++overviewIt )
1246  {
1247  ( *overviewIt )->writeXML( composerMapElem, doc );
1248  }
1249 
1250  //atlas
1251  QDomElement atlasElem = doc.createElement( "AtlasMap" );
1252  atlasElem.setAttribute( "atlasDriven", mAtlasDriven );
1253  atlasElem.setAttribute( "scalingMode", mAtlasScalingMode );
1254  atlasElem.setAttribute( "margin", qgsDoubleToString( mAtlasMargin ) );
1255  composerMapElem.appendChild( atlasElem );
1256 
1257  elem.appendChild( composerMapElem );
1258  return _writeXML( composerMapElem, doc );
1259 }
1260 
1261 bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& doc )
1262 {
1263  if ( itemElem.isNull() )
1264  {
1265  return false;
1266  }
1267 
1268  removeGrids();
1269  removeOverviews();
1270 
1271  QString idRead = itemElem.attribute( "id", "not found" );
1272  if ( idRead != "not found" )
1273  {
1274  mId = idRead.toInt();
1275  }
1277 
1278  //previewMode
1279  QString previewMode = itemElem.attribute( "previewMode" );
1280  if ( previewMode == "Cache" )
1281  {
1282  mPreviewMode = Cache;
1283  }
1284  else if ( previewMode == "Render" )
1285  {
1286  mPreviewMode = Render;
1287  }
1288  else
1289  {
1291  }
1292 
1293  //extent
1294  QDomNodeList extentNodeList = itemElem.elementsByTagName( "Extent" );
1295  if ( extentNodeList.size() > 0 )
1296  {
1297  QDomElement extentElem = extentNodeList.at( 0 ).toElement();
1298  double xmin, xmax, ymin, ymax;
1299  xmin = extentElem.attribute( "xmin" ).toDouble();
1300  xmax = extentElem.attribute( "xmax" ).toDouble();
1301  ymin = extentElem.attribute( "ymin" ).toDouble();
1302  ymax = extentElem.attribute( "ymax" ).toDouble();
1303  setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
1304  }
1305 
1306  //map rotation
1307  if ( itemElem.attribute( "mapRotation", "0" ).toDouble() != 0 )
1308  {
1309  mMapRotation = itemElem.attribute( "mapRotation", "0" ).toDouble();
1310  }
1311 
1312  //mKeepLayerSet flag
1313  QString keepLayerSetFlag = itemElem.attribute( "keepLayerSet" );
1314  if ( keepLayerSetFlag.compare( "true", Qt::CaseInsensitive ) == 0 )
1315  {
1316  mKeepLayerSet = true;
1317  }
1318  else
1319  {
1320  mKeepLayerSet = false;
1321  }
1322 
1323  QString drawCanvasItemsFlag = itemElem.attribute( "drawCanvasItems", "true" );
1324  if ( drawCanvasItemsFlag.compare( "true", Qt::CaseInsensitive ) == 0 )
1325  {
1326  mDrawCanvasItems = true;
1327  }
1328  else
1329  {
1330  mDrawCanvasItems = false;
1331  }
1332 
1333  //mLayerSet
1334  QDomNodeList layerSetNodeList = itemElem.elementsByTagName( "LayerSet" );
1335  QStringList layerSet;
1336  if ( layerSetNodeList.size() > 0 )
1337  {
1338  QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
1339  QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( "Layer" );
1340  for ( int i = 0; i < layerIdNodeList.size(); ++i )
1341  {
1342  layerSet << layerIdNodeList.at( i ).toElement().text();
1343  }
1344  }
1345  mLayerSet = layerSet;
1346 
1347  mDrawing = false;
1348  mNumCachedLayers = 0;
1349  mCacheUpdated = false;
1350 
1351  //grids
1352  QDomNodeList mapGridNodeList = itemElem.elementsByTagName( "ComposerMapGrid" );
1353  for ( int i = 0; i < mapGridNodeList.size(); ++i )
1354  {
1355  QDomElement mapGridElem = mapGridNodeList.at( i ).toElement();
1356  QgsComposerMapGrid* mapGrid = new QgsComposerMapGrid( mapGridElem.attribute( "name" ), this );
1357  mapGrid->readXML( mapGridElem, doc );
1358  mGrids.append( mapGrid );
1359  }
1360 
1361  //load grid / grid annotation in old xml format
1362  //only do this if we don't have the newer ComposerMapGrid element, otherwise this will
1363  //be the dummy element created by QGIS >= 2.5 (refs #10905)
1364  QDomNodeList gridNodeList = itemElem.elementsByTagName( "Grid" );
1365  if ( mapGridNodeList.size() == 0 && gridNodeList.size() > 0 )
1366  {
1367  QDomElement gridElem = gridNodeList.at( 0 ).toElement();
1368  QgsComposerMapGrid* mapGrid = new QgsComposerMapGrid( tr( "Grid %1" ).arg( gridCount() + 1 ), this );
1369  mapGrid->setGridEnabled( gridElem.attribute( "show", "0" ) != "0" );
1370  mapGrid->setGridStyle( QgsComposerMap::GridStyle( gridElem.attribute( "gridStyle", "0" ).toInt() ) );
1371  mapGrid->setGridIntervalX( gridElem.attribute( "intervalX", "0" ).toDouble() );
1372  mapGrid->setGridIntervalY( gridElem.attribute( "intervalY", "0" ).toDouble() );
1373  mapGrid->setGridOffsetX( gridElem.attribute( "offsetX", "0" ).toDouble() );
1374  mapGrid->setGridOffsetY( gridElem.attribute( "offsetY", "0" ).toDouble() );
1375  mapGrid->setCrossLength( gridElem.attribute( "crossLength", "3" ).toDouble() );
1376  mapGrid->setGridFrameStyle(( QgsComposerMap::GridFrameStyle )gridElem.attribute( "gridFrameStyle", "0" ).toInt() );
1377  mapGrid->setGridFrameWidth( gridElem.attribute( "gridFrameWidth", "2.0" ).toDouble() );
1378  mapGrid->setGridFramePenSize( gridElem.attribute( "gridFramePenThickness", "0.5" ).toDouble() );
1379  mapGrid->setGridFramePenColor( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "framePenColor", "0,0,0" ) ) );
1380  mapGrid->setGridFrameFillColor1( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "frameFillColor1", "255,255,255,255" ) ) );
1381  mapGrid->setGridFrameFillColor2( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "frameFillColor2", "0,0,0,255" ) ) );
1382  mapGrid->setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) itemElem.attribute( "gridBlendMode", "0" ).toUInt() ) );
1383  QDomElement gridSymbolElem = gridElem.firstChildElement( "symbol" );
1384  QgsLineSymbolV2* lineSymbol = 0;
1385  if ( gridSymbolElem.isNull( ) )
1386  {
1387  //old project file, read penWidth /penColorRed, penColorGreen, penColorBlue
1388  lineSymbol = QgsLineSymbolV2::createSimple( QgsStringMap() );
1389  lineSymbol->setWidth( gridElem.attribute( "penWidth", "0" ).toDouble() );
1390  lineSymbol->setColor( QColor( gridElem.attribute( "penColorRed", "0" ).toInt(),
1391  gridElem.attribute( "penColorGreen", "0" ).toInt(),
1392  gridElem.attribute( "penColorBlue", "0" ).toInt() ) );
1393  }
1394  else
1395  {
1396  lineSymbol = dynamic_cast<QgsLineSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( gridSymbolElem ) );
1397  }
1398  mapGrid->setGridLineSymbol( lineSymbol );
1399 
1400  //annotation
1401  QDomNodeList annotationNodeList = gridElem.elementsByTagName( "Annotation" );
1402  if ( annotationNodeList.size() > 0 )
1403  {
1404  QDomElement annotationElem = annotationNodeList.at( 0 ).toElement();
1405  mapGrid->setShowGridAnnotation( annotationElem.attribute( "show", "0" ) != "0" );
1406  mapGrid->setGridAnnotationFormat( QgsComposerMap::GridAnnotationFormat( annotationElem.attribute( "format", "0" ).toInt() ) );
1407  mapGrid->setGridAnnotationPosition( QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "leftPosition", "0" ).toInt() ), QgsComposerMap::Left );
1408  mapGrid->setGridAnnotationPosition( QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "rightPosition", "0" ).toInt() ), QgsComposerMap::Right );
1409  mapGrid->setGridAnnotationPosition( QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "topPosition", "0" ).toInt() ), QgsComposerMap::Top );
1410  mapGrid->setGridAnnotationPosition( QgsComposerMap::GridAnnotationPosition( annotationElem.attribute( "bottomPosition", "0" ).toInt() ), QgsComposerMap::Bottom );
1411  mapGrid->setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "leftDirection", "0" ).toInt() ), QgsComposerMap::Left );
1412  mapGrid->setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "rightDirection", "0" ).toInt() ), QgsComposerMap::Right );
1413  mapGrid->setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "topDirection", "0" ).toInt() ), QgsComposerMap::Top );
1414  mapGrid->setGridAnnotationDirection( QgsComposerMap::GridAnnotationDirection( annotationElem.attribute( "bottomDirection", "0" ).toInt() ), QgsComposerMap::Bottom );
1415  mapGrid->setAnnotationFrameDistance( annotationElem.attribute( "frameDistance", "0" ).toDouble() );
1416  QFont annotationFont;
1417  annotationFont.fromString( annotationElem.attribute( "font", "" ) );
1418  mapGrid->setGridAnnotationFont( annotationFont );
1419  mapGrid->setGridAnnotationFontColor( QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "fontColor", "0,0,0,255" ) ) );
1420 
1421  mapGrid->setGridAnnotationPrecision( annotationElem.attribute( "precision", "3" ).toInt() );
1422  }
1423  mGrids.append( mapGrid );
1424  }
1425 
1426  //load overview in old xml format
1427  QDomElement overviewFrameElem = itemElem.firstChildElement( "overviewFrame" );
1428  if ( !overviewFrameElem.isNull() )
1429  {
1430  QgsComposerMapOverview* mapOverview = new QgsComposerMapOverview( tr( "Overview %1" ).arg( overviewCount() + 1 ), this );
1431 
1432  mapOverview->setFrameMap( overviewFrameElem.attribute( "overviewFrameMap", "-1" ).toInt() );
1433  mapOverview->setBlendMode( QgsMapRenderer::getCompositionMode(( QgsMapRenderer::BlendMode ) overviewFrameElem.attribute( "overviewBlendMode", "0" ).toUInt() ) );
1434  mapOverview->setInverted( overviewFrameElem.attribute( "overviewInverted" ).compare( "true", Qt::CaseInsensitive ) == 0 );
1435  mapOverview->setCentered( overviewFrameElem.attribute( "overviewCentered" ).compare( "true", Qt::CaseInsensitive ) == 0 );
1436 
1437  QgsFillSymbolV2* fillSymbol = 0;
1438  QDomElement overviewFrameSymbolElem = overviewFrameElem.firstChildElement( "symbol" );
1439  if ( !overviewFrameSymbolElem.isNull() )
1440  {
1441  fillSymbol = dynamic_cast<QgsFillSymbolV2*>( QgsSymbolLayerV2Utils::loadSymbol( overviewFrameSymbolElem ) );
1442  mapOverview->setFrameSymbol( fillSymbol );
1443  }
1444  }
1445 
1446  //overviews
1447  QDomNodeList mapOverviewNodeList = itemElem.elementsByTagName( "ComposerMapOverview" );
1448  for ( int i = 0; i < mapOverviewNodeList.size(); ++i )
1449  {
1450  QDomElement mapOverviewElem = mapOverviewNodeList.at( i ).toElement();
1451  QgsComposerMapOverview* mapOverview = new QgsComposerMapOverview( mapOverviewElem.attribute( "name" ), this );
1452  mapOverview->readXML( mapOverviewElem, doc );
1453  mOverviews.append( mapOverview );
1454  }
1455 
1456  //atlas
1457  QDomNodeList atlasNodeList = itemElem.elementsByTagName( "AtlasMap" );
1458  if ( atlasNodeList.size() > 0 )
1459  {
1460  QDomElement atlasElem = atlasNodeList.at( 0 ).toElement();
1461  mAtlasDriven = ( atlasElem.attribute( "atlasDriven", "0" ) != "0" );
1462  if ( atlasElem.hasAttribute( "fixedScale" ) ) // deprecated XML
1463  {
1464  mAtlasScalingMode = ( atlasElem.attribute( "fixedScale", "0" ) != "0" ) ? Fixed : Auto;
1465  }
1466  else if ( atlasElem.hasAttribute( "scalingMode" ) )
1467  {
1468  mAtlasScalingMode = static_cast<AtlasScalingMode>( atlasElem.attribute( "scalingMode" ).toInt() );
1469  }
1470  mAtlasMargin = atlasElem.attribute( "margin", "0.1" ).toDouble();
1471  }
1472 
1473  //restore general composer item properties
1474  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
1475  if ( composerItemList.size() > 0 )
1476  {
1477  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
1478 
1479  if ( composerItemElem.attribute( "rotation", "0" ).toDouble() != 0 )
1480  {
1481  //in versions prior to 2.1 map rotation was stored in the rotation attribute
1482  mMapRotation = composerItemElem.attribute( "rotation", "0" ).toDouble();
1483  }
1484 
1485  _readXML( composerItemElem, doc );
1486  }
1487 
1489  emit itemChanged();
1490  return true;
1491 }
1492 
1494 {
1496 }
1497 
1499 {
1500  if ( mLayerSet.size() < 1 )
1501  {
1502  return;
1503  }
1504 
1505  //if layer set is fixed, do a lookup in the layer registry to also find the non-visible layers
1506  QStringList currentLayerSet;
1507  if ( mKeepLayerSet )
1508  {
1509  currentLayerSet = QgsMapLayerRegistry::instance()->mapLayers().uniqueKeys();
1510  }
1511  else //only consider layers visible in the map
1512  {
1513  currentLayerSet = mComposition->mapSettings().layers();
1514  }
1515 
1516  for ( int i = mLayerSet.size() - 1; i >= 0; --i )
1517  {
1518  if ( !currentLayerSet.contains( mLayerSet.at( i ) ) )
1519  {
1520  mLayerSet.removeAt( i );
1521  }
1522  }
1523 }
1524 
1526 {
1527  if ( mGrids.size() < 1 )
1528  {
1529  QgsComposerMapGrid* grid = new QgsComposerMapGrid( tr( "Grid %1" ).arg( 1 ), this );
1530  mGrids.push_back( grid );
1531  }
1532  return mGrids.at( 0 );
1533 }
1534 
1536 {
1537  return const_cast<QgsComposerMap*>( this )->firstMapGrid();
1538 }
1539 
1541 {
1543  g->setGridStyle( style );
1544 }
1545 
1547 {
1549  return g->gridStyle();
1550 }
1551 
1552 void QgsComposerMap::setGridIntervalX( double interval )
1553 {
1555  g->setGridIntervalX( interval );
1556 }
1557 
1559 {
1561  return g->gridIntervalX();
1562 }
1563 
1564 void QgsComposerMap::setGridIntervalY( double interval )
1565 {
1567  g->setGridIntervalY( interval );
1568 }
1569 
1571 {
1573  return g->gridIntervalY();
1574 }
1575 
1576 void QgsComposerMap::setGridOffsetX( double offset )
1577 {
1579  g->setGridOffsetX( offset );
1580 }
1581 
1583 {
1585  return g->gridOffsetX();
1586 }
1587 
1588 void QgsComposerMap::setGridOffsetY( double offset )
1589 {
1591  g->setGridOffsetY( offset );
1592 }
1593 
1595 {
1597  return g->gridOffsetY();
1598 }
1599 
1601 {
1603  g->setGridPenWidth( w );
1604 }
1605 
1606 void QgsComposerMap::setGridPenColor( const QColor& c )
1607 {
1609  g->setGridPenColor( c );
1610 }
1611 
1612 void QgsComposerMap::setGridPen( const QPen& p )
1613 {
1615  g->setGridPen( p );
1616 }
1617 
1619 {
1621  return g->gridPen();
1622 }
1623 
1625 {
1627  g->setGridAnnotationFont( f );
1628 }
1629 
1631 {
1633  return g->gridAnnotationFont();
1634 }
1635 
1637 {
1640 }
1641 
1643 {
1645  return g->gridAnnotationFontColor();
1646 }
1647 
1649 {
1652 }
1653 
1655 {
1657  return g->gridAnnotationPrecision();
1658 }
1659 
1661 {
1663  g->setShowGridAnnotation( show );
1664 }
1665 
1667 {
1669  return g->showGridAnnotation();
1670 }
1671 
1673 {
1675  g->setGridAnnotationPosition( p, border );
1676 }
1677 
1679 {
1681  return g->gridAnnotationPosition( border );
1682 }
1683 
1685 {
1688 }
1689 
1691 {
1693  return g->annotationFrameDistance();
1694 }
1695 
1697 {
1699  g->setGridAnnotationDirection( d, border );
1700 }
1701 
1703 {
1705  return g->gridAnnotationDirection( border );
1706 }
1707 
1709 {
1711  g->setGridAnnotationFormat( f );
1712 }
1713 
1715 {
1717  return g->gridAnnotationFormat();
1718 }
1719 
1721 {
1723  g->setGridFrameStyle( style );
1724 }
1725 
1727 {
1729  return g->gridFrameStyle();
1730 }
1731 
1733 {
1735  g->setGridFrameWidth( w );
1736 }
1737 
1739 {
1741  return g->gridFrameWidth();
1742 }
1743 
1745 {
1747  g->setGridFramePenSize( w );
1748 }
1749 
1751 {
1753  return g->gridFramePenSize();
1754 }
1755 
1757 {
1759  g->setGridFramePenColor( c );
1760 }
1761 
1763 {
1765  return g->gridFramePenColor();
1766 }
1767 
1769 {
1771  g->setGridFrameFillColor1( c );
1772 }
1773 
1775 {
1777  return g->gridFrameFillColor1();
1778 }
1779 
1781 {
1783  g->setGridFrameFillColor2( c );
1784 }
1785 
1787 {
1789  return g->gridFrameFillColor2();
1790 }
1791 
1793 {
1795  g->setCrossLength( l );
1796 }
1797 
1799 {
1801  return g->crossLength();
1802 }
1803 
1805 {
1806  qDeleteAll( mGrids );
1807  mGrids.clear();
1808 }
1809 
1810 void QgsComposerMap::drawGrids( QPainter* p )
1811 {
1812  QList< QgsComposerMapGrid* >::const_iterator gridIt = mGrids.constBegin();
1813  for ( ; gridIt != mGrids.constEnd(); ++gridIt )
1814  {
1815  ( *gridIt )->drawGrid( p );
1816  }
1817 }
1818 
1820 {
1821  if ( mOverviews.size() < 1 )
1822  {
1823  QgsComposerMapOverview* overview = new QgsComposerMapOverview( tr( "Overview %1" ).arg( 1 ), this );
1824  mOverviews.push_back( overview );
1825  }
1826  return mOverviews.at( 0 );
1827 }
1828 
1830 {
1831  return const_cast<QgsComposerMap*>( this )->firstMapOverview();
1832 }
1833 
1835 {
1836  qDeleteAll( mOverviews );
1837  mOverviews.clear();
1838 }
1839 
1841 {
1842  QList< QgsComposerMapOverview* >::const_iterator overviewIt = mOverviews.constBegin();
1843  for ( ; overviewIt != mOverviews.constEnd(); ++overviewIt )
1844  {
1845  ( *overviewIt )->drawOverview( p );
1846  }
1847 }
1848 
1849 /*QString QgsComposerMap::gridAnnotationString( double value, AnnotationCoordinate coord ) const
1850 {
1851  if ( mGridAnnotationFormat == Decimal )
1852  {
1853  return QString::number( value, 'f', mGridAnnotationPrecision );
1854  }
1855 
1856  QgsPoint p;
1857  p.setX( coord == Longitude ? value : 0 );
1858  p.setY( coord == Longitude ? 0 : value );
1859 
1860  QString annotationString;
1861  if ( mGridAnnotationFormat == DegreeMinute )
1862  {
1863  annotationString = p.toDegreesMinutes( mGridAnnotationPrecision );
1864  }
1865  else //DegreeMinuteSecond
1866  {
1867  annotationString = p.toDegreesMinutesSeconds( mGridAnnotationPrecision );
1868  }
1869 
1870  QStringList split = annotationString.split( "," );
1871  if ( coord == Longitude )
1872  {
1873  return split.at( 0 );
1874  }
1875  else
1876  {
1877  if ( split.size() < 2 )
1878  {
1879  return "";
1880  }
1881  return split.at( 1 );
1882  }
1883 }*/
1884 
1885 void QgsComposerMap::setGridBlendMode( QPainter::CompositionMode blendMode )
1886 {
1888  g->setBlendMode( blendMode );
1889 }
1890 
1891 QPainter::CompositionMode QgsComposerMap::gridBlendMode() const
1892 {
1894  return g->blendMode();
1895 }
1896 
1898 {
1899  return mCurrentRectangle;
1900 }
1901 
1903 {
1904  QRectF rectangle = rect();
1905  double frameExtension = mFrame ? pen().widthF() / 2.0 : 0.0;
1906  double maxGridExtension = 0;
1907 
1908  QList< QgsComposerMapGrid* >::const_iterator it = mGrids.constBegin();
1909  for ( ; it != mGrids.constEnd(); ++it )
1910  {
1911  maxGridExtension = qMax( maxGridExtension, ( *it )->maxExtension() );
1912  }
1913  double maxExtension = qMax( frameExtension, maxGridExtension );
1914 
1915  rectangle.setLeft( rectangle.left() - maxExtension );
1916  rectangle.setRight( rectangle.right() + maxExtension );
1917  rectangle.setTop( rectangle.top() - maxExtension );
1918  rectangle.setBottom( rectangle.bottom() + maxExtension );
1919  if ( rectangle != mCurrentRectangle )
1920  {
1921  prepareGeometryChange();
1922  mCurrentRectangle = rectangle;
1923  }
1924 }
1925 
1927 {
1928  QgsComposerItem::setFrameOutlineWidth( outlineWidth );
1930 }
1931 
1933 {
1934  double dx = mXOffset;
1935  double dy = mYOffset;
1936  transformShift( dx, dy );
1937  return QgsRectangle( currentMapExtent()->xMinimum() - dx, currentMapExtent()->yMinimum() - dy, currentMapExtent()->xMaximum() - dx, currentMapExtent()->yMaximum() - dy );
1938 }
1939 
1941 {
1942  double dx = mXOffset;
1943  double dy = mYOffset;
1944  //qWarning("offset");
1945  //qWarning(QString::number(dx).toLocal8Bit().data());
1946  //qWarning(QString::number(dy).toLocal8Bit().data());
1947  transformShift( dx, dy );
1948  //qWarning("transformed:");
1949  //qWarning(QString::number(dx).toLocal8Bit().data());
1950  //qWarning(QString::number(dy).toLocal8Bit().data());
1951  QPolygonF poly = visibleExtentPolygon();
1952  poly.translate( -dx, -dy );
1953  return poly;
1954 }
1955 
1956 void QgsComposerMap::mapPolygon( const QgsRectangle& extent, QPolygonF& poly ) const
1957 {
1958  poly.clear();
1959  if ( mEvaluatedMapRotation == 0 )
1960  {
1961  poly << QPointF( extent.xMinimum(), extent.yMaximum() );
1962  poly << QPointF( extent.xMaximum(), extent.yMaximum() );
1963  poly << QPointF( extent.xMaximum(), extent.yMinimum() );
1964  poly << QPointF( extent.xMinimum(), extent.yMinimum() );
1965  return;
1966  }
1967 
1968  //there is rotation
1969  QgsPoint rotationPoint(( extent.xMaximum() + extent.xMinimum() ) / 2.0, ( extent.yMaximum() + extent.yMinimum() ) / 2.0 );
1970  double dx, dy; //x-, y- shift from rotation point to corner point
1971 
1972  //top left point
1973  dx = rotationPoint.x() - extent.xMinimum();
1974  dy = rotationPoint.y() - extent.yMaximum();
1976  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1977 
1978  //top right point
1979  dx = rotationPoint.x() - extent.xMaximum();
1980  dy = rotationPoint.y() - extent.yMaximum();
1982  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1983 
1984  //bottom right point
1985  dx = rotationPoint.x() - extent.xMaximum();
1986  dy = rotationPoint.y() - extent.yMinimum();
1988  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1989 
1990  //bottom left point
1991  dx = rotationPoint.x() - extent.xMinimum();
1992  dy = rotationPoint.y() - extent.yMinimum();
1994  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1995 }
1996 
1998 {
1999  QPolygonF poly;
2000  mapPolygon( *currentMapExtent(), poly );
2001  return poly;
2002 }
2003 
2005 {
2006  if ( !QgsComposerItem::id().isEmpty() )
2007  {
2008  return QgsComposerItem::id();
2009  }
2010 
2011  return tr( "Map %1" ).arg( mId );
2012 }
2013 
2015 {
2016  mGrids.append( grid );
2018 }
2019 
2020 void QgsComposerMap::removeGrid( const QString& name )
2021 {
2022  for ( int i = mGrids.size() - 1; i >= 0; --i )
2023  {
2024  if ( mGrids.at( i )->name() == name )
2025  {
2026  delete mGrids.takeAt( i );
2027  }
2028  }
2029 }
2030 
2031 void QgsComposerMap::moveGridUp( const QString& name )
2032 {
2033  QgsComposerMapGrid* grid = mapGrid( name );
2034  if ( !grid )
2035  {
2036  return;
2037  }
2038 
2039  int index = mGrids.indexOf( grid );
2040  if ( index >= mGrids.size() - 1 )
2041  {
2042  return;
2043  }
2044  mGrids.swap( index, index + 1 );
2045  update();
2046 }
2047 
2048 void QgsComposerMap::moveGridDown( const QString& name )
2049 {
2050  QgsComposerMapGrid* grid = mapGrid( name );
2051  if ( !grid )
2052  {
2053  return;
2054  }
2055 
2056  int index = mGrids.indexOf( grid );
2057  if ( index < 1 )
2058  {
2059  return;
2060  }
2061  mGrids.swap( index, index - 1 );
2062  update();
2063 }
2064 
2065 const QgsComposerMapGrid* QgsComposerMap::constMapGrid( const QString& id ) const
2066 {
2067  QList< QgsComposerMapGrid* >::const_iterator it = mGrids.constBegin();
2068  for ( ; it != mGrids.constEnd(); ++it )
2069  {
2070  if (( *it )->id() == id )
2071  {
2072  return ( *it );
2073  }
2074  }
2075 
2076  return 0;
2077 }
2078 
2079 QgsComposerMapGrid* QgsComposerMap::mapGrid( const QString& id ) const
2080 {
2081  QList< QgsComposerMapGrid* >::const_iterator it = mGrids.begin();
2082  for ( ; it != mGrids.end(); ++it )
2083  {
2084  if (( *it )->id() == id )
2085  {
2086  return ( *it );
2087  }
2088  }
2089 
2090  return 0;
2091 }
2092 
2093 QList< const QgsComposerMapGrid* > QgsComposerMap::mapGrids() const
2094 {
2095  QList< const QgsComposerMapGrid* > list;
2096  QList< QgsComposerMapGrid* >::const_iterator it = mGrids.begin();
2097  for ( ; it != mGrids.end(); ++it )
2098  {
2099  list.append( *it );
2100  }
2101  return list;
2102 }
2103 
2105 {
2106  mOverviews.append( overview );
2107 }
2108 
2109 void QgsComposerMap::removeOverview( const QString &name )
2110 {
2111  for ( int i = mOverviews.size() - 1; i >= 0; --i )
2112  {
2113  if ( mOverviews.at( i )->name() == name )
2114  {
2115  delete mOverviews.takeAt( i );
2116  }
2117  }
2118 }
2119 
2120 void QgsComposerMap::moveOverviewUp( const QString &name )
2121 {
2122  QgsComposerMapOverview* overview = mapOverview( name );
2123  if ( !overview )
2124  {
2125  return;
2126  }
2127 
2128  int index = mOverviews.indexOf( overview );
2129  if ( index >= mOverviews.size() - 1 )
2130  {
2131  return;
2132  }
2133  mOverviews.swap( index, index + 1 );
2134  update();
2135 }
2136 
2137 void QgsComposerMap::moveOverviewDown( const QString &name )
2138 {
2139  QgsComposerMapOverview* overview = mapOverview( name );
2140  if ( !overview )
2141  {
2142  return;
2143  }
2144 
2145  int index = mOverviews.indexOf( overview );
2146  if ( index < 1 )
2147  {
2148  return;
2149  }
2150  mOverviews.swap( index, index - 1 );
2151  update();
2152 }
2153 
2155 {
2156  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.constBegin();
2157  for ( ; it != mOverviews.constEnd(); ++it )
2158  {
2159  if (( *it )->id() == id )
2160  {
2161  return ( *it );
2162  }
2163  }
2164 
2165  return 0;
2166 }
2167 
2169 {
2170  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.begin();
2171  for ( ; it != mOverviews.end(); ++it )
2172  {
2173  if (( *it )->id() == id )
2174  {
2175  return ( *it );
2176  }
2177  }
2178 
2179  return 0;
2180 }
2181 
2182 QList<QgsComposerMapOverview *> QgsComposerMap::mapOverviews() const
2183 {
2184  QList< QgsComposerMapOverview* > list;
2185  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.begin();
2186  for ( ; it != mOverviews.end(); ++it )
2187  {
2188  list.append( *it );
2189  }
2190  return list;
2191 }
2192 
2194 {
2195  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.begin();
2196  for ( ; it != mOverviews.end(); ++it )
2197  {
2198  ( *it )->connectSignals();
2199  }
2200 }
2201 
2203 {
2204  QgsRectangle newExtent = *currentMapExtent();
2205  if ( mEvaluatedMapRotation == 0 )
2206  {
2207  extent = newExtent;
2208  }
2209  else
2210  {
2211  QPolygonF poly;
2212  mapPolygon( newExtent, poly );
2213  QRectF bRect = poly.boundingRect();
2214  extent.setXMinimum( bRect.left() );
2215  extent.setXMaximum( bRect.right() );
2216  extent.setYMinimum( bRect.top() );
2217  extent.setYMaximum( bRect.bottom() );
2218  }
2219 }
2220 
2222 {
2223  double extentWidth = currentMapExtent()->width();
2224  if ( extentWidth <= 0 )
2225  {
2226  return 1;
2227  }
2228  return rect().width() / extentWidth;
2229 }
2230 
2232 {
2234  overview->setFrameMap( mapId );
2235 }
2236 
2238 {
2239  const QgsComposerMapOverview* overview = constFirstMapOverview();
2240  return overview->frameMapId();
2241 }
2242 
2244 {
2245  //updates data defined properties and redraws item to match
2246  if ( property == QgsComposerObject::MapRotation || property == QgsComposerObject::MapScale ||
2247  property == QgsComposerObject::MapXMin || property == QgsComposerObject::MapYMin ||
2248  property == QgsComposerObject::MapXMax || property == QgsComposerObject::MapYMax ||
2249  property == QgsComposerObject::AllProperties )
2250  {
2252  emit itemChanged();
2253  emit extentChanged();
2254  }
2255 
2256  //force redraw
2257  cache();
2258 
2260 }
2261 
2263 {
2265  overview->setFrameSymbol( symbol );
2266 }
2267 
2269 {
2271  return overview->frameSymbol();
2272 }
2273 
2274 QPainter::CompositionMode QgsComposerMap::overviewBlendMode() const
2275 {
2276  const QgsComposerMapOverview* overview = constFirstMapOverview();
2277  return overview->blendMode();
2278 }
2279 
2280 void QgsComposerMap::setOverviewBlendMode( QPainter::CompositionMode blendMode )
2281 {
2283  overview->setBlendMode( blendMode );
2284 }
2285 
2287 {
2288  const QgsComposerMapOverview* overview = constFirstMapOverview();
2289  return overview->inverted();
2290 }
2291 
2293 {
2295  overview->setInverted( inverted );
2296 }
2297 
2299 {
2300  const QgsComposerMapOverview* overview = constFirstMapOverview();
2301  return overview->centered();
2302 }
2303 
2305 {
2307  overview->setCentered( centered );
2308  //overviewExtentChanged();
2309 }
2310 
2312 {
2314  g->setGridLineSymbol( symbol );
2315 }
2316 
2318 {
2320  return g->gridLineSymbol();
2321 }
2322 
2324 {
2326  g->setGridEnabled( enabled );
2327 }
2328 
2330 {
2332  return g->gridEnabled();
2333 }
2334 
2335 void QgsComposerMap::transformShift( double& xShift, double& yShift ) const
2336 {
2337  double mmToMapUnits = 1.0 / mapUnitsToMM();
2338  double dxScaled = xShift * mmToMapUnits;
2339  double dyScaled = - yShift * mmToMapUnits;
2340 
2341  QgsComposerUtils::rotate( mEvaluatedMapRotation, dxScaled, dyScaled );
2342 
2343  xShift = dxScaled;
2344  yShift = dyScaled;
2345 }
2346 
2347 QPointF QgsComposerMap::mapToItemCoords( const QPointF& mapCoords ) const
2348 {
2349  QPolygonF mapPoly = transformedMapPolygon();
2350  if ( mapPoly.size() < 1 )
2351  {
2352  return QPointF( 0, 0 );
2353  }
2354 
2355  QgsRectangle tExtent = transformedExtent();
2356  QgsPoint rotationPoint(( tExtent.xMaximum() + tExtent.xMinimum() ) / 2.0, ( tExtent.yMaximum() + tExtent.yMinimum() ) / 2.0 );
2357  double dx = mapCoords.x() - rotationPoint.x();
2358  double dy = mapCoords.y() - rotationPoint.y();
2360  QgsPoint backRotatedCoords( rotationPoint.x() + dx, rotationPoint.y() + dy );
2361 
2362  QgsRectangle unrotatedExtent = transformedExtent();
2363  double xItem = rect().width() * ( backRotatedCoords.x() - unrotatedExtent.xMinimum() ) / unrotatedExtent.width();
2364  double yItem = rect().height() * ( 1 - ( backRotatedCoords.y() - unrotatedExtent.yMinimum() ) / unrotatedExtent.height() );
2365  return QPointF( xItem, yItem );
2366 }
2367 
2369 {
2370  if ( p.x() <= pen().widthF() )
2371  {
2372  return Left;
2373  }
2374  else if ( p.x() >= ( rect().width() - pen().widthF() ) )
2375  {
2376  return Right;
2377  }
2378  else if ( p.y() <= pen().widthF() )
2379  {
2380  return Top;
2381  }
2382  else
2383  {
2384  return Bottom;
2385  }
2386 }
2387 
2388 void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
2389 {
2390  if ( !mMapCanvas || !mDrawCanvasItems )
2391  {
2392  return;
2393  }
2394 
2395  QList<QGraphicsItem*> itemList = mMapCanvas->items();
2396  if ( itemList.size() < 1 )
2397  {
2398  return;
2399  }
2400  QGraphicsItem* currentItem = 0;
2401 
2402  for ( int i = itemList.size() - 1; i >= 0; --i )
2403  {
2404  currentItem = itemList.at( i );
2405  //don't draw mapcanvasmap (has z value -10)
2406  if ( !currentItem || currentItem->data( 0 ).toString() != "AnnotationItem" )
2407  {
2408  continue;
2409  }
2410  drawCanvasItem( currentItem, painter, itemStyle );
2411  }
2412 }
2413 
2414 void QgsComposerMap::drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
2415 {
2416  if ( !item || !mMapCanvas || !item->isVisible() )
2417  {
2418  return;
2419  }
2420 
2421  painter->save();
2422  painter->setRenderHint( QPainter::Antialiasing );
2423 
2424  //determine scale factor according to graphics view dpi
2425  double scaleFactor = 1.0 / mMapCanvas->logicalDpiX() * 25.4;
2426 
2427  double itemX, itemY;
2428  QGraphicsItem* parent = item->parentItem();
2429  if ( !parent )
2430  {
2431  QPointF mapPos = composerMapPosForItem( item );
2432  itemX = mapPos.x();
2433  itemY = mapPos.y();
2434  }
2435  else //place item relative to the parent item
2436  {
2437  QPointF itemScenePos = item->scenePos();
2438  QPointF parentScenePos = parent->scenePos();
2439 
2440  QPointF mapPos = composerMapPosForItem( parent );
2441 
2442  itemX = mapPos.x() + ( itemScenePos.x() - parentScenePos.x() ) * scaleFactor;
2443  itemY = mapPos.y() + ( itemScenePos.y() - parentScenePos.y() ) * scaleFactor;
2444  }
2445  painter->translate( itemX, itemY );
2446 
2447  painter->scale( scaleFactor, scaleFactor );
2448 
2449  //a little trick to let the item know that the paint request comes from the composer
2450  item->setData( 1, "composer" );
2451  item->paint( painter, itemStyle, 0 );
2452  item->setData( 1, "" );
2453  painter->restore();
2454 }
2455 
2456 QPointF QgsComposerMap::composerMapPosForItem( const QGraphicsItem* item ) const
2457 {
2458  if ( !item || !mMapCanvas )
2459  {
2460  return QPointF( 0, 0 );
2461  }
2462 
2463  if ( currentMapExtent()->height() <= 0 || currentMapExtent()->width() <= 0 || mMapCanvas->width() <= 0 || mMapCanvas->height() <= 0 )
2464  {
2465  return QPointF( 0, 0 );
2466  }
2467 
2468  QRectF graphicsSceneRect = mMapCanvas->sceneRect();
2469  QPointF itemScenePos = item->scenePos();
2470  QgsRectangle mapRendererExtent = mComposition->mapSettings().visibleExtent();
2471 
2472  double mapX = itemScenePos.x() / graphicsSceneRect.width() * mapRendererExtent.width() + mapRendererExtent.xMinimum();
2473  double mapY = mapRendererExtent.yMaximum() - itemScenePos.y() / graphicsSceneRect.height() * mapRendererExtent.height();
2474  return mapToItemCoords( QPointF( mapX, mapY ) );
2475 }
2476 
2477 /*void QgsComposerMap::initGridAnnotationFormatFromProject()
2478 {
2479  QString format = QgsProject::instance()->readEntry( "PositionPrecision", "/DegreeFormat", "D" );
2480 
2481  bool degreeUnits = ( mComposition->mapSettings().mapUnits() == QGis::Degrees );
2482 
2483  if ( format == "DM" && degreeUnits )
2484  {
2485  mGridAnnotationFormat = DegreeMinute;
2486  }
2487  else if ( format == "DMS" && degreeUnits )
2488  {
2489  mGridAnnotationFormat = DegreeMinuteSecond;
2490  }
2491  else
2492  {
2493  mGridAnnotationFormat = Decimal;
2494  }
2495 }*/
2496 
2498 {
2499  if ( !mComposition )
2500  {
2501  return;
2502  }
2503 
2504  const QgsComposerMap* existingMap = mComposition->getComposerMapById( mId );
2505  if ( !existingMap )
2506  {
2507  return; //keep mId as it is still available
2508  }
2509 
2510  int maxId = -1;
2511  QList<const QgsComposerMap*> mapList = mComposition->composerMapItems();
2512  QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin();
2513  for ( ; mapIt != mapList.constEnd(); ++mapIt )
2514  {
2515  if (( *mapIt )->id() > maxId )
2516  {
2517  maxId = ( *mapIt )->id();
2518  }
2519  }
2520  mId = maxId + 1;
2521 }
2522 
2523 bool QgsComposerMap::imageSizeConsideringRotation( double& width, double& height ) const
2524 {
2525  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2529 }
2530 
2531 bool QgsComposerMap::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const
2532 {
2533  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2537 }
2538 
2539 void QgsComposerMap::sizeChangedByRotation( double& width, double& height )
2540 {
2541  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2545 }
2546 
2548 {
2549  mAtlasDriven = enabled;
2550 
2551  if ( !enabled )
2552  {
2553  //if not enabling the atlas, we still need to refresh the map extents
2554  //so that data defined extents and scale are recalculated
2556  }
2557 }
2558 
2560 {
2561  return mAtlasScalingMode == Fixed;
2562 }
2563 
2565 {
2566  // implicit : if set to false => auto scaling
2567  mAtlasScalingMode = fixed ? Fixed : Auto;
2568 }
2569 
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.
void setGridAnnotationFormat(QgsComposerMap::GridAnnotationFormat f)
void cache()
Create cache image.
bool showGridAnnotation() const
void removeGrid(const QString &name)
bool centered() const
Returns true if the extent is forced to center on the overview.
void setGridStyle(GridStyle style)
Sets coordinate grid style to solid or cross.
Q_DECL_DEPRECATED bool imageSizeConsideringRotation(double &width, double &height) const
Calculates width and hight of the picture (in mm) such that it fits into the item frame with the give...
QList< const QgsComposerMap * > composerMapItems() const
Returns pointers to all composer maps in the scene.
QMap< QgsComposerObject::DataDefinedProperty, QString > mDataDefinedNames
Map of data defined properties for the item to string name to use when exporting item to xml...
A item that forms part of a map composition.
void connectUpdateSlot()
Establishes signal/slot connection for update in case of layer change.
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:439
Border
Enum for different frame borders.
void drawGrids(QPainter *p)
QgsRectangle visibleExtent() const
Return the actual extent derived from requested extent that takes takes output image size into accoun...
void updateItem()
Updates item, with the possibility to do custom update for subclasses.
QPointF composerMapPosForItem(const QGraphicsItem *item) const
double annotationFrameDistance() const
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
void setGridIntervalX(double interval)
Sets coordinate interval in x-direction for composergrid.
AtlasScalingMode mAtlasScalingMode
Current atlas scaling mode.
QGraphicsView * mMapCanvas
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
bool hasCrsTransformEnabled() const
returns true if projections are enabled for this layer set
void mapRotationChanged(double newRotation)
Is emitted on rotation change to notify north arrow pictures.
static QgsPalLayerSettings fromLayer(QgsVectorLayer *layer)
QList< QgsComposerMapOverview * > mapOverviews() const
virtual QString displayName() const
Get item display name.
static QColor decodeColor(QString str)
virtual void drawFrame(QPainter *p)
Draw black frame around item.
void setGridFrameFillColor1(const QColor &c)
Sets first fill color for grid zebra frame.
void updateCachedImage()
Called if map canvas has changed.
Flags flags() const
Return combination of flags used for rendering.
DataDefinedProperty
Data defined properties for different item types.
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)
Refreshes a data defined property for the item by reevaluating the property's value and redrawing the...
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.
double x() const
Definition: qgspoint.h:110
void zoomContent(int delta, double x, double y)
Zoom content of map.
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
void zoomToExtent(const QgsRectangle &extent)
Zooms the map so that the specified extent is fully visible within the map item.
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)
Draws additional graphics on selected items.
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 for the map.
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
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
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.
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.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
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
QString qgsDoubleToString(const double &a, const int &precision=17)
Definition: qgis.h:316
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)