QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
qgscomposermap.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposermap.h
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 #ifndef QGSCOMPOSERMAP_H
18 #define QGSCOMPOSERMAP_H
19 
20 //#include "ui_qgscomposermapbase.h"
21 #include "qgscomposeritem.h"
22 #include "qgsrectangle.h"
23 #include <QFont>
24 #include <QGraphicsRectItem>
25 
26 class QgsComposition;
30 class QgsComposerMapGrid;
31 class QgsMapRenderer;
32 class QgsMapToPixel;
33 class QDomNode;
34 class QDomDocument;
35 class QGraphicsView;
36 class QPainter;
37 class QgsFillSymbolV2;
38 class QgsLineSymbolV2;
39 class QgsVectorLayer;
40 
47 class CORE_EXPORT QgsComposerMap : public QgsComposerItem
48 {
49  Q_OBJECT
50 
51  public:
53  QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height );
55  QgsComposerMap( QgsComposition *composition );
56  virtual ~QgsComposerMap();
57 
59  virtual int type() const { return ComposerMap; }
60 
63  {
64  Cache = 0, // Use raster cache
65  Render, // Render the map
66  Rectangle // Display only rectangle
67  };
68 
69  //grid enums are moved to QgsComposerMapGrid
70  //TODO - remove for QGIS 3.0
71  enum GridStyle
72  {
73  Solid = 0, //solid lines
74  Cross, //only draw line crossings
76  FrameAnnotationsOnly
77  };
78 
80  {
81  InsideMapFrame = 0,
83  Disabled
84  };
85 
87  {
88  Horizontal = 0,
91  BoundaryDirection
92  };
93 
95  {
96  Decimal = 0,
103  DegreeMinuteSecondPadded
104  };
105 
107  {
108  NoGridFrame = 0,
109  Zebra, // black/white pattern
113  LineBorder
114  };
115 
117  enum Border
118  {
122  Top
123  };
124 
128  {
129  Fixed, /*< The current scale of the map is used for each feature of the atlas */
130  Predefined, /*< A scale is chosen from the predefined scales. The smallest scale from
131  the list of scales where the atlas feature is fully visible is chosen.
132  @see QgsAtlasComposition::setPredefinedScales.
133  @note This mode is only valid for polygon or line atlas coverage layers
134  */
135  Auto /*< The extent is adjusted so that each feature is fully visible.
136  A margin is applied around the center @see setAtlasMargin
137  @note This mode is only valid for polygon or line atlas coverage layers*/
138  };
139 
147  void draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi, double* forceWidthScale = 0 );
148 
150  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
151 
153  void cache();
154 
157  QgsMapSettings mapSettings( const QgsRectangle& extent, const QSizeF& size, int dpi ) const;
158 
160  int id() const {return mId;}
161 
163  bool isDrawing() const {return mDrawing;}
164 
166  void resize( double dx, double dy );
167 
171  void moveContent( double dx, double dy );
172 
179  Q_DECL_DEPRECATED void zoomContent( int delta, double x, double y );
180 
187  virtual void zoomContent( const double factor, const QPointF point, const ZoomMode mode = QgsComposerItem::Zoom );
188 
190  void setSceneRect( const QRectF& rectangle );
191 
193  double scale() const;
194 
196  void setNewScale( double scaleDenominator, bool forceUpdate = true );
197 
204  void setNewExtent( const QgsRectangle& extent );
205 
214  void zoomToExtent( const QgsRectangle& extent );
215 
219  void setNewAtlasFeatureExtent( const QgsRectangle& extent );
220 
224  Q_DECL_DEPRECATED void toggleAtlasPreview() {}
225 
232  QgsRectangle* currentMapExtent();
233  const QgsRectangle* currentMapExtent() const;
234 
235  PreviewMode previewMode() const {return mPreviewMode;}
236  void setPreviewMode( PreviewMode m );
237 
239  bool keepLayerSet() const {return mKeepLayerSet;}
241  void setKeepLayerSet( bool enabled ) {mKeepLayerSet = enabled;}
242 
244  QStringList layerSet() const {return mLayerSet;}
246  void setLayerSet( const QStringList& layerSet ) {mLayerSet = layerSet;}
248  void storeCurrentLayerSet();
249 
250  // Set cache outdated
251  void setCacheUpdated( bool u = false );
252 
253  QgsRectangle extent() const {return mExtent;}
254 
256  Q_DECL_DEPRECATED const QgsMapRenderer* mapRenderer() const;
257 
259  void setOffset( double xOffset, double yOffset );
260 
262  bool containsWMSLayer() const;
263 
265  bool containsAdvancedEffects() const;
266 
271  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
272 
277  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
278 
282  Q_DECL_DEPRECATED void setGridEnabled( bool enabled );
283 
287  Q_DECL_DEPRECATED bool gridEnabled() const;
288 
292  Q_DECL_DEPRECATED void setGridStyle( GridStyle style );
293 
297  Q_DECL_DEPRECATED GridStyle gridStyle() const;
298 
302  Q_DECL_DEPRECATED void setGridIntervalX( double interval );
303 
307  Q_DECL_DEPRECATED double gridIntervalX() const;
308 
312  Q_DECL_DEPRECATED void setGridIntervalY( double interval );
313 
317  Q_DECL_DEPRECATED double gridIntervalY() const;
318 
322  Q_DECL_DEPRECATED void setGridOffsetX( double offset );
323 
327  Q_DECL_DEPRECATED double gridOffsetX() const;
328 
332  Q_DECL_DEPRECATED void setGridOffsetY( double offset );
333 
337  Q_DECL_DEPRECATED double gridOffsetY() const;
338 
342  Q_DECL_DEPRECATED void setGridPen( const QPen& p );
343 
347  Q_DECL_DEPRECATED QPen gridPen() const;
348 
352  Q_DECL_DEPRECATED void setGridPenWidth( double w );
353 
357  Q_DECL_DEPRECATED void setGridPenColor( const QColor& c );
358 
362  Q_DECL_DEPRECATED void setGridAnnotationFont( const QFont& f );
363 
367  Q_DECL_DEPRECATED QFont gridAnnotationFont() const;
368 
372  Q_DECL_DEPRECATED void setAnnotationFontColor( const QColor& c );
373 
377  Q_DECL_DEPRECATED QColor annotationFontColor() const;
378 
382  Q_DECL_DEPRECATED void setGridAnnotationPrecision( int p );
383 
387  Q_DECL_DEPRECATED int gridAnnotationPrecision() const;
388 
392  Q_DECL_DEPRECATED void setShowGridAnnotation( bool show );
393 
397  Q_DECL_DEPRECATED bool showGridAnnotation() const;
398 
402  Q_DECL_DEPRECATED void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border );
403 
407  Q_DECL_DEPRECATED GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;
408 
412  Q_DECL_DEPRECATED void setAnnotationFrameDistance( double d );
413 
417  Q_DECL_DEPRECATED double annotationFrameDistance() const;
418 
422  Q_DECL_DEPRECATED void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border );
423 
427  Q_DECL_DEPRECATED GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;
428 
432  Q_DECL_DEPRECATED void setGridAnnotationFormat( GridAnnotationFormat f );
433 
437  Q_DECL_DEPRECATED GridAnnotationFormat gridAnnotationFormat() const;
438 
442  Q_DECL_DEPRECATED void setGridFrameStyle( GridFrameStyle style );
443 
447  Q_DECL_DEPRECATED GridFrameStyle gridFrameStyle() const;
448 
452  Q_DECL_DEPRECATED void setGridFrameWidth( double w );
453 
457  Q_DECL_DEPRECATED double gridFrameWidth() const;
458 
463  Q_DECL_DEPRECATED void setGridFramePenSize( double w );
464 
468  Q_DECL_DEPRECATED double gridFramePenSize() const;
469 
474  Q_DECL_DEPRECATED void setGridFramePenColor( const QColor& c );
475 
480  Q_DECL_DEPRECATED QColor gridFramePenColor() const;
481 
486  Q_DECL_DEPRECATED void setGridFrameFillColor1( const QColor& c );
487 
492  Q_DECL_DEPRECATED QColor gridFrameFillColor1() const;
493 
498  Q_DECL_DEPRECATED void setGridFrameFillColor2( const QColor& c );
499 
504  Q_DECL_DEPRECATED QColor gridFrameFillColor2() const;
505 
509  Q_DECL_DEPRECATED void setCrossLength( double l );
510 
514  Q_DECL_DEPRECATED double crossLength();
515 
519  Q_DECL_DEPRECATED void setGridLineSymbol( QgsLineSymbolV2* symbol );
520 
524  Q_DECL_DEPRECATED QgsLineSymbolV2* gridLineSymbol();
525 
529  Q_DECL_DEPRECATED QPainter::CompositionMode gridBlendMode() const;
530 
534  Q_DECL_DEPRECATED void setGridBlendMode( QPainter::CompositionMode blendMode );
535 
542  QgsComposerMapGridStack* grids() { return mGridStack; }
543 
549  QgsComposerMapGrid* grid();
550 
557  QgsComposerMapOverviewStack* overviews() { return mOverviewStack; }
558 
564  QgsComposerMapOverview* overview();
565 
567  QRectF boundingRect() const;
568 
569  /* reimplement setFrameOutlineWidth, so that updateBoundingRect() is called after setting the frame width */
570  virtual void setFrameOutlineWidth( const double outlineWidth );
571 
576  Q_DECL_DEPRECATED void setRotation( double r );
577 
581  Q_DECL_DEPRECATED double rotation() const { return mMapRotation;}
582 
586  void setMapRotation( double r );
587 
594  double mapRotation( QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;
595 
596  void updateItem();
597 
599  void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; }
600 
601  void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; }
602  bool drawCanvasItems() const { return mDrawCanvasItems; }
603 
605  double mapUnitsToMM() const;
606 
610  Q_DECL_DEPRECATED void setOverviewFrameMap( int mapId );
611 
615  Q_DECL_DEPRECATED int overviewFrameMapId() const;
616 
620  Q_DECL_DEPRECATED void setOverviewFrameMapSymbol( QgsFillSymbolV2* symbol );
621 
625  Q_DECL_DEPRECATED QgsFillSymbolV2* overviewFrameMapSymbol();
626 
630  Q_DECL_DEPRECATED QPainter::CompositionMode overviewBlendMode() const;
631 
635  Q_DECL_DEPRECATED void setOverviewBlendMode( QPainter::CompositionMode blendMode );
636 
640  Q_DECL_DEPRECATED bool overviewInverted() const;
641 
645  Q_DECL_DEPRECATED void setOverviewInverted( bool inverted );
646 
650  Q_DECL_DEPRECATED bool overviewCentered() const;
651 
655  Q_DECL_DEPRECATED void setOverviewCentered( bool centered );
656 
659  void assignFreeId();
660 
665  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
670  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
675  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
676 
682  bool atlasDriven() const { return mAtlasDriven; }
683 
689  void setAtlasDriven( bool enabled );
690 
694  Q_DECL_DEPRECATED bool atlasFixedScale() const;
695 
699  Q_DECL_DEPRECATED void setAtlasFixedScale( bool fixed );
700 
709  AtlasScalingMode atlasScalingMode() const { return mAtlasScalingMode; }
710 
719  void setAtlasScalingMode( AtlasScalingMode mode ) { mAtlasScalingMode = mode; }
720 
730  double atlasMargin( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue );
731 
738  void setAtlasMargin( double margin ) { mAtlasMargin = margin; }
739 
741  void setUpdatesEnabled( bool enabled ) { mUpdatesEnabled = enabled; }
742 
744  bool updatesEnabled() const { return mUpdatesEnabled; }
745 
751  int numberExportLayers() const;
752 
759  QPolygonF visibleExtentPolygon() const;
760 
761  //overriden to show "Map 1" type names
762  virtual QString displayName() const;
763 
765  QPolygonF transformedMapPolygon() const;
766 
768  QPointF mapToItemCoords( const QPointF& mapCoords ) const;
769 
770  Q_DECL_DEPRECATED void connectMapOverviewSignals();
771 
774  void requestedExtent( QgsRectangle& extent ) const;
775 
776  signals:
777  void extentChanged();
778 
780  void mapRotationChanged( double newRotation );
781 
783  void preparedForAtlas();
784 
785  public slots:
786 
788  void updateCachedImage();
790  void renderModeUpdateCachedImage();
791 
793  void updateBoundingRect();
794 
797 
799 
800  private:
801 
803  int mId;
804 
805  QgsComposerMapGridStack* mGridStack;
806 
807  QgsComposerMapOverviewStack* mOverviewStack;
808 
809  // Map region in map units realy used for rendering
810  // It can be the same as mUserExtent, but it can be bigger in on dimension if mCalculate==Scale,
811  // so that full rectangle in paper is used.
812  QgsRectangle mExtent;
813 
814  // Current temporary map region in map units. This is overwritten when atlas feature changes. It's also
815  // used when the user changes the map extent and an atlas preview is enabled. This allows the user
816  // to manually tweak each atlas preview page without affecting the actual original map extent.
817  QgsRectangle mAtlasFeatureExtent;
818 
819  // Cache used in composer preview
820  QImage mCacheImage;
821 
822  // Is cache up to date
823  bool mCacheUpdated;
824 
826  PreviewMode mPreviewMode;
827 
829  int mNumCachedLayers;
830 
832  bool mDrawing;
833 
835  double mXOffset;
837  double mYOffset;
838 
840  double mMapRotation;
843  double mEvaluatedMapRotation;
844 
846  bool mKeepLayerSet;
847 
849  QStringList mLayerSet;
850 
852  bool mUpdatesEnabled;
853 
855  void connectUpdateSlot();
856 
858  void syncLayerSet();
859 
861  const QgsComposerMapGrid* constFirstMapGrid() const;
862 
864  const QgsComposerMapOverview* constFirstMapOverview() const;
865 
867  QRectF mCurrentRectangle;
868  QGraphicsView* mMapCanvas;
870  bool mDrawCanvasItems;
871 
874  void adjustExtentToItemShape( double itemWidth, double itemHeight, QgsRectangle& extent ) const;
875 
877  bool mAtlasDriven;
879  AtlasScalingMode mAtlasScalingMode;
881  double mAtlasMargin;
882 
883  void init();
884 
886  void updateToolTip();
887 
889  QStringList layersToRender() const;
890 
892  QgsRectangle transformedExtent() const;
893 
895  void mapPolygon( const QgsRectangle& extent, QPolygonF& poly ) const;
896 
900  void transformShift( double& xShift, double& yShift ) const;
901 
902  void drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
903  void drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
904  QPointF composerMapPosForItem( const QGraphicsItem* item ) const;
905 
906  enum PartType
907  {
908  Background,
909  Layer,
910  Grid,
911  OverviewMapExtent,
912  Frame,
913  SelectionBoxes
914  };
915 
917  bool shouldDrawPart( PartType part ) const;
918 
922  void refreshMapExtents();
923 
924  friend class QgsComposerMapOverview; //to access mXOffset, mYOffset
925 };
927 
928 #endif
929 
AtlasScalingMode
Scaling modes used for the serial rendering (atlas)
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
A rectangle specified with double values.
Definition: qgsrectangle.h:35
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const
Stores item state in DOM element.
bool updatesEnabled() const
Returns whether updates to the composer map are enabled.
Q_DECL_DEPRECATED void toggleAtlasPreview()
Called when atlas preview is toggled, to force map item to update its extent and redraw.
void overviewExtentChanged()
QgsComposerMapOverviewStack * overviews()
Returns the map item's overview stack, which is used to control how overviews are drawn over the map'...
virtual void setRotation(double r)
Sets the item rotation.
A collection of grids which is drawn above the map content in a QgsComposerMap.
QStringList layerSet() const
Getter for stored layer set that is used if mKeepLayerSet is true.
A item that forms part of a map composition.
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:435
Border
Enum for different frame borders.
void setMapCanvas(QGraphicsView *canvas)
Sets canvas pointer (necessary to query and draw map canvas items)
DataDefinedProperty
Data defined properties for different item types.
A non GUI class for rendering a map layer set onto a QPainter.
bool isDrawing() const
True if a draw is already in progress.
The QgsMapSettings class contains configuration for rendering of the map.
void setAtlasMargin(double margin)
Sets the margin size (percentage) used when the map is in atlas mode.
virtual int type() const
return correct graphics item type.
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
virtual void moveContent(double dx, double dy)
Move Content of item.
void setAtlasScalingMode(AtlasScalingMode mode)
Sets the current atlas scaling mode.
An individual overview which is drawn above the map content in a QgsComposerMap, and shows the extent...
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...
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses.
bool drawCanvasItems() const
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
virtual int numberExportLayers() const
Get the number of layers that this item requires for exporting as layers.
An individual grid which is drawn above the map content in a QgsComposerMap.
PreviewMode
Preview style.
Graphics scene for map printing.
Object representing map window.
void setUpdatesEnabled(bool enabled)
Sets whether updates to the composer map are enabled.
PreviewMode previewMode() const
virtual QString displayName() const
Get item display name.
virtual void setFrameOutlineWidth(const double outlineWidth)
Sets frame outline width.
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:436
int id() const
Get identification number.
Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height, double rotation) const
Calculates corner point after rotation and scaling.
virtual Q_DECL_DEPRECATED void zoomContent(int delta, double x, double y)
Zoom content of item.
Q_DECL_DEPRECATED double rotation() const
Returns the rotation used for drawing the map within the composer item.
QgsRectangle extent() const
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
void setLayerSet(const QStringList &layerSet)
Setter for stored layer set that is used if mKeepLayerSet is true.
QgsComposerMapGridStack * grids()
Returns the map item's grid stack, which is used to control how grids are drawn over the map's conten...
AtlasScalingMode atlasScalingMode() const
Returns the current atlas scaling mode.
void setDrawCanvasItems(bool b)
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 setKeepLayerSet(bool enabled)
Setter for flag that determines if the stored layer set should be used or the current layer set of th...
bool atlasDriven() const
Returns whether the map extent is set to follow the current atlas feature.
bool keepLayerSet() const
Getter for flag that determines if the stored layer set should be used or the current layer set of th...
Represents a vector layer which manages a vector based data sets.
double size
Definition: qgssvgcache.cpp:77
Q_DECL_DEPRECATED void sizeChangedByRotation(double &width, double &height, double rotation)
Calculates width / height of the bounding box of a rotated rectangle.
A collection of overviews which are drawn above the map content in a QgsComposerMap.