QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgscomposermap.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposermap.cpp
3  -------------------
4  begin : January 2005
5  copyright : (C) 2005 by Radim Blazek
6  email : blazek@itc.it
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgscomposermap.h"
19 #include "qgscomposermapgrid.h"
20 #include "qgscomposermapoverview.h"
21 #include "qgscomposition.h"
22 #include "qgscomposerutils.h"
23 #include "qgscoordinatetransform.h"
24 #include "qgslogger.h"
25 #include "qgsmaprenderer.h"
27 #include "qgsmaplayerregistry.h"
28 #include "qgsmaptopixel.h"
29 #include "qgsproject.h"
30 #include "qgsrasterlayer.h"
31 #include "qgsrendercontext.h"
32 #include "qgsscalecalculator.h"
33 #include "qgsvectorlayer.h"
34 #include "qgspallabeling.h"
35 #include "qgsexpression.h"
36 
37 #include "qgslabel.h"
38 #include "qgslabelattributes.h"
39 #include "qgssymbollayerv2utils.h" //for pointOnLineWithDistance
40 
41 #include <QGraphicsScene>
42 #include <QGraphicsView>
43 #include <QPainter>
44 #include <QSettings>
45 #include <cmath>
46 
47 QgsComposerMap::QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height )
48  : QgsComposerItem( x, y, width, height, composition )
49  , mGridStack( 0 )
50  , mMapRotation( 0 )
51  , mEvaluatedMapRotation( 0 )
52  , mKeepLayerSet( false )
53  , mUpdatesEnabled( true )
54  , mMapCanvas( 0 )
55  , mDrawCanvasItems( true )
56  , mAtlasDriven( false )
57  , mAtlasScalingMode( Auto )
58  , mAtlasMargin( 0.10 )
59 {
61 
62  mId = 0;
63  assignFreeId();
64 
66  mCurrentRectangle = rect();
67 
68  // Cache
69  mCacheUpdated = false;
70  mDrawing = false;
71 
72  //Offset
73  mXOffset = 0.0;
74  mYOffset = 0.0;
75 
76  //get the color for map canvas background and set map background color accordingly
77  int bgRedInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorRedPart", 255 );
78  int bgGreenInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorGreenPart", 255 );
79  int bgBlueInt = QgsProject::instance()->readNumEntry( "Gui", "/CanvasColorBluePart", 255 );
80  setBackgroundColor( QColor( bgRedInt, bgGreenInt, bgBlueInt ) );
81 
82  //calculate mExtent based on width/height ratio and map canvas extent
84 
85  init();
86 
87  setSceneRect( QRectF( x, y, width, height ) );
88 }
89 
91  : QgsComposerItem( 0, 0, 10, 10, composition )
92  , mGridStack( 0 )
93  , mMapRotation( 0 )
94  , mEvaluatedMapRotation( 0 )
95  , mKeepLayerSet( false )
96  , mUpdatesEnabled( true )
97  , mMapCanvas( 0 )
98  , mDrawCanvasItems( true )
99  , mAtlasDriven( false )
100  , mAtlasScalingMode( Auto )
101  , mAtlasMargin( 0.10 )
102 {
103  //Offset
104  mXOffset = 0.0;
105  mYOffset = 0.0;
106 
108  mId = mComposition->composerMapItems().size();
110  mCurrentRectangle = rect();
111 
112  init();
113 }
114 
116 {
117  mGridStack = new QgsComposerMapGridStack( this );
119 
120  setToolTip( tr( "Map %1" ).arg( mId ) );
121 
122  // data defined strings
123  mDataDefinedNames.insert( QgsComposerObject::MapRotation, QString( "dataDefinedMapRotation" ) );
124  mDataDefinedNames.insert( QgsComposerObject::MapScale, QString( "dataDefinedMapScale" ) );
125  mDataDefinedNames.insert( QgsComposerObject::MapXMin, QString( "dataDefinedMapXMin" ) );
126  mDataDefinedNames.insert( QgsComposerObject::MapYMin, QString( "dataDefinedMapYMin" ) );
127  mDataDefinedNames.insert( QgsComposerObject::MapXMax, QString( "dataDefinedMapXMax" ) );
128  mDataDefinedNames.insert( QgsComposerObject::MapYMax, QString( "dataDefinedMapYMax" ) );
129 }
130 
131 void QgsComposerMap::adjustExtentToItemShape( double itemWidth, double itemHeight, QgsRectangle& extent ) const
132 {
133  double itemWidthHeightRatio = itemWidth / itemHeight;
134  double newWidthHeightRatio = extent.width() / extent.height();
135 
136  if ( itemWidthHeightRatio <= newWidthHeightRatio )
137  {
138  //enlarge height of new extent, ensuring the map center stays the same
139  double newHeight = extent.width() / itemWidthHeightRatio;
140  double deltaHeight = newHeight - extent.height();
141  extent.setYMinimum( extent.yMinimum() - deltaHeight / 2 );
142  extent.setYMaximum( extent.yMaximum() + deltaHeight / 2 );
143  }
144  else
145  {
146  //enlarge width of new extent, ensuring the map center stays the same
147  double newWidth = itemWidthHeightRatio * extent.height();
148  double deltaWidth = newWidth - extent.width();
149  extent.setXMinimum( extent.xMinimum() - deltaWidth / 2 );
150  extent.setXMaximum( extent.xMaximum() + deltaWidth / 2 );
151  }
152 }
153 
155 {
156  removeOverviews();
157  delete mGridStack;
158 }
159 
160 /* This function is called by paint() and cache() to render the map. It does not override any functions
161 from QGraphicsItem. */
162 void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi, double* forceWidthScale )
163 {
164  Q_UNUSED( forceWidthScale );
165 
166  if ( !painter )
167  {
168  return;
169  }
170  if ( size.width() == 0 || size.height() == 0 )
171  {
172  //don't attempt to draw if size is invalid
173  return;
174  }
175 
176  const QgsMapSettings& ms = mComposition->mapSettings();
177 
178  QgsMapSettings jobMapSettings;
179  jobMapSettings.setExtent( extent );
180  jobMapSettings.setOutputSize( size.toSize() );
181  jobMapSettings.setOutputDpi( dpi );
182  jobMapSettings.setMapUnits( ms.mapUnits() );
183  jobMapSettings.setBackgroundColor( Qt::transparent );
184  jobMapSettings.setOutputImageFormat( ms.outputImageFormat() );
185 
186  //set layers to render
187  QStringList theLayerSet = layersToRender();
188  if ( -1 != mCurrentExportLayer )
189  {
190  //exporting with separate layers (eg, to svg layers), so we only want to render a single map layer
191  const int layerIdx = mCurrentExportLayer - ( hasBackground() ? 1 : 0 );
192  theLayerSet =
193  ( layerIdx >= 0 && layerIdx < theLayerSet.length() )
194  ? QStringList( theLayerSet[ theLayerSet.length() - layerIdx - 1 ] )
195  : QStringList(); //exporting decorations such as map frame/grid/overview, so no map layers required
196  }
197  jobMapSettings.setLayers( theLayerSet );
198  jobMapSettings.setDestinationCrs( ms.destinationCrs() );
199  jobMapSettings.setCrsTransformEnabled( ms.hasCrsTransformEnabled() );
200  jobMapSettings.setFlags( ms.flags() );
201  jobMapSettings.setFlag( QgsMapSettings::DrawSelection, false );
202 
205  {
206  //if outputing composer, disable optimisations like layer simplification
207  jobMapSettings.setFlag( QgsMapSettings::UseRenderingOptimization, false );
208  }
209 
210  //update $map variable. Use QgsComposerItem's id since that is user-definable
212 
213  // composer-specific overrides of flags
214  jobMapSettings.setFlag( QgsMapSettings::ForceVectorOutput ); // force vector output (no caching of marker images etc.)
215  jobMapSettings.setFlag( QgsMapSettings::DrawEditingInfo, false );
216  jobMapSettings.setFlag( QgsMapSettings::UseAdvancedEffects, mComposition->useAdvancedEffects() ); // respect the composition's useAdvancedEffects flag
217 
218  // render
219  QgsMapRendererCustomPainterJob job( jobMapSettings, painter );
220  // Render the map in this thread. This is done because of problems
221  // with printing to printer on Windows (printing to PDF is fine though).
222  // Raster images were not displayed - see #10599
223  job.renderSynchronously();
224 }
225 
227 {
228  if ( mPreviewMode == Rectangle )
229  {
230  return;
231  }
232 
233  if ( mDrawing )
234  {
235  return;
236  }
237 
238  mDrawing = true;
239 
240  //in case of rotation, we need to request a larger rectangle and create a larger cache image
241  QgsRectangle requestExtent;
242  requestedExtent( requestExtent );
243 
244  double horizontalVScaleFactor = horizontalViewScaleFactor();
245  if ( horizontalVScaleFactor < 0 )
246  {
247  //make sure scale factor is positive
248  horizontalVScaleFactor = mLastValidViewScaleFactor > 0 ? mLastValidViewScaleFactor : 1;
249  }
250 
251  double widthMM = requestExtent.width() * mapUnitsToMM();
252  double heightMM = requestExtent.height() * mapUnitsToMM();
253 
254  int w = widthMM * horizontalVScaleFactor;
255  int h = heightMM * horizontalVScaleFactor;
256 
257  if ( w > 5000 ) //limit size of image for better performance
258  {
259  w = 5000;
260  }
261 
262  if ( h > 5000 )
263  {
264  h = 5000;
265  }
266 
267  mCacheImage = QImage( w, h, QImage::Format_ARGB32 );
268 
269  // set DPI of the image
270  mCacheImage.setDotsPerMeterX( 1000 * w / widthMM );
271  mCacheImage.setDotsPerMeterY( 1000 * h / heightMM );
272 
273  if ( hasBackground() )
274  {
275  //Initially fill image with specified background color. This ensures that layers with blend modes will
276  //preview correctly
277  mCacheImage.fill( backgroundColor().rgba() );
278  }
279  else
280  {
281  //no background, but start with empty fill to avoid artifacts
282  mCacheImage.fill( QColor( 255, 255, 255, 0 ).rgba() );
283  }
284 
285  QPainter p( &mCacheImage );
286 
287  draw( &p, requestExtent, QSizeF( w, h ), mCacheImage.logicalDpiX() );
288  p.end();
289  mCacheUpdated = true;
290 
291  mDrawing = false;
292 }
293 
294 void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
295 {
296  Q_UNUSED( pWidget );
297 
298  if ( !mComposition || !painter )
299  {
300  return;
301  }
302 
303  QRectF thisPaintRect = QRectF( 0, 0, QGraphicsRectItem::rect().width(), QGraphicsRectItem::rect().height() );
304  painter->save();
305  painter->setClipRect( thisPaintRect );
306 
308  {
309  // Fill with background color
310  drawBackground( painter );
311  QFont messageFont( "", 12 );
312  painter->setFont( messageFont );
313  painter->setPen( QColor( 0, 0, 0, 125 ) );
314  painter->drawText( thisPaintRect, tr( "Map will be printed here" ) );
315  }
317  {
318  //draw cached pixmap. This function does not call cache() any more because
319  //Qt 4.4.0 and 4.4.1 have problems with recursive paintings
320  //QgsComposerMap::cache() and QgsComposerMap::update() need to be called by
321  //client functions
322 
323  //Background color is already included in cached image, so no need to draw
324 
325  QgsRectangle requestRectangle;
326  requestedExtent( requestRectangle );
327 
328  QgsRectangle cExtent = *currentMapExtent();
329 
330  double imagePixelWidth = cExtent.width() / requestRectangle.width() * mCacheImage.width() ; //how many pixels of the image are for the map extent?
331  double scale = rect().width() / imagePixelWidth;
332  QgsPoint rotationPoint = QgsPoint(( cExtent.xMaximum() + cExtent.xMinimum() ) / 2.0, ( cExtent.yMaximum() + cExtent.yMinimum() ) / 2.0 );
333 
334  //shift such that rotation point is at 0/0 point in the coordinate system
335  double yShiftMM = ( requestRectangle.yMaximum() - rotationPoint.y() ) * mapUnitsToMM();
336  double xShiftMM = ( requestRectangle.xMinimum() - rotationPoint.x() ) * mapUnitsToMM();
337 
338  //shift such that top left point of the extent at point 0/0 in item coordinate system
339  double xTopLeftShift = ( rotationPoint.x() - cExtent.xMinimum() ) * mapUnitsToMM();
340  double yTopLeftShift = ( cExtent.yMaximum() - rotationPoint.y() ) * mapUnitsToMM();
341 
342  painter->save();
343 
344  painter->translate( mXOffset, mYOffset );
345  painter->translate( xTopLeftShift, yTopLeftShift );
346  painter->rotate( mEvaluatedMapRotation );
347  painter->translate( xShiftMM, -yShiftMM );
348  painter->scale( scale, scale );
349  painter->drawImage( 0, 0, mCacheImage );
350 
351  //restore rotation
352  painter->restore();
353 
354  //draw canvas items
355  drawCanvasItems( painter, itemStyle );
356  }
357  else if ( mComposition->plotStyle() == QgsComposition::Print ||
359  {
360  if ( mDrawing )
361  {
362  return;
363  }
364 
365  mDrawing = true;
366  QPaintDevice* thePaintDevice = painter->device();
367  if ( !thePaintDevice )
368  {
369  return;
370  }
371 
372  // Fill with background color
373  if ( shouldDrawPart( Background ) )
374  {
375  drawBackground( painter );
376  }
377 
378  QgsRectangle requestRectangle;
379  requestedExtent( requestRectangle );
380 
381  QgsRectangle cExtent = *currentMapExtent();
382 
383  QSizeF theSize( requestRectangle.width() * mapUnitsToMM(), requestRectangle.height() * mapUnitsToMM() );
384 
385  QgsPoint rotationPoint = QgsPoint(( cExtent.xMaximum() + cExtent.xMinimum() ) / 2.0, ( cExtent.yMaximum() + cExtent.yMinimum() ) / 2.0 );
386 
387  //shift such that rotation point is at 0/0 point in the coordinate system
388  double yShiftMM = ( requestRectangle.yMaximum() - rotationPoint.y() ) * mapUnitsToMM();
389  double xShiftMM = ( requestRectangle.xMinimum() - rotationPoint.x() ) * mapUnitsToMM();
390 
391  //shift such that top left point of the extent at point 0/0 in item coordinate system
392  double xTopLeftShift = ( rotationPoint.x() - cExtent.xMinimum() ) * mapUnitsToMM();
393  double yTopLeftShift = ( cExtent.yMaximum() - rotationPoint.y() ) * mapUnitsToMM();
394  painter->save();
395  painter->translate( mXOffset, mYOffset );
396  painter->translate( xTopLeftShift, yTopLeftShift );
397  painter->rotate( mEvaluatedMapRotation );
398  painter->translate( xShiftMM, -yShiftMM );
399 
400  double dotsPerMM = thePaintDevice->logicalDpiX() / 25.4;
401  theSize *= dotsPerMM; // output size will be in dots (pixels)
402  painter->scale( 1 / dotsPerMM, 1 / dotsPerMM ); // scale painter from mm to dots
403  draw( painter, requestRectangle, theSize, thePaintDevice->logicalDpiX() );
404 
405  //restore rotation
406  painter->restore();
407 
408  //draw canvas items
409  drawCanvasItems( painter, itemStyle );
410 
411  mDrawing = false;
412  }
413 
414  painter->setClipRect( thisPaintRect , Qt::NoClip );
416  ( mComposition->plotStyle() != QgsComposition::Preview || mPreviewMode != Rectangle ) )
417  {
418  drawOverviews( painter );
419  }
420  if ( shouldDrawPart( Grid ) &&
421  ( mComposition->plotStyle() != QgsComposition::Preview || mPreviewMode != Rectangle ) )
422  {
423  mGridStack->drawGrids( painter );
424  }
425  if ( shouldDrawPart( Frame ) )
426  {
427  drawFrame( painter );
428  }
429  if ( isSelected() && shouldDrawPart( SelectionBoxes ) )
430  {
431  drawSelectionBoxes( painter );
432  }
433 
434  painter->restore();
435 }
436 
438 {
439  return
440  ( hasBackground() ? 1 : 0 )
441  + layersToRender().length()
442  + 1 // for grids, if they exist
443  + 1 // for overviews, if they exist
444  + ( hasFrame() ? 1 : 0 )
445  + ( isSelected() ? 1 : 0 )
446  ;
447 }
448 
450 {
451  if ( -1 == mCurrentExportLayer )
452  {
453  //all parts of the composer map are visible
454  return true;
455  }
456 
457  int idx = numberExportLayers();
458  if ( isSelected() )
459  {
460  --idx;
461  if ( SelectionBoxes == part )
462  {
463  return mCurrentExportLayer == idx;
464  }
465  }
466 
467  if ( hasFrame() )
468  {
469  --idx;
470  if ( Frame == part )
471  {
472  return mCurrentExportLayer == idx;
473  }
474  }
475  --idx;
476  if ( OverviewMapExtent == part )
477  {
478  return mCurrentExportLayer == idx;
479  }
480  --idx;
481  if ( Grid == part )
482  {
483  return mCurrentExportLayer == idx;
484  }
485  if ( hasBackground() )
486  {
487  if ( Background == part )
488  {
489  return mCurrentExportLayer == 0;
490  }
491  }
492 
493  return true; // for Layer
494 }
495 
497 {
498  syncLayerSet(); //layer list may have changed
499  mCacheUpdated = false;
500  cache();
501  QGraphicsRectItem::update();
502 }
503 
505 {
506  if ( mPreviewMode == Render )
507  {
509  }
510 }
511 
513 {
514  mCacheUpdated = u;
515 }
516 
518 {
520  return mComposition->mapRenderer();
522 }
523 
525 {
526  //use stored layer set or read current set from main canvas
527  QStringList renderLayerSet;
528  if ( mKeepLayerSet )
529  {
530  renderLayerSet = mLayerSet;
531  }
532  else
533  {
534  renderLayerSet = mComposition->mapSettings().layers();
535  }
536 
537  //remove atlas coverage layer if required
538  //TODO - move setting for hiding coverage layer to map item properties
540  {
542  {
543  //hiding coverage layer
544  int removeAt = renderLayerSet.indexOf( mComposition->atlasComposition().coverageLayer()->id() );
545  if ( removeAt != -1 )
546  {
547  renderLayerSet.removeAt( removeAt );
548  }
549  }
550  }
551 
552  return renderLayerSet;
553 }
554 
555 double QgsComposerMap::scale() const
556 {
557  QgsScaleCalculator calculator;
558  calculator.setMapUnits( mComposition->mapSettings().mapUnits() );
559  calculator.setDpi( 25.4 ); //QGraphicsView units are mm
560  return calculator.calculate( *currentMapExtent(), rect().width() );
561 }
562 
563 void QgsComposerMap::resize( double dx, double dy )
564 {
565  //setRect
566  QRectF currentRect = rect();
567  QRectF newSceneRect = QRectF( pos().x(), pos().y(), currentRect.width() + dx, currentRect.height() + dy );
568  setSceneRect( newSceneRect );
569  updateItem();
570 }
571 
572 void QgsComposerMap::moveContent( double dx, double dy )
573 {
574  if ( !mDrawing )
575  {
576  transformShift( dx, dy );
577  currentMapExtent()->setXMinimum( currentMapExtent()->xMinimum() + dx );
578  currentMapExtent()->setXMaximum( currentMapExtent()->xMaximum() + dx );
579  currentMapExtent()->setYMinimum( currentMapExtent()->yMinimum() + dy );
580  currentMapExtent()->setYMaximum( currentMapExtent()->yMaximum() + dy );
581 
582  //in case data defined extents are set, these override the calculated values
584 
585  cache();
586  update();
587  emit itemChanged();
588  emit extentChanged();
589  }
590 }
591 
592 void QgsComposerMap::zoomContent( int delta, double x, double y )
593 {
594  if ( mDrawing )
595  {
596  return;
597  }
598 
599  QSettings settings;
600 
601  //read zoom mode
602  //0: zoom, 1: zoom and recenter, 2: zoom to cursor, 3: nothing
603  int zoomMode = settings.value( "/qgis/wheel_action", 2 ).toInt();
604  if ( zoomMode == 3 ) //do nothing
605  {
606  return;
607  }
608 
609  double zoomFactor = settings.value( "/qgis/zoom_factor", 2.0 ).toDouble();
610 
611  //find out new center point
612  double centerX = ( currentMapExtent()->xMaximum() + currentMapExtent()->xMinimum() ) / 2;
613  double centerY = ( currentMapExtent()->yMaximum() + currentMapExtent()->yMinimum() ) / 2;
614 
615  if ( zoomMode != 0 )
616  {
617  //find out map coordinates of mouse position
618  double mapMouseX = currentMapExtent()->xMinimum() + ( x / rect().width() ) * ( currentMapExtent()->xMaximum() - currentMapExtent()->xMinimum() );
619  double mapMouseY = currentMapExtent()->yMinimum() + ( 1 - ( y / rect().height() ) ) * ( currentMapExtent()->yMaximum() - currentMapExtent()->yMinimum() );
620  if ( zoomMode == 1 ) //zoom and recenter
621  {
622  centerX = mapMouseX;
623  centerY = mapMouseY;
624  }
625  else if ( zoomMode == 2 ) //zoom to cursor
626  {
627  centerX = mapMouseX + ( centerX - mapMouseX ) * ( 1.0 / zoomFactor );
628  centerY = mapMouseY + ( centerY - mapMouseY ) * ( 1.0 / zoomFactor );
629  }
630  }
631 
632  double newIntervalX, newIntervalY;
633 
634  if ( delta > 0 )
635  {
636  newIntervalX = ( currentMapExtent()->xMaximum() - currentMapExtent()->xMinimum() ) / zoomFactor;
637  newIntervalY = ( currentMapExtent()->yMaximum() - currentMapExtent()->yMinimum() ) / zoomFactor;
638  }
639  else if ( delta < 0 )
640  {
641  newIntervalX = ( currentMapExtent()->xMaximum() - currentMapExtent()->xMinimum() ) * zoomFactor;
642  newIntervalY = ( currentMapExtent()->yMaximum() - currentMapExtent()->yMinimum() ) * zoomFactor;
643  }
644  else //no need to zoom
645  {
646  return;
647  }
648 
649  currentMapExtent()->setXMaximum( centerX + newIntervalX / 2 );
650  currentMapExtent()->setXMinimum( centerX - newIntervalX / 2 );
651  currentMapExtent()->setYMaximum( centerY + newIntervalY / 2 );
652  currentMapExtent()->setYMinimum( centerY - newIntervalY / 2 );
653 
655  {
656  //if map is atlas controlled and set to fixed scaling mode, then scale changes should be treated as permanant
657  //and also apply to the map's original extent (see #9602)
658  //we can't use the scaleRatio calculated earlier, as the scale can vary depending on extent for geographic coordinate systems
659  QgsScaleCalculator calculator;
660  calculator.setMapUnits( mComposition->mapSettings().mapUnits() );
661  calculator.setDpi( 25.4 ); //QGraphicsView units are mm
662  double scaleRatio = scale() / calculator.calculate( mExtent, rect().width() );
663  mExtent.scale( scaleRatio );
664  }
665 
666  //recalculate data defined scale and extents, since that may override zoom
668 
669  cache();
670  update();
671  emit itemChanged();
672  emit extentChanged();
673 }
674 
675 void QgsComposerMap::setSceneRect( const QRectF& rectangle )
676 {
677  double w = rectangle.width();
678  double h = rectangle.height();
679  //prepareGeometryChange();
680 
681  QgsComposerItem::setSceneRect( rectangle );
682 
683  //QGraphicsRectItem::update();
684  double newHeight = mExtent.width() * h / w ;
686 
687  //recalculate data defined scale and extents
689  mCacheUpdated = false;
690 
692  update();
693  emit itemChanged();
694  emit extentChanged();
695 }
696 
698 {
699  if ( *currentMapExtent() == extent )
700  {
701  return;
702  }
704 
705  //recalculate data defined scale and extents, since that may override extent
707 
708  //adjust height
709  QRectF currentRect = rect();
710 
711  double newHeight = currentRect.width() * currentMapExtent()->height() / currentMapExtent()->width();
712 
713  setSceneRect( QRectF( pos().x(), pos().y(), currentRect.width(), newHeight ) );
714  updateItem();
715 }
716 
718 {
719  QgsRectangle newExtent = extent;
720  //Make sure the width/height ratio is the same as the current composer map extent.
721  //This is to keep the map item frame size fixed
722  double currentWidthHeightRatio = currentMapExtent()->width() / currentMapExtent()->height();
723  double newWidthHeightRatio = newExtent.width() / newExtent.height();
724 
725  if ( currentWidthHeightRatio < newWidthHeightRatio )
726  {
727  //enlarge height of new extent, ensuring the map center stays the same
728  double newHeight = newExtent.width() / currentWidthHeightRatio;
729  double deltaHeight = newHeight - newExtent.height();
730  newExtent.setYMinimum( newExtent.yMinimum() - deltaHeight / 2 );
731  newExtent.setYMaximum( newExtent.yMaximum() + deltaHeight / 2 );
732  }
733  else
734  {
735  //enlarge width of new extent, ensuring the map center stays the same
736  double newWidth = currentWidthHeightRatio * newExtent.height();
737  double deltaWidth = newWidth - newExtent.width();
738  newExtent.setXMinimum( newExtent.xMinimum() - deltaWidth / 2 );
739  newExtent.setXMaximum( newExtent.xMaximum() + deltaWidth / 2 );
740  }
741 
742  if ( *currentMapExtent() == newExtent )
743  {
744  return;
745  }
746  *currentMapExtent() = newExtent;
747 
748  //recalculate data defined scale and extents, since that may override extent
750 
751  mCacheUpdated = false;
752  updateItem();
753  emit itemChanged();
754  emit extentChanged();
755 }
756 
758 {
759  if ( mAtlasFeatureExtent != extent )
760  {
761  //don't adjust size of item, instead adjust size of bounds to fit
762  QgsRectangle newExtent = extent;
763 
764  //Make sure the width/height ratio is the same as the map item size
765  double currentWidthHeightRatio = rect().width() / rect().height();
766  double newWidthHeightRatio = newExtent.width() / newExtent.height();
767 
768  if ( currentWidthHeightRatio < newWidthHeightRatio )
769  {
770  //enlarge height of new extent, ensuring the map center stays the same
771  double newHeight = newExtent.width() / currentWidthHeightRatio;
772  double deltaHeight = newHeight - newExtent.height();
773  newExtent.setYMinimum( extent.yMinimum() - deltaHeight / 2 );
774  newExtent.setYMaximum( extent.yMaximum() + deltaHeight / 2 );
775  }
776  else if ( currentWidthHeightRatio >= newWidthHeightRatio )
777  {
778  //enlarge width of new extent, ensuring the map center stays the same
779  double newWidth = currentWidthHeightRatio * newExtent.height();
780  double deltaWidth = newWidth - newExtent.width();
781  newExtent.setXMinimum( extent.xMinimum() - deltaWidth / 2 );
782  newExtent.setXMaximum( extent.xMaximum() + deltaWidth / 2 );
783  }
784 
785  mAtlasFeatureExtent = newExtent;
786  }
787 
788  //recalculate data defined scale and extents, since that may override extents
790 
791  mCacheUpdated = false;
792  emit preparedForAtlas();
793  updateItem();
794  emit itemChanged();
795  emit extentChanged();
796 }
797 
799 {
800  //atlas preview has been toggled, so update item and extents
801  mCacheUpdated = false;
802  updateItem();
803  emit itemChanged();
804  emit extentChanged();
805 }
806 
808 {
809  //non-const version
811  {
812  //if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
813  //return the current temporary atlas feature extent
814  return &mAtlasFeatureExtent;
815  }
816  else
817  {
818  //otherwise return permenant user set extent
819  return &mExtent;
820  }
821 }
822 
824 {
825  //const version
827  {
828  //if atlas is enabled, and we are either exporting the composition or previewing the atlas, then
829  //return the current temporary atlas feature extent
830  return &mAtlasFeatureExtent;
831  }
832  else
833  {
834  //otherwise return permenant user set extent
835  return &mExtent;
836  }
837 }
838 
839 void QgsComposerMap::setNewScale( double scaleDenominator, bool forceUpdate )
840 {
841  double currentScaleDenominator = scale();
842 
843  if ( scaleDenominator == currentScaleDenominator || scaleDenominator == 0 )
844  {
845  return;
846  }
847 
848  double scaleRatio = scaleDenominator / currentScaleDenominator;
849  currentMapExtent()->scale( scaleRatio );
850 
852  {
853  //if map is atlas controlled and set to fixed scaling mode, then scale changes should be treated as permanant
854  //and also apply to the map's original extent (see #9602)
855  //we can't use the scaleRatio calculated earlier, as the scale can vary depending on extent for geographic coordinate systems
856  QgsScaleCalculator calculator;
857  calculator.setMapUnits( mComposition->mapSettings().mapUnits() );
858  calculator.setDpi( 25.4 ); //QGraphicsView units are mm
859  scaleRatio = scaleDenominator / calculator.calculate( mExtent, rect().width() );
860  mExtent.scale( scaleRatio );
861  }
862 
863  mCacheUpdated = false;
864  if ( forceUpdate )
865  {
866  cache();
867  update();
868  emit itemChanged();
869  }
870  emit extentChanged();
871 }
872 
874 {
875  mPreviewMode = m;
876  emit itemChanged();
877 }
878 
879 void QgsComposerMap::setOffset( double xOffset, double yOffset )
880 {
881  mXOffset = xOffset;
882  mYOffset = yOffset;
883 }
884 
886 {
887  //kept for api compatibility with QGIS 2.0
888  setMapRotation( r );
889 }
890 
892 {
893  mMapRotation = r;
895  emit mapRotationChanged( r );
896  emit itemChanged();
897  update();
898 }
899 
901 {
903 }
904 
906 {
907  //data defined map extents set?
908  QVariant exprVal;
909 
910  QgsRectangle newExtent = *currentMapExtent();
911  bool useDdXMin = false;
912  bool useDdXMax = false;
913  bool useDdYMin = false;
914  bool useDdYMax = false;
915  double minXD = 0;
916  double minYD = 0;
917  double maxXD = 0;
918  double maxYD = 0;
919 
921  {
922  bool ok;
923  minXD = exprVal.toDouble( &ok );
924  QgsDebugMsg( QString( "exprVal Map XMin:%1" ).arg( minXD ) );
925  if ( ok )
926  {
927  useDdXMin = true;
928  newExtent.setXMinimum( minXD );
929  }
930  }
932  {
933  bool ok;
934  minYD = exprVal.toDouble( &ok );
935  QgsDebugMsg( QString( "exprVal Map YMin:%1" ).arg( minYD ) );
936  if ( ok )
937  {
938  useDdYMin = true;
939  newExtent.setYMinimum( minYD );
940  }
941  }
943  {
944  bool ok;
945  maxXD = exprVal.toDouble( &ok );
946  QgsDebugMsg( QString( "exprVal Map XMax:%1" ).arg( maxXD ) );
947  if ( ok )
948  {
949  useDdXMax = true;
950  newExtent.setXMaximum( maxXD );
951  }
952  }
954  {
955  bool ok;
956  maxYD = exprVal.toDouble( &ok );
957  QgsDebugMsg( QString( "exprVal Map YMax:%1" ).arg( maxYD ) );
958  if ( ok )
959  {
960  useDdYMax = true;
961  newExtent.setYMaximum( maxYD );
962  }
963  }
964 
965  if ( newExtent != *currentMapExtent() )
966  {
967  //calculate new extents to fit data defined extents
968 
969  //Make sure the width/height ratio is the same as in current map extent.
970  //This is to keep the map item frame and the page layout fixed
971  double currentWidthHeightRatio = currentMapExtent()->width() / currentMapExtent()->height();
972  double newWidthHeightRatio = newExtent.width() / newExtent.height();
973 
974  if ( currentWidthHeightRatio < newWidthHeightRatio )
975  {
976  //enlarge height of new extent, ensuring the map center stays the same
977  double newHeight = newExtent.width() / currentWidthHeightRatio;
978  double deltaHeight = newHeight - newExtent.height();
979  newExtent.setYMinimum( newExtent.yMinimum() - deltaHeight / 2 );
980  newExtent.setYMaximum( newExtent.yMaximum() + deltaHeight / 2 );
981  }
982  else
983  {
984  //enlarge width of new extent, ensuring the map center stays the same
985  double newWidth = currentWidthHeightRatio * newExtent.height();
986  double deltaWidth = newWidth - newExtent.width();
987  newExtent.setXMinimum( newExtent.xMinimum() - deltaWidth / 2 );
988  newExtent.setXMaximum( newExtent.xMaximum() + deltaWidth / 2 );
989  }
990 
991  *currentMapExtent() = newExtent;
992  }
993 
994  //now refresh scale, as this potentially overrides extents
995 
996  //data defined map scale set?
998  {
999  bool ok;
1000  double scaleD = exprVal.toDouble( &ok );
1001  QgsDebugMsg( QString( "exprVal Map Scale:%1" ).arg( scaleD ) );
1002  if ( ok )
1003  {
1004  setNewScale( scaleD, false );
1005  newExtent = *currentMapExtent();
1006  }
1007  }
1008 
1009  if ( useDdXMax || useDdXMin || useDdYMax || useDdYMin )
1010  {
1011  //if only one of min/max was set for either x or y, then make sure our extent is locked on that value
1012  //as we can do this without altering the scale
1013  if ( useDdXMin && !useDdXMax )
1014  {
1015  double xMax = currentMapExtent()->xMaximum() - ( currentMapExtent()->xMinimum() - minXD );
1016  newExtent.setXMinimum( minXD );
1017  newExtent.setXMaximum( xMax );
1018  }
1019  else if ( !useDdXMin && useDdXMax )
1020  {
1021  double xMin = currentMapExtent()->xMinimum() - ( currentMapExtent()->xMaximum() - maxXD );
1022  newExtent.setXMinimum( xMin );
1023  newExtent.setXMaximum( maxXD );
1024  }
1025  if ( useDdYMin && !useDdYMax )
1026  {
1027  double yMax = currentMapExtent()->yMaximum() - ( currentMapExtent()->yMinimum() - minYD );
1028  newExtent.setYMinimum( minYD );
1029  newExtent.setYMaximum( yMax );
1030  }
1031  else if ( !useDdYMin && useDdYMax )
1032  {
1033  double yMin = currentMapExtent()->yMinimum() - ( currentMapExtent()->yMaximum() - maxYD );
1034  newExtent.setYMinimum( yMin );
1035  newExtent.setYMaximum( maxYD );
1036  }
1037 
1038  if ( newExtent != *currentMapExtent() )
1039  {
1040  *currentMapExtent() = newExtent;
1041  }
1042  }
1043 
1044  //lastly, map rotation overrides all
1045  double mapRotation = mMapRotation;
1046 
1047  //data defined map rotation set?
1049  {
1050  bool ok;
1051  double rotationD = exprVal.toDouble( &ok );
1052  QgsDebugMsg( QString( "exprVal Map Rotation:%1" ).arg( rotationD ) );
1053  if ( ok )
1054  {
1055  mapRotation = rotationD;
1056  }
1057  }
1058 
1059  if ( mEvaluatedMapRotation != mapRotation )
1060  {
1062  emit mapRotationChanged( mapRotation );
1063  }
1064 
1065 }
1066 
1068 {
1069  if ( !mUpdatesEnabled )
1070  {
1071  return;
1072  }
1073 
1075  {
1076  cache();
1077  }
1079 }
1080 
1082 {
1083  QStringList layers = mComposition->mapSettings().layers();
1084 
1085  QStringList::const_iterator layer_it = layers.constBegin();
1086  QgsMapLayer* currentLayer = 0;
1087 
1088  for ( ; layer_it != layers.constEnd(); ++layer_it )
1089  {
1090  currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *layer_it );
1091  if ( currentLayer )
1092  {
1093  QgsRasterLayer* currentRasterLayer = qobject_cast<QgsRasterLayer *>( currentLayer );
1094  if ( currentRasterLayer )
1095  {
1096  const QgsRasterDataProvider* rasterProvider = 0;
1097  if (( rasterProvider = currentRasterLayer->dataProvider() ) )
1098  {
1099  if ( rasterProvider->name() == "wms" )
1100  {
1101  return true;
1102  }
1103  }
1104  }
1105  }
1106  }
1107  return false;
1108 }
1109 
1111 {
1112  //check easy things first
1113 
1114  //grids
1116  {
1117  return true;
1118  }
1119 
1120  // check if map contains advanced effects like blend modes, or flattened layers for transparency
1121 
1122  QStringList layers = mComposition->mapSettings().layers();
1123 
1124  QStringList::const_iterator layer_it = layers.constBegin();
1125  QgsMapLayer* currentLayer = 0;
1126 
1127  for ( ; layer_it != layers.constEnd(); ++layer_it )
1128  {
1129  currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *layer_it );
1130  if ( currentLayer )
1131  {
1132  if ( currentLayer->blendMode() != QPainter::CompositionMode_SourceOver )
1133  {
1134  return true;
1135  }
1136  // if vector layer, check labels and feature blend mode
1137  QgsVectorLayer* currentVectorLayer = qobject_cast<QgsVectorLayer *>( currentLayer );
1138  if ( currentVectorLayer )
1139  {
1140  if ( currentVectorLayer->layerTransparency() != 0 )
1141  {
1142  return true;
1143  }
1144  if ( currentVectorLayer->featureBlendMode() != QPainter::CompositionMode_SourceOver )
1145  {
1146  return true;
1147  }
1148  // check label blend modes
1149  if ( QgsPalLabeling::staticWillUseLayer( currentVectorLayer ) )
1150  {
1151  // Check all label blending properties
1152  QgsPalLayerSettings layerSettings = QgsPalLayerSettings::fromLayer( currentVectorLayer );
1153  if (( layerSettings.blendMode != QPainter::CompositionMode_SourceOver ) ||
1154  ( layerSettings.bufferSize != 0 && layerSettings.bufferBlendMode != QPainter::CompositionMode_SourceOver ) ||
1155  ( layerSettings.shadowDraw && layerSettings.shadowBlendMode != QPainter::CompositionMode_SourceOver ) ||
1156  ( layerSettings.shapeDraw && layerSettings.shapeBlendMode != QPainter::CompositionMode_SourceOver ) )
1157  {
1158  return true;
1159  }
1160  }
1161  }
1162  }
1163  }
1164 
1165  return false;
1166 }
1167 
1169 {
1170  //connect signal from layer registry to update in case of new or deleted layers
1172  if ( layerRegistry )
1173  {
1174  connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( updateCachedImage() ) );
1175  connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( updateCachedImage() ) );
1176  }
1177 }
1178 
1179 bool QgsComposerMap::writeXML( QDomElement& elem, QDomDocument & doc ) const
1180 {
1181  if ( elem.isNull() )
1182  {
1183  return false;
1184  }
1185 
1186  QDomElement composerMapElem = doc.createElement( "ComposerMap" );
1187  composerMapElem.setAttribute( "id", mId );
1188 
1189  //previewMode
1190  if ( mPreviewMode == Cache )
1191  {
1192  composerMapElem.setAttribute( "previewMode", "Cache" );
1193  }
1194  else if ( mPreviewMode == Render )
1195  {
1196  composerMapElem.setAttribute( "previewMode", "Render" );
1197  }
1198  else //rectangle
1199  {
1200  composerMapElem.setAttribute( "previewMode", "Rectangle" );
1201  }
1202 
1203  if ( mKeepLayerSet )
1204  {
1205  composerMapElem.setAttribute( "keepLayerSet", "true" );
1206  }
1207  else
1208  {
1209  composerMapElem.setAttribute( "keepLayerSet", "false" );
1210  }
1211 
1212  if ( mDrawCanvasItems )
1213  {
1214  composerMapElem.setAttribute( "drawCanvasItems", "true" );
1215  }
1216  else
1217  {
1218  composerMapElem.setAttribute( "drawCanvasItems", "false" );
1219  }
1220 
1221  //extent
1222  QDomElement extentElem = doc.createElement( "Extent" );
1223  extentElem.setAttribute( "xmin", qgsDoubleToString( mExtent.xMinimum() ) );
1224  extentElem.setAttribute( "xmax", qgsDoubleToString( mExtent.xMaximum() ) );
1225  extentElem.setAttribute( "ymin", qgsDoubleToString( mExtent.yMinimum() ) );
1226  extentElem.setAttribute( "ymax", qgsDoubleToString( mExtent.yMaximum() ) );
1227  composerMapElem.appendChild( extentElem );
1228 
1229  //map rotation
1230  composerMapElem.setAttribute( "mapRotation", QString::number( mMapRotation ) );
1231 
1232  //layer set
1233  QDomElement layerSetElem = doc.createElement( "LayerSet" );
1234  QStringList::const_iterator layerIt = mLayerSet.constBegin();
1235  for ( ; layerIt != mLayerSet.constEnd(); ++layerIt )
1236  {
1237  QDomElement layerElem = doc.createElement( "Layer" );
1238  QDomText layerIdText = doc.createTextNode( *layerIt );
1239  layerElem.appendChild( layerIdText );
1240  layerSetElem.appendChild( layerElem );
1241  }
1242  composerMapElem.appendChild( layerSetElem );
1243 
1244  //write a dummy "Grid" element to prevent crashes on pre 2.5 versions (refs #10905)
1245  QDomElement gridElem = doc.createElement( "Grid" );
1246  composerMapElem.appendChild( gridElem );
1247 
1248  //grids
1249  mGridStack->writeXML( composerMapElem, doc );
1250 
1251  //overviews
1252  QList< QgsComposerMapOverview* >::const_iterator overviewIt = mOverviews.constBegin();
1253  for ( ; overviewIt != mOverviews.constEnd(); ++overviewIt )
1254  {
1255  ( *overviewIt )->writeXML( composerMapElem, doc );
1256  }
1257 
1258  //atlas
1259  QDomElement atlasElem = doc.createElement( "AtlasMap" );
1260  atlasElem.setAttribute( "atlasDriven", mAtlasDriven );
1261  atlasElem.setAttribute( "scalingMode", mAtlasScalingMode );
1262  atlasElem.setAttribute( "margin", qgsDoubleToString( mAtlasMargin ) );
1263  composerMapElem.appendChild( atlasElem );
1264 
1265  elem.appendChild( composerMapElem );
1266  return _writeXML( composerMapElem, doc );
1267 }
1268 
1269 bool QgsComposerMap::readXML( const QDomElement& itemElem, const QDomDocument& doc )
1270 {
1271  if ( itemElem.isNull() )
1272  {
1273  return false;
1274  }
1275 
1276  removeOverviews();
1277 
1278  QString idRead = itemElem.attribute( "id", "not found" );
1279  if ( idRead != "not found" )
1280  {
1281  mId = idRead.toInt();
1282  }
1284 
1285  //previewMode
1286  QString previewMode = itemElem.attribute( "previewMode" );
1287  if ( previewMode == "Cache" )
1288  {
1289  mPreviewMode = Cache;
1290  }
1291  else if ( previewMode == "Render" )
1292  {
1293  mPreviewMode = Render;
1294  }
1295  else
1296  {
1298  }
1299 
1300  //extent
1301  QDomNodeList extentNodeList = itemElem.elementsByTagName( "Extent" );
1302  if ( extentNodeList.size() > 0 )
1303  {
1304  QDomElement extentElem = extentNodeList.at( 0 ).toElement();
1305  double xmin, xmax, ymin, ymax;
1306  xmin = extentElem.attribute( "xmin" ).toDouble();
1307  xmax = extentElem.attribute( "xmax" ).toDouble();
1308  ymin = extentElem.attribute( "ymin" ).toDouble();
1309  ymax = extentElem.attribute( "ymax" ).toDouble();
1310  setNewExtent( QgsRectangle( xmin, ymin, xmax, ymax ) );
1311  }
1312 
1313  //map rotation
1314  if ( itemElem.attribute( "mapRotation", "0" ).toDouble() != 0 )
1315  {
1316  mMapRotation = itemElem.attribute( "mapRotation", "0" ).toDouble();
1317  }
1318 
1319  //mKeepLayerSet flag
1320  QString keepLayerSetFlag = itemElem.attribute( "keepLayerSet" );
1321  if ( keepLayerSetFlag.compare( "true", Qt::CaseInsensitive ) == 0 )
1322  {
1323  mKeepLayerSet = true;
1324  }
1325  else
1326  {
1327  mKeepLayerSet = false;
1328  }
1329 
1330  QString drawCanvasItemsFlag = itemElem.attribute( "drawCanvasItems", "true" );
1331  if ( drawCanvasItemsFlag.compare( "true", Qt::CaseInsensitive ) == 0 )
1332  {
1333  mDrawCanvasItems = true;
1334  }
1335  else
1336  {
1337  mDrawCanvasItems = false;
1338  }
1339 
1340  //mLayerSet
1341  QDomNodeList layerSetNodeList = itemElem.elementsByTagName( "LayerSet" );
1342  QStringList layerSet;
1343  if ( layerSetNodeList.size() > 0 )
1344  {
1345  QDomElement layerSetElem = layerSetNodeList.at( 0 ).toElement();
1346  QDomNodeList layerIdNodeList = layerSetElem.elementsByTagName( "Layer" );
1347  for ( int i = 0; i < layerIdNodeList.size(); ++i )
1348  {
1349  layerSet << layerIdNodeList.at( i ).toElement().text();
1350  }
1351  }
1352  mLayerSet = layerSet;
1353 
1354  mDrawing = false;
1355  mNumCachedLayers = 0;
1356  mCacheUpdated = false;
1357 
1358  //grids
1359  mGridStack->readXML( itemElem, doc );
1360 
1361  //load grid / grid annotation in old xml format
1362  //only do this if the grid stack didn't load any grids, otherwise this will
1363  //be the dummy element created by QGIS >= 2.5 (refs #10905)
1364  QDomNodeList gridNodeList = itemElem.elementsByTagName( "Grid" );
1365  if ( mGridStack->size() == 0 && gridNodeList.size() > 0 )
1366  {
1367  QDomElement gridElem = gridNodeList.at( 0 ).toElement();
1368  QgsComposerMapGrid* mapGrid = new QgsComposerMapGrid( tr( "Grid %1" ).arg( 1 ), this );
1369  mapGrid->setEnabled( gridElem.attribute( "show", "0" ) != "0" );
1370  mapGrid->setStyle( QgsComposerMapGrid::GridStyle( gridElem.attribute( "gridStyle", "0" ).toInt() ) );
1371  mapGrid->setIntervalX( gridElem.attribute( "intervalX", "0" ).toDouble() );
1372  mapGrid->setIntervalY( gridElem.attribute( "intervalY", "0" ).toDouble() );
1373  mapGrid->setOffsetX( gridElem.attribute( "offsetX", "0" ).toDouble() );
1374  mapGrid->setOffsetY( gridElem.attribute( "offsetY", "0" ).toDouble() );
1375  mapGrid->setCrossLength( gridElem.attribute( "crossLength", "3" ).toDouble() );
1376  mapGrid->setFrameStyle(( QgsComposerMapGrid::FrameStyle )gridElem.attribute( "gridFrameStyle", "0" ).toInt() );
1377  mapGrid->setFrameWidth( gridElem.attribute( "gridFrameWidth", "2.0" ).toDouble() );
1378  mapGrid->setFramePenSize( gridElem.attribute( "gridFramePenThickness", "0.5" ).toDouble() );
1379  mapGrid->setFramePenColor( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "framePenColor", "0,0,0" ) ) );
1380  mapGrid->setFrameFillColor1( QgsSymbolLayerV2Utils::decodeColor( gridElem.attribute( "frameFillColor1", "255,255,255,255" ) ) );
1381  mapGrid->setFrameFillColor2( 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->setLineSymbol( 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->setAnnotationEnabled( annotationElem.attribute( "show", "0" ) != "0" );
1406  mapGrid->setAnnotationFormat( QgsComposerMapGrid::AnnotationFormat( annotationElem.attribute( "format", "0" ).toInt() ) );
1407  mapGrid->setAnnotationPosition( QgsComposerMapGrid::AnnotationPosition( annotationElem.attribute( "leftPosition", "0" ).toInt() ), QgsComposerMapGrid::Left );
1408  mapGrid->setAnnotationPosition( QgsComposerMapGrid::AnnotationPosition( annotationElem.attribute( "rightPosition", "0" ).toInt() ), QgsComposerMapGrid::Right );
1409  mapGrid->setAnnotationPosition( QgsComposerMapGrid::AnnotationPosition( annotationElem.attribute( "topPosition", "0" ).toInt() ), QgsComposerMapGrid::Top );
1410  mapGrid->setAnnotationPosition( QgsComposerMapGrid::AnnotationPosition( annotationElem.attribute( "bottomPosition", "0" ).toInt() ), QgsComposerMapGrid::Bottom );
1411  mapGrid->setAnnotationDirection( QgsComposerMapGrid::AnnotationDirection( annotationElem.attribute( "leftDirection", "0" ).toInt() ), QgsComposerMapGrid::Left );
1412  mapGrid->setAnnotationDirection( QgsComposerMapGrid::AnnotationDirection( annotationElem.attribute( "rightDirection", "0" ).toInt() ), QgsComposerMapGrid::Right );
1413  mapGrid->setAnnotationDirection( QgsComposerMapGrid::AnnotationDirection( annotationElem.attribute( "topDirection", "0" ).toInt() ), QgsComposerMapGrid::Top );
1414  mapGrid->setAnnotationDirection( QgsComposerMapGrid::AnnotationDirection( annotationElem.attribute( "bottomDirection", "0" ).toInt() ), QgsComposerMapGrid::Bottom );
1415  mapGrid->setAnnotationFrameDistance( annotationElem.attribute( "frameDistance", "0" ).toDouble() );
1416  QFont annotationFont;
1417  annotationFont.fromString( annotationElem.attribute( "font", "" ) );
1418  mapGrid->setAnnotationFont( annotationFont );
1419  mapGrid->setAnnotationFontColor( QgsSymbolLayerV2Utils::decodeColor( itemElem.attribute( "fontColor", "0,0,0,255" ) ) );
1420 
1421  mapGrid->setAnnotationPrecision( annotationElem.attribute( "precision", "3" ).toInt() );
1422  }
1423  mGridStack->addGrid( 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 ( mGridStack->size() < 1 )
1528  {
1529  QgsComposerMapGrid* grid = new QgsComposerMapGrid( tr( "Grid %1" ).arg( 1 ), this );
1530  mGridStack->addGrid( grid );
1531  }
1532  return mGridStack->grid( 0 );
1533 }
1534 
1536 {
1537  return const_cast<QgsComposerMap*>( this )->grid();
1538 }
1539 
1541 {
1542  QgsComposerMapGrid* g = grid();
1543  g->setStyle( QgsComposerMapGrid::GridStyle( style ) );
1544 }
1545 
1547 {
1549  return ( QgsComposerMap::GridStyle )g->style();
1550 }
1551 
1552 void QgsComposerMap::setGridIntervalX( double interval )
1553 {
1554  QgsComposerMapGrid* g = grid();
1555  g->setIntervalX( interval );
1556 }
1557 
1559 {
1561  return g->intervalX();
1562 }
1563 
1564 void QgsComposerMap::setGridIntervalY( double interval )
1565 {
1566  QgsComposerMapGrid* g = grid();
1567  g->setIntervalY( interval );
1568 }
1569 
1571 {
1573  return g->intervalY();
1574 }
1575 
1576 void QgsComposerMap::setGridOffsetX( double offset )
1577 {
1578  QgsComposerMapGrid* g = grid();
1579  g->setOffsetX( offset );
1580 }
1581 
1583 {
1585  return g->offsetX();
1586 }
1587 
1588 void QgsComposerMap::setGridOffsetY( double offset )
1589 {
1590  QgsComposerMapGrid* g = grid();
1591  g->setOffsetY( offset );
1592 }
1593 
1595 {
1597  return g->offsetY();
1598 }
1599 
1601 {
1602  QgsComposerMapGrid* g = grid();
1603  g->setGridLineWidth( w );
1604 }
1605 
1606 void QgsComposerMap::setGridPenColor( const QColor& c )
1607 {
1608  QgsComposerMapGrid* g = grid();
1609  g->setGridLineColor( c );
1610 }
1611 
1612 void QgsComposerMap::setGridPen( const QPen& p )
1613 {
1614  QgsComposerMapGrid* g = grid();
1615  g->setGridLineWidth( p.widthF() );
1616  g->setGridLineColor( p.color() );
1617 }
1618 
1620 {
1622  QPen p;
1623  if ( g->lineSymbol() )
1624  {
1625  QgsLineSymbolV2* line = dynamic_cast<QgsLineSymbolV2*>( g->lineSymbol()->clone() );
1626  p.setWidthF( line->width() );
1627  p.setColor( line->color() );
1628  p.setCapStyle( Qt::FlatCap );
1629  delete line;
1630  }
1631  return p;
1632 }
1633 
1635 {
1636  QgsComposerMapGrid* g = grid();
1637  g->setAnnotationFont( f );
1638 }
1639 
1641 {
1643  return g->annotationFont();
1644 }
1645 
1647 {
1648  QgsComposerMapGrid* g = grid();
1649  g->setAnnotationFontColor( c );
1650 }
1651 
1653 {
1655  return g->annotationFontColor();
1656 }
1657 
1659 {
1660  QgsComposerMapGrid* g = grid();
1661  g->setAnnotationPrecision( p );
1662 }
1663 
1665 {
1667  return g->annotationPrecision();
1668 }
1669 
1671 {
1672  QgsComposerMapGrid* g = grid();
1673  g->setAnnotationEnabled( show );
1674 }
1675 
1677 {
1679  return g->annotationEnabled();
1680 }
1681 
1683 {
1684  QgsComposerMapGrid* g = grid();
1686 }
1687 
1689 {
1692 }
1693 
1695 {
1696  QgsComposerMapGrid* g = grid();
1698 }
1699 
1701 {
1703  return g->annotationFrameDistance();
1704 }
1705 
1707 {
1708  QgsComposerMapGrid* g = grid();
1709  //map grid direction to QgsComposerMapGrid direction (values are different)
1711  switch ( d )
1712  {
1714  gridDirection = QgsComposerMapGrid::Horizontal;
1715  break;
1717  gridDirection = QgsComposerMapGrid::Vertical;
1718  break;
1720  gridDirection = QgsComposerMapGrid::BoundaryDirection;
1721  break;
1722  default:
1723  gridDirection = QgsComposerMapGrid::Horizontal;
1724  }
1725  g->setAnnotationDirection( gridDirection, ( QgsComposerMapGrid::BorderSide )border );
1726 
1727 }
1728 
1730 {
1733 }
1734 
1736 {
1737  QgsComposerMapGrid* g = grid();
1739 }
1740 
1742 {
1745 }
1746 
1748 {
1749  QgsComposerMapGrid* g = grid();
1751 }
1752 
1754 {
1757 }
1758 
1760 {
1761  QgsComposerMapGrid* g = grid();
1762  g->setFrameWidth( w );
1763 }
1764 
1766 {
1768  return g->frameWidth();
1769 }
1770 
1772 {
1773  QgsComposerMapGrid* g = grid();
1774  g->setFramePenSize( w );
1775 }
1776 
1778 {
1780  return g->framePenSize();
1781 }
1782 
1784 {
1785  QgsComposerMapGrid* g = grid();
1786  g->setFramePenColor( c );
1787 }
1788 
1790 {
1792  return g->framePenColor();
1793 }
1794 
1796 {
1797  QgsComposerMapGrid* g = grid();
1798  g->setFrameFillColor1( c );
1799 }
1800 
1802 {
1804  return g->frameFillColor1();
1805 }
1806 
1808 {
1809  QgsComposerMapGrid* g = grid();
1810  g->setFrameFillColor2( c );
1811 }
1812 
1814 {
1816  return g->frameFillColor2();
1817 }
1818 
1820 {
1821  QgsComposerMapGrid* g = grid();
1822  g->setCrossLength( l );
1823 }
1824 
1826 {
1828  return g->crossLength();
1829 }
1830 
1832 {
1833  if ( mOverviews.size() < 1 )
1834  {
1835  QgsComposerMapOverview* overview = new QgsComposerMapOverview( tr( "Overview %1" ).arg( 1 ), this );
1836  mOverviews.push_back( overview );
1837  }
1838  return mOverviews.at( 0 );
1839 }
1840 
1842 {
1843  return const_cast<QgsComposerMap*>( this )->firstMapOverview();
1844 }
1845 
1847 {
1848  qDeleteAll( mOverviews );
1849  mOverviews.clear();
1850 }
1851 
1853 {
1854  QList< QgsComposerMapOverview* >::const_iterator overviewIt = mOverviews.constBegin();
1855  for ( ; overviewIt != mOverviews.constEnd(); ++overviewIt )
1856  {
1857  ( *overviewIt )->drawOverview( p );
1858  }
1859 }
1860 
1861 void QgsComposerMap::setGridBlendMode( QPainter::CompositionMode blendMode )
1862 {
1863  QgsComposerMapGrid* g = grid();
1864  g->setBlendMode( blendMode );
1865 }
1866 
1867 QPainter::CompositionMode QgsComposerMap::gridBlendMode() const
1868 {
1870  return g->blendMode();
1871 }
1872 
1874 {
1875  return mCurrentRectangle;
1876 }
1877 
1879 {
1880  QRectF rectangle = rect();
1881  double frameExtension = mFrame ? pen().widthF() / 2.0 : 0.0;
1882  double maxGridExtension = mGridStack ? mGridStack->maxGridExtension() : 0;
1883 
1884  double maxExtension = qMax( frameExtension, maxGridExtension );
1885 
1886  rectangle.setLeft( rectangle.left() - maxExtension );
1887  rectangle.setRight( rectangle.right() + maxExtension );
1888  rectangle.setTop( rectangle.top() - maxExtension );
1889  rectangle.setBottom( rectangle.bottom() + maxExtension );
1890  if ( rectangle != mCurrentRectangle )
1891  {
1892  prepareGeometryChange();
1893  mCurrentRectangle = rectangle;
1894  }
1895 }
1896 
1898 {
1899  QgsComposerItem::setFrameOutlineWidth( outlineWidth );
1901 }
1902 
1904 {
1905  double dx = mXOffset;
1906  double dy = mYOffset;
1907  transformShift( dx, dy );
1908  return QgsRectangle( currentMapExtent()->xMinimum() - dx, currentMapExtent()->yMinimum() - dy, currentMapExtent()->xMaximum() - dx, currentMapExtent()->yMaximum() - dy );
1909 }
1910 
1912 {
1913  double dx = mXOffset;
1914  double dy = mYOffset;
1915  //qWarning("offset");
1916  //qWarning(QString::number(dx).toLocal8Bit().data());
1917  //qWarning(QString::number(dy).toLocal8Bit().data());
1918  transformShift( dx, dy );
1919  //qWarning("transformed:");
1920  //qWarning(QString::number(dx).toLocal8Bit().data());
1921  //qWarning(QString::number(dy).toLocal8Bit().data());
1922  QPolygonF poly = visibleExtentPolygon();
1923  poly.translate( -dx, -dy );
1924  return poly;
1925 }
1926 
1927 void QgsComposerMap::mapPolygon( const QgsRectangle& extent, QPolygonF& poly ) const
1928 {
1929  poly.clear();
1930  if ( mEvaluatedMapRotation == 0 )
1931  {
1932  poly << QPointF( extent.xMinimum(), extent.yMaximum() );
1933  poly << QPointF( extent.xMaximum(), extent.yMaximum() );
1934  poly << QPointF( extent.xMaximum(), extent.yMinimum() );
1935  poly << QPointF( extent.xMinimum(), extent.yMinimum() );
1936  return;
1937  }
1938 
1939  //there is rotation
1940  QgsPoint rotationPoint(( extent.xMaximum() + extent.xMinimum() ) / 2.0, ( extent.yMaximum() + extent.yMinimum() ) / 2.0 );
1941  double dx, dy; //x-, y- shift from rotation point to corner point
1942 
1943  //top left point
1944  dx = rotationPoint.x() - extent.xMinimum();
1945  dy = rotationPoint.y() - extent.yMaximum();
1947  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1948 
1949  //top right point
1950  dx = rotationPoint.x() - extent.xMaximum();
1951  dy = rotationPoint.y() - extent.yMaximum();
1953  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1954 
1955  //bottom right point
1956  dx = rotationPoint.x() - extent.xMaximum();
1957  dy = rotationPoint.y() - extent.yMinimum();
1959  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1960 
1961  //bottom left point
1962  dx = rotationPoint.x() - extent.xMinimum();
1963  dy = rotationPoint.y() - extent.yMinimum();
1965  poly << QPointF( rotationPoint.x() - dx, rotationPoint.y() - dy );
1966 }
1967 
1969 {
1970  QPolygonF poly;
1971  mapPolygon( *currentMapExtent(), poly );
1972  return poly;
1973 }
1974 
1976 {
1977  if ( !QgsComposerItem::id().isEmpty() )
1978  {
1979  return QgsComposerItem::id();
1980  }
1981 
1982  return tr( "Map %1" ).arg( mId );
1983 }
1984 
1986 {
1987  mOverviews.append( overview );
1988 }
1989 
1990 void QgsComposerMap::removeOverview( const QString &name )
1991 {
1992  for ( int i = mOverviews.size() - 1; i >= 0; --i )
1993  {
1994  if ( mOverviews.at( i )->name() == name )
1995  {
1996  delete mOverviews.takeAt( i );
1997  }
1998  }
1999 }
2000 
2001 void QgsComposerMap::moveOverviewUp( const QString &name )
2002 {
2003  QgsComposerMapOverview* overview = mapOverview( name );
2004  if ( !overview )
2005  {
2006  return;
2007  }
2008 
2009  int index = mOverviews.indexOf( overview );
2010  if ( index >= mOverviews.size() - 1 )
2011  {
2012  return;
2013  }
2014  mOverviews.swap( index, index + 1 );
2015  update();
2016 }
2017 
2018 void QgsComposerMap::moveOverviewDown( const QString &name )
2019 {
2020  QgsComposerMapOverview* overview = mapOverview( name );
2021  if ( !overview )
2022  {
2023  return;
2024  }
2025 
2026  int index = mOverviews.indexOf( overview );
2027  if ( index < 1 )
2028  {
2029  return;
2030  }
2031  mOverviews.swap( index, index - 1 );
2032  update();
2033 }
2034 
2036 {
2037  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.constBegin();
2038  for ( ; it != mOverviews.constEnd(); ++it )
2039  {
2040  if (( *it )->id() == id )
2041  {
2042  return ( *it );
2043  }
2044  }
2045 
2046  return 0;
2047 }
2048 
2050 {
2051  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.begin();
2052  for ( ; it != mOverviews.end(); ++it )
2053  {
2054  if (( *it )->id() == id )
2055  {
2056  return ( *it );
2057  }
2058  }
2059 
2060  return 0;
2061 }
2062 
2063 QList<QgsComposerMapOverview *> QgsComposerMap::mapOverviews() const
2064 {
2065  QList< QgsComposerMapOverview* > list;
2066  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.begin();
2067  for ( ; it != mOverviews.end(); ++it )
2068  {
2069  list.append( *it );
2070  }
2071  return list;
2072 }
2073 
2075 {
2076  QList< QgsComposerMapOverview* >::const_iterator it = mOverviews.begin();
2077  for ( ; it != mOverviews.end(); ++it )
2078  {
2079  ( *it )->connectSignals();
2080  }
2081 }
2082 
2084 {
2085  QgsRectangle newExtent = *currentMapExtent();
2086  if ( mEvaluatedMapRotation == 0 )
2087  {
2088  extent = newExtent;
2089  }
2090  else
2091  {
2092  QPolygonF poly;
2093  mapPolygon( newExtent, poly );
2094  QRectF bRect = poly.boundingRect();
2095  extent.setXMinimum( bRect.left() );
2096  extent.setXMaximum( bRect.right() );
2097  extent.setYMinimum( bRect.top() );
2098  extent.setYMaximum( bRect.bottom() );
2099  }
2100 }
2101 
2103 {
2104  double extentWidth = currentMapExtent()->width();
2105  if ( extentWidth <= 0 )
2106  {
2107  return 1;
2108  }
2109  return rect().width() / extentWidth;
2110 }
2111 
2113 {
2115  overview->setFrameMap( mapId );
2116 }
2117 
2119 {
2120  const QgsComposerMapOverview* overview = constFirstMapOverview();
2121  return overview->frameMapId();
2122 }
2123 
2125 {
2126  //updates data defined properties and redraws item to match
2127  if ( property == QgsComposerObject::MapRotation || property == QgsComposerObject::MapScale ||
2128  property == QgsComposerObject::MapXMin || property == QgsComposerObject::MapYMin ||
2129  property == QgsComposerObject::MapXMax || property == QgsComposerObject::MapYMax ||
2130  property == QgsComposerObject::AllProperties )
2131  {
2133  emit itemChanged();
2134  emit extentChanged();
2135  }
2136 
2137  //force redraw
2138  cache();
2139 
2141 }
2142 
2144 {
2146  overview->setFrameSymbol( symbol );
2147 }
2148 
2150 {
2152  return overview->frameSymbol();
2153 }
2154 
2155 QPainter::CompositionMode QgsComposerMap::overviewBlendMode() const
2156 {
2157  const QgsComposerMapOverview* overview = constFirstMapOverview();
2158  return overview->blendMode();
2159 }
2160 
2161 void QgsComposerMap::setOverviewBlendMode( QPainter::CompositionMode blendMode )
2162 {
2164  overview->setBlendMode( blendMode );
2165 }
2166 
2168 {
2169  const QgsComposerMapOverview* overview = constFirstMapOverview();
2170  return overview->inverted();
2171 }
2172 
2174 {
2176  overview->setInverted( inverted );
2177 }
2178 
2180 {
2181  const QgsComposerMapOverview* overview = constFirstMapOverview();
2182  return overview->centered();
2183 }
2184 
2186 {
2188  overview->setCentered( centered );
2189  //overviewExtentChanged();
2190 }
2191 
2193 {
2194  QgsComposerMapGrid* g = grid();
2195  g->setLineSymbol( symbol );
2196 }
2197 
2199 {
2200  QgsComposerMapGrid* g = grid();
2201  return g->lineSymbol();
2202 }
2203 
2205 {
2206  QgsComposerMapGrid* g = grid();
2207  g->setEnabled( enabled );
2208 }
2209 
2211 {
2213  return g->enabled();
2214 }
2215 
2216 void QgsComposerMap::transformShift( double& xShift, double& yShift ) const
2217 {
2218  double mmToMapUnits = 1.0 / mapUnitsToMM();
2219  double dxScaled = xShift * mmToMapUnits;
2220  double dyScaled = - yShift * mmToMapUnits;
2221 
2222  QgsComposerUtils::rotate( mEvaluatedMapRotation, dxScaled, dyScaled );
2223 
2224  xShift = dxScaled;
2225  yShift = dyScaled;
2226 }
2227 
2228 QPointF QgsComposerMap::mapToItemCoords( const QPointF& mapCoords ) const
2229 {
2230  QPolygonF mapPoly = transformedMapPolygon();
2231  if ( mapPoly.size() < 1 )
2232  {
2233  return QPointF( 0, 0 );
2234  }
2235 
2236  QgsRectangle tExtent = transformedExtent();
2237  QgsPoint rotationPoint(( tExtent.xMaximum() + tExtent.xMinimum() ) / 2.0, ( tExtent.yMaximum() + tExtent.yMinimum() ) / 2.0 );
2238  double dx = mapCoords.x() - rotationPoint.x();
2239  double dy = mapCoords.y() - rotationPoint.y();
2241  QgsPoint backRotatedCoords( rotationPoint.x() + dx, rotationPoint.y() + dy );
2242 
2243  QgsRectangle unrotatedExtent = transformedExtent();
2244  double xItem = rect().width() * ( backRotatedCoords.x() - unrotatedExtent.xMinimum() ) / unrotatedExtent.width();
2245  double yItem = rect().height() * ( 1 - ( backRotatedCoords.y() - unrotatedExtent.yMinimum() ) / unrotatedExtent.height() );
2246  return QPointF( xItem, yItem );
2247 }
2248 
2249 void QgsComposerMap::drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
2250 {
2251  if ( !mMapCanvas || !mDrawCanvasItems )
2252  {
2253  return;
2254  }
2255 
2256  QList<QGraphicsItem*> itemList = mMapCanvas->items();
2257  if ( itemList.size() < 1 )
2258  {
2259  return;
2260  }
2261  QGraphicsItem* currentItem = 0;
2262 
2263  for ( int i = itemList.size() - 1; i >= 0; --i )
2264  {
2265  currentItem = itemList.at( i );
2266  //don't draw mapcanvasmap (has z value -10)
2267  if ( !currentItem || currentItem->data( 0 ).toString() != "AnnotationItem" )
2268  {
2269  continue;
2270  }
2271  drawCanvasItem( currentItem, painter, itemStyle );
2272  }
2273 }
2274 
2275 void QgsComposerMap::drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle )
2276 {
2277  if ( !item || !mMapCanvas || !item->isVisible() )
2278  {
2279  return;
2280  }
2281 
2282  painter->save();
2283  painter->setRenderHint( QPainter::Antialiasing );
2284 
2285  //determine scale factor according to graphics view dpi
2286  double scaleFactor = 1.0 / mMapCanvas->logicalDpiX() * 25.4;
2287 
2288  double itemX, itemY;
2289  QGraphicsItem* parent = item->parentItem();
2290  if ( !parent )
2291  {
2292  QPointF mapPos = composerMapPosForItem( item );
2293  itemX = mapPos.x();
2294  itemY = mapPos.y();
2295  }
2296  else //place item relative to the parent item
2297  {
2298  QPointF itemScenePos = item->scenePos();
2299  QPointF parentScenePos = parent->scenePos();
2300 
2301  QPointF mapPos = composerMapPosForItem( parent );
2302 
2303  itemX = mapPos.x() + ( itemScenePos.x() - parentScenePos.x() ) * scaleFactor;
2304  itemY = mapPos.y() + ( itemScenePos.y() - parentScenePos.y() ) * scaleFactor;
2305  }
2306  painter->translate( itemX, itemY );
2307 
2308  painter->scale( scaleFactor, scaleFactor );
2309 
2310  //a little trick to let the item know that the paint request comes from the composer
2311  item->setData( 1, "composer" );
2312  item->paint( painter, itemStyle, 0 );
2313  item->setData( 1, "" );
2314  painter->restore();
2315 }
2316 
2317 QPointF QgsComposerMap::composerMapPosForItem( const QGraphicsItem* item ) const
2318 {
2319  if ( !item || !mMapCanvas )
2320  {
2321  return QPointF( 0, 0 );
2322  }
2323 
2324  if ( currentMapExtent()->height() <= 0 || currentMapExtent()->width() <= 0 || mMapCanvas->width() <= 0 || mMapCanvas->height() <= 0 )
2325  {
2326  return QPointF( 0, 0 );
2327  }
2328 
2329  QRectF graphicsSceneRect = mMapCanvas->sceneRect();
2330  QPointF itemScenePos = item->scenePos();
2331  QgsRectangle mapRendererExtent = mComposition->mapSettings().visibleExtent();
2332 
2333  double mapX = itemScenePos.x() / graphicsSceneRect.width() * mapRendererExtent.width() + mapRendererExtent.xMinimum();
2334  double mapY = mapRendererExtent.yMaximum() - itemScenePos.y() / graphicsSceneRect.height() * mapRendererExtent.height();
2335  return mapToItemCoords( QPointF( mapX, mapY ) );
2336 }
2337 
2339 {
2340  if ( !mComposition )
2341  {
2342  return;
2343  }
2344 
2345  const QgsComposerMap* existingMap = mComposition->getComposerMapById( mId );
2346  if ( !existingMap )
2347  {
2348  return; //keep mId as it is still available
2349  }
2350 
2351  int maxId = -1;
2352  QList<const QgsComposerMap*> mapList = mComposition->composerMapItems();
2353  QList<const QgsComposerMap*>::const_iterator mapIt = mapList.constBegin();
2354  for ( ; mapIt != mapList.constEnd(); ++mapIt )
2355  {
2356  if (( *mapIt )->id() > maxId )
2357  {
2358  maxId = ( *mapIt )->id();
2359  }
2360  }
2361  mId = maxId + 1;
2362 }
2363 
2364 bool QgsComposerMap::imageSizeConsideringRotation( double& width, double& height ) const
2365 {
2366  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2370 }
2371 
2372 bool QgsComposerMap::cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const
2373 {
2374  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2378 }
2379 
2380 void QgsComposerMap::sizeChangedByRotation( double& width, double& height )
2381 {
2382  //kept for api compatibility with QGIS 2.0 - use mMapRotation
2386 }
2387 
2389 {
2390  mAtlasDriven = enabled;
2391 
2392  if ( !enabled )
2393  {
2394  //if not enabling the atlas, we still need to refresh the map extents
2395  //so that data defined extents and scale are recalculated
2397  }
2398 }
2399 
2401 {
2402  return mAtlasScalingMode == Fixed;
2403 }
2404 
2406 {
2407  // implicit : if set to false => auto scaling
2408  mAtlasScalingMode = fixed ? Fixed : Auto;
2409 }
2410 
Q_DECL_DEPRECATED 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.
void setStyle(const GridStyle style)
Sets the grid style, which controls how the grid is drawn over the map's contents.
void preparedForAtlas()
Is emitted when the map has been prepared for atlas rendering, just before actual rendering...
void addGrid(QgsComposerMapGrid *grid)
Adds a new map grid to the stack and takes ownership of the grid.
AtlasScalingMode
Scaling modes used for the serial rendering (atlas)
QgsComposition::AtlasMode atlasMode() const
Returns the current atlas mode of the composition.
QColor frameFillColor1() const
Retrieves the first fill color for the grid frame.
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
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.
void setAnnotationDirection(const AnnotationDirection direction, const BorderSide border)
Sets the direction for drawing frame annotations.
double mMapRotation
Map rotation.
double intervalX() const
Gets the interval between grid lines in the x-direction.
void setBlendMode(const QPainter::CompositionMode mode)
Sets the blending mode used for drawing the grid.
Q_DECL_DEPRECATED GridAnnotationDirection gridAnnotationDirection(QgsComposerMap::Border border) const
Q_DECL_DEPRECATED QgsLineSymbolV2 * gridLineSymbol()
Q_DECL_DEPRECATED void setGridIntervalY(double interval)
Sets coordinate interval in y-direction for composergrid.
void setOverviewCentered(bool centered)
Set the overview's centering mode.
void setLineSymbol(QgsLineSymbolV2 *symbol)
Sets the line symbol used for drawing grid lines.
GridStyle
Grid drawing style.
bool containsWMSLayer() const
True if composer map renders a WMS layer.
QgsComposerMapGrid * grid(const QString &gridId) const
Returns a reference to a grid within the stack.
Q_DECL_DEPRECATED void setGridAnnotationFormat(GridAnnotationFormat f)
Q_DECL_DEPRECATED void setGridFrameFillColor1(const QColor &c)
Sets first fill color for grid zebra frame.
Q_DECL_DEPRECATED double gridIntervalX() const
void setOffsetY(const double offset)
Sets the offset for grid lines in the y-direction.
QgsComposerMapGridStack * mGridStack
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:169
double mapUnitsToMM() const
Returns the conversion factor map units -> mm.
bool hideCoverage() const
Returns true if the atlas is set to hide the coverage layer.
Q_DECL_DEPRECATED void setGridEnabled(bool enabled)
Enables a coordinate grid that is shown on top of this composermap.
const QgsLineSymbolV2 * lineSymbol() const
Gets the line symbol used for drawing grid lines.
Q_DECL_DEPRECATED double gridFramePenSize() const
void setFramePenSize(const double width)
Sets the width of the outline drawn in the grid frame.
void assignFreeId()
Sets mId to a number not yet used in the composition.
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
Returns first map grid or creates an empty one if none.
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.
Q_DECL_DEPRECATED 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
A collection of grids which is drawn above the map content in a QgsComposerMap.
FrameStyle
Style for grid frame.
QStringList layerSet() const
Getter for stored layer set that is used if mKeepLayerSet is true.
Q_DECL_DEPRECATED void setAnnotationFontColor(const QColor &c)
Sets font color for grid annotations.
void cache()
Create cache image.
Q_DECL_DEPRECATED bool showGridAnnotation() const
bool centered() const
Returns true if the extent is forced to center on the overview.
Q_DECL_DEPRECATED void setGridStyle(GridStyle style)
Sets coordinate grid style to solid or cross.
Q_DECL_DEPRECATED bool imageSizeConsideringRotation(double &width, double &height) const
Calculates width and hight of the picture (in mm) such that it fits into the item frame with the give...
QList< const QgsComposerMap * > composerMapItems() const
Returns pointers to all composer maps in the scene.
QMap< QgsComposerObject::DataDefinedProperty, QString > mDataDefinedNames
Map of data defined properties for the item to string name to use when exporting item to xml...
A item that forms part of a map composition.
void 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.
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
Gets the distance between the map frame and annotations.
void setDpi(double dpi)
Set the dpi to be used in scale calculations.
AtlasScalingMode mAtlasScalingMode
Current atlas scaling mode.
QGraphicsView * mMapCanvas
double mLastValidViewScaleFactor
Backup to restore item appearance if no view scale factor is available.
QColor frameFillColor2() const
Retrieves the second fill color for the grid frame.
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
FrameStyle frameStyle() const
Gets the grid frame style.
virtual QString displayName() const
Get item display name.
static QColor decodeColor(QString str)
virtual void drawFrame(QPainter *p)
Draw black frame around item.
void updateCachedImage()
Called if map canvas has changed.
void setAnnotationFont(const QFont &font)
Sets the font used for drawing grid annotations.
Flags flags() const
Return combination of flags used for rendering.
Q_DECL_DEPRECATED double annotationFrameDistance() const
QColor framePenColor() const
Retrieves the color of the outline drawn in the grid frame.
Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height) const
Calculates corner point after rotation and scaling.
bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
sets state from Dom document
bool containsAdvancedEffects() const
Returns whether any grids within the stack contain advanced effects, such as blending modes...
QPolygonF transformedMapPolygon() const
Returns extent that considers rotation and shift with mOffsetX / mOffsetY.
QColor backgroundColor() const
Gets the background color for this item.
virtual void setFrameOutlineWidth(const double outlineWidth)
Sets frame outline width.
A non GUI class for rendering a map layer set onto a QPainter.
AnnotationDirection
Direction of grid annotations.
void setLayers(const QStringList &layers)
Set list of layer IDs for map rendering.
Enable layer transparency and blending effects.
void setGridLineColor(const QColor &color)
Sets color of grid lines.
Q_DECL_DEPRECATED 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.
AnnotationFormat annotationFormat() const
Gets the format for drawing grid annotations.
virtual void refreshDataDefinedProperty(const QgsComposerObject::DataDefinedProperty property=QgsComposerObject::AllProperties)
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
Q_DECL_DEPRECATED GridFrameStyle gridFrameStyle() const
AnnotationFormat
Format for displaying grid annotations.
int readNumEntry(const QString &scope, const QString &key, int def=0, bool *ok=0) const
QRectF boundingRect() const
In case of annotations, the bounding rectangle can be larger than the map item rectangle.
BlendMode
Blending modes enum defining the available composition modes that can be used when rendering a layer...
double x() const
Definition: qgspoint.h:110
void zoomContent(int delta, double x, double y)
Zoom content of map.
DataDefinedProperty
Data defined properties for different item types.
AnnotationPosition annotationPosition(const BorderSide border) const
Gets the position for the grid annotations on a specified side of the map frame.
Q_DECL_DEPRECATED void setGridPenColor(const QColor &c)
Sets the color of the grid pen.
virtual QString name() const =0
return a provider name
void setWidth(double width)
double intervalY() const
Gets the interval between grid lines in the y-direction.
void setCrossLength(const double length)
Sets the length of the cross segments drawn for the grid.
const QgsComposerMapOverview * constFirstMapOverview() const
QFont annotationFont() const
Gets the font used for drawing grid annotations.
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)
Q_DECL_DEPRECATED void setGridAnnotationPrecision(int p)
Sets coordinate precision for grid annotations.
Q_DECL_DEPRECATED 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
Q_DECL_DEPRECATED QPainter::CompositionMode gridBlendMode() const
Returns the grid's blending mode.
QgsRectangle mExtent
void storeCurrentLayerSet()
Stores the current layer set of the qgis mapcanvas in mLayerSet.
void setColor(const QColor &color)
Q_DECL_DEPRECATED 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.
Q_DECL_DEPRECATED double gridFrameWidth() const
QPainter::CompositionMode blendMode() const
Read blend mode for layer.
void moveOverviewUp(const QString &name)
double horizontalViewScaleFactor() const
Returns the zoom factor of the graphics view.
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.
Q_DECL_DEPRECATED 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.
Q_DECL_DEPRECATED 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.
virtual void drawSelectionBoxes(QPainter *p)
Draws additional graphics on selected items.
static QgsLineSymbolV2 * createSimple(const QgsStringMap &properties)
Create a line symbol with one symbol layer: SimpleLine with specified properties. ...
int size() const
Returns the number of grids in the stack.
QPainter::CompositionMode blendMode
friend class QgsComposerMapOverview
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
bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores the state of the grid stack in a DOM node.
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:174
Q_DECL_DEPRECATED void setAnnotationFrameDistance(double d)
Sets distance between map frame and annotations.
void setAnnotationFormat(const AnnotationFormat format)
Sets the format for drawing grid annotations.
double mYOffset
Offset in y direction for showing map cache image.
AnnotationPosition
Position for grid annotations.
double offsetX() const
Gets the offset for grid lines in the x-direction.
void setCentered(const bool centered)
Set the overview's centering mode.
void addOverview(QgsComposerMapOverview *overview)
Adds new map overview (takes ownership)
void setAnnotationEnabled(const bool enabled)
Sets whether annotations should be shown for the grid.
void setNewExtent(const QgsRectangle &extent)
Sets new extent for the map.
Q_DECL_DEPRECATED void setGridPen(const QPen &p)
Sets the pen to draw composer grid.
Q_DECL_DEPRECATED void setGridFrameFillColor2(const QColor &c)
Sets second fill color for grid zebra frame.
bool enabled() const
Returns whether the grid will be drawn.
Q_DECL_DEPRECATED 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
GridStyle style() const
Gets the grid's style, which controls how the grid is drawn over the map's contents.
Q_DECL_DEPRECATED bool atlasFixedScale() const
Returns true if the map uses a fixed scale when in atlas mode.
QGis::UnitType mapUnits() const
Get units of map's geographical coordinates - used for scale calculation.
An individual grid which is drawn above the map content in a QgsComposerMap.
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
QPainter::CompositionMode shapeBlendMode
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)
double offsetY() const
Gets the offset for grid lines in the y-direction.
Q_DECL_DEPRECATED void setGridFramePenSize(double w)
Set grid frame pen thickness.
void setGridLineWidth(const double width)
Sets width of grid lines.
double mapRotation(QgsComposerObject::PropertyValueType valueType=QgsComposerObject::EvaluatedValue) const
Returns the rotation used for drawing the map within the composer item.
double framePenSize() const
Retrieves the width of the outline drawn in the grid frame.
bool readXML(const QDomElement &elem, const QDomDocument &doc)
Sets the grid stack's state from a DOM document.
bool mAtlasDriven
True if map is being controlled by an atlas.
PreviewMode
Preview style.
Q_DECL_DEPRECATED GridAnnotationPosition gridAnnotationPosition(QgsComposerMap::Border border) const
QPolygonF visibleExtentPolygon() const
Returns a polygon representing the current visible map extent, considering map extents and rotation...
void removeOverview(const QString &name)
A class to represent a point geometry.
Definition: qgspoint.h:63
void setFrameWidth(const double width)
Sets the grid frame width.
void setAnnotationFontColor(const QColor &color)
Sets the font color used for drawing grid annotations.
Graphics scene for map printing.
Q_DECL_DEPRECATED QColor gridFramePenColor() const
Get pen color for grid frame.
This class tracks map layers that are currently loaded and provides a means to fetch a pointer to a m...
Object representing map window.
Enable drawing of vertex markers for layers in editing mode.
const QgsComposerMapOverview * constMapOverview(const QString &id) const
static void rotate(const double angle, double &x, double &y)
Rotates a point / vector around the origin.
Q_DECL_DEPRECATED 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.
BorderSide
Border sides for annotations.
QString qgsDoubleToString(const double &a, const int &precision=17)
Definition: qgis.h:316
PreviewMode previewMode() const
void setFrameFillColor1(const QColor &color)
Sets the first fill color used for the grid frame.
void setFramePenColor(const QColor &color)
Sets the color of the outline drawn in the grid frame.
void setAnnotationPosition(const AnnotationPosition position, const BorderSide border)
Sets the position for the grid annotations on a specified side of the map frame.
virtual ~QgsComposerMap()
Q_DECL_DEPRECATED int gridAnnotationPrecision() const
Q_DECL_DEPRECATED void setGridAnnotationDirection(GridAnnotationDirection d, QgsComposerMap::Border border)
Calculates scale for a given combination of canvas size, map extent, and monitor dpi.
Q_DECL_DEPRECATED void setCrossLength(double l)
Sets length of the cross segments (if grid style is cross)
int layerTransparency() const
Read transparency for layer.
Q_DECL_DEPRECATED bool gridEnabled() const
virtual QgsSymbolV2 * clone() const
static QPainter::CompositionMode getCompositionMode(const QgsMapRenderer::BlendMode &blendMode)
Returns a QPainter::CompositionMode corresponding to a BlendMode Added in 1.9.
int annotationPrecision() const
Returns the coordinate precision for grid annotations.
virtual void setFrameOutlineWidth(const double outlineWidth)
Sets frame outline width.
#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
Retrieves the blending mode used for drawing the grid.
void paint(QPainter *painter, const QStyleOptionGraphicsItem *itemStyle, QWidget *pWidget)
Reimplementation of QCanvasItem::paint - draw on canvas.
QgsComposition * mComposition
void setEnabled(const bool enabled)
Controls whether the grid will be drawn.
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.
QColor annotationFontColor() const
Gets the font color used for drawing grid annotations.
bool mKeepLayerSet
Flag if layers to be displayed should be read from qgis canvas (true) or from stored list in mLayerSe...
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.
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.
QgsRectangle extent() const
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.
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
Q_DECL_DEPRECATED 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 setMapRotation(double r)
Sets rotation for the map - this does not affect the composer item shape, only the way the map is dra...
virtual void setSceneRect(const QRectF &rectangle)
Sets this items bound in scene coordinates such that 1 item size units corresponds to 1 scene size un...
void setAnnotationPrecision(const int precision)
Sets the coordinate precision for grid annotations.
Q_DECL_DEPRECATED void setGridAnnotationPosition(GridAnnotationPosition p, QgsComposerMap::Border border)
void drawOverviews(QPainter *p)
void transformShift(double &xShift, double &yShift) const
Scales a composer map shift (in MM) and rotates it by mRotation.
Q_DECL_DEPRECATED double gridIntervalY() 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.
void setIntervalY(const double interval)
Sets the interval between grid lines in the y-direction.
const QMap< QString, QgsMapLayer * > & mapLayers()
Retrieve the mapLayers collection (mainly intended for use by projection)
bool annotationEnabled() const
Gets whether annotations are shown for the grid.
QgsComposerMap(QgsComposition *composition, int x, int y, int width, int height)
Constructor.
QgsRectangle mAtlasFeatureExtent
void drawGrids(QPainter *painter)
Draws the grids from the stack on a specified painter.
void setInverted(const bool inverted)
Sets the overview's inversion mode.
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
Retrieves the length of the cross segments drawn for the grid.
QStringList layers() const
Get list of layer IDs for map rendering The layers are stored in the reverse order of how they are re...
QgsAtlasComposition & atlasComposition()
Q_DECL_DEPRECATED double crossLength()
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
Q_DECL_DEPRECATED double gridOffsetY() const
Q_DECL_DEPRECATED void setGridOffsetX(double offset)
Sets x-coordinate offset for composer grid.
Enable vector simplification and other rendering optimizations.
QPainter::CompositionMode shadowBlendMode
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.
Q_DECL_DEPRECATED void setGridLineSymbol(QgsLineSymbolV2 *symbol)
void extentChanged()
Q_DECL_DEPRECATED void setGridPenWidth(double w)
Sets width of grid pen.
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.
double maxGridExtension() const
Calculates the maximum distance grids within the stack extend beyond the QgsComposerMap's item rect...
void setFrameFillColor2(const QColor &color)
Sets the second fill color used for the grid frame.
void setFrameStyle(const FrameStyle style)
Sets the grid frame style.
Q_DECL_DEPRECATED 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
AnnotationDirection annotationDirection(const BorderSide border) const
Gets the direction for drawing frame annotations.
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
Q_DECL_DEPRECATED void setGridFrameStyle(GridFrameStyle style)
Set grid frame style (NoGridFrame or Zebra)
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...
Q_DECL_DEPRECATED GridAnnotationFormat gridAnnotationFormat() const
void renderSynchronously()
Render the map synchronously in this thread.
void setIntervalX(const double interval)
Sets the interval between grid lines in the x-direction.
void moveOverviewDown(const QString &name)
void refreshMapExtents()
Refresh the map's extents, considering data defined extent, scale and rotation.
int frameMapId() const
Returns id of overview frame (or -1 if no overfiew frame)
void setOffsetX(const double offset)
Sets the offset for grid lines in the x-direction.
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.
Q_DECL_DEPRECATED 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
QgsComposerMapGrid * grid()
Returns the map item's first grid.
Q_DECL_DEPRECATED void setGridFramePenColor(const QColor &c)
Sets pen color for grid frame.
QgsRectangle transformedExtent() const
Returns extent that considers mOffsetX / mOffsetY (during content move)
void setAnnotationFrameDistance(const double distance)
Sets the distance between the map frame and annotations.
Q_DECL_DEPRECATED void sizeChangedByRotation(double &width, double &height, double rotation)
Calculates width / height of the bounding box of a rotated rectangle.
double frameWidth() const
Gets the grid frame width.
double height() const
Height of the rectangle.
Definition: qgsrectangle.h:209
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.
Q_DECL_DEPRECATED GridStyle gridStyle() const
Base class for raster data providers.
QColor color() const
bool inverted() const
Returns true if the overview frame is inverted.
#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.
QString id() const
Get item's id (which is not necessarly unique)