QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
46 class CORE_EXPORT QgsComposerMap : public QgsComposerItem
47 {
48  Q_OBJECT
49 
50  public:
52  QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height );
54  QgsComposerMap( QgsComposition *composition );
55  virtual ~QgsComposerMap();
56 
58  virtual int type() const { return ComposerMap; }
59 
62  {
63  Cache = 0, // Use raster cache
64  Render, // Render the map
65  Rectangle // Display only rectangle
66  };
67 
68  //grid enums are moved to QgsComposerMapGrid
69  //TODO - remove for QGIS 3.0
70  enum GridStyle
71  {
72  Solid = 0, //solid lines
73  Cross, //only draw line crossings
75  FrameAnnotationsOnly
76  };
77 
79  {
80  InsideMapFrame = 0,
82  Disabled
83  };
84 
86  {
87  Horizontal = 0,
90  BoundaryDirection
91  };
92 
94  {
95  Decimal = 0,
102  DegreeMinuteSecondPadded
103  };
104 
106  {
107  NoGridFrame = 0,
108  Zebra, // black/white pattern
112  LineBorder
113  };
114 
116  enum Border
117  {
121  Top
122  };
123 
127  {
128  Fixed, /*< The current scale of the map is used for each feature of the atlas */
129  Predefined, /*< A scale is chosen from the predefined scales. The smallest scale from
130  the list of scales where the atlas feature is fully visible is chosen.
131  @see QgsAtlasComposition::setPredefinedScales.
132  @note This mode is only valid for polygon or line atlas coverage layers
133  */
134  Auto /*< The extent is adjusted so that each feature is fully visible.
135  A margin is applied around the center @see setAtlasMargin
136  @note This mode is only valid for polygon or line atlas coverage layers*/
137  };
138 
146  void draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi, double* forceWidthScale = 0 );
147 
149  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
150 
152  void cache();
153 
156  QgsMapSettings mapSettings( const QgsRectangle& extent, const QSizeF& size, int dpi ) const;
157 
159  int id() const {return mId;}
160 
162  bool isDrawing() const {return mDrawing;}
163 
165  void resize( double dx, double dy );
166 
170  void moveContent( double dx, double dy );
171 
176  void zoomContent( int delta, double x, double y );
177 
179  void setSceneRect( const QRectF& rectangle );
180 
182  double scale() const;
183 
185  void setNewScale( double scaleDenominator, bool forceUpdate = true );
186 
193  void setNewExtent( const QgsRectangle& extent );
194 
203  void zoomToExtent( const QgsRectangle& extent );
204 
208  void setNewAtlasFeatureExtent( const QgsRectangle& extent );
209 
211  void toggleAtlasPreview();
212 
219  QgsRectangle* currentMapExtent();
220  const QgsRectangle* currentMapExtent() const;
221 
222  PreviewMode previewMode() const {return mPreviewMode;}
223  void setPreviewMode( PreviewMode m );
224 
227  bool keepLayerSet() const {return mKeepLayerSet;}
230  void setKeepLayerSet( bool enabled ) {mKeepLayerSet = enabled;}
231 
234  QStringList layerSet() const {return mLayerSet;}
237  void setLayerSet( const QStringList& layerSet ) {mLayerSet = layerSet;}
239  void storeCurrentLayerSet();
240 
241  // Set cache outdated
242  void setCacheUpdated( bool u = false );
243 
244  QgsRectangle extent() const {return mExtent;}
245 
247  Q_DECL_DEPRECATED const QgsMapRenderer* mapRenderer() const;
248 
250  void setOffset( double xOffset, double yOffset );
251 
253  bool containsWMSLayer() const;
254 
256  bool containsAdvancedEffects() const;
257 
262  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
263 
268  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
269 
274  Q_DECL_DEPRECATED void setGridEnabled( bool enabled );
275 
279  Q_DECL_DEPRECATED bool gridEnabled() const;
280 
285  Q_DECL_DEPRECATED void setGridStyle( GridStyle style );
286 
290  Q_DECL_DEPRECATED GridStyle gridStyle() const;
291 
296  Q_DECL_DEPRECATED void setGridIntervalX( double interval );
297 
301  Q_DECL_DEPRECATED double gridIntervalX() const;
302 
307  Q_DECL_DEPRECATED void setGridIntervalY( double interval );
308 
312  Q_DECL_DEPRECATED double gridIntervalY() const;
313 
318  Q_DECL_DEPRECATED void setGridOffsetX( double offset );
319 
323  Q_DECL_DEPRECATED double gridOffsetX() const;
324 
329  Q_DECL_DEPRECATED void setGridOffsetY( double offset );
330 
334  Q_DECL_DEPRECATED double gridOffsetY() const;
335 
340  Q_DECL_DEPRECATED void setGridPen( const QPen& p );
341 
345  Q_DECL_DEPRECATED QPen gridPen() const;
346 
351  Q_DECL_DEPRECATED void setGridPenWidth( double w );
352 
357  Q_DECL_DEPRECATED void setGridPenColor( const QColor& c );
358 
363  Q_DECL_DEPRECATED void setGridAnnotationFont( const QFont& f );
364 
368  Q_DECL_DEPRECATED QFont gridAnnotationFont() const;
369 
374  Q_DECL_DEPRECATED void setAnnotationFontColor( const QColor& c );
375 
380  Q_DECL_DEPRECATED QColor annotationFontColor() const;
381 
386  Q_DECL_DEPRECATED void setGridAnnotationPrecision( int p );
387 
391  Q_DECL_DEPRECATED int gridAnnotationPrecision() const;
392 
397  Q_DECL_DEPRECATED void setShowGridAnnotation( bool show );
398 
402  Q_DECL_DEPRECATED bool showGridAnnotation() const;
403 
407  Q_DECL_DEPRECATED void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border );
408 
412  Q_DECL_DEPRECATED GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;
413 
418  Q_DECL_DEPRECATED void setAnnotationFrameDistance( double d );
419 
423  Q_DECL_DEPRECATED double annotationFrameDistance() const;
424 
428  Q_DECL_DEPRECATED void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border );
429 
433  Q_DECL_DEPRECATED GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;
434 
438  Q_DECL_DEPRECATED void setGridAnnotationFormat( GridAnnotationFormat f );
439 
443  Q_DECL_DEPRECATED GridAnnotationFormat gridAnnotationFormat() const;
444 
449  Q_DECL_DEPRECATED void setGridFrameStyle( GridFrameStyle style );
450 
454  Q_DECL_DEPRECATED GridFrameStyle gridFrameStyle() const;
455 
460  Q_DECL_DEPRECATED void setGridFrameWidth( double w );
461 
465  Q_DECL_DEPRECATED double gridFrameWidth() const;
466 
471  Q_DECL_DEPRECATED void setGridFramePenSize( double w );
472 
476  Q_DECL_DEPRECATED double gridFramePenSize() const;
477 
482  Q_DECL_DEPRECATED void setGridFramePenColor( const QColor& c );
483 
488  Q_DECL_DEPRECATED QColor gridFramePenColor() const;
489 
494  Q_DECL_DEPRECATED void setGridFrameFillColor1( const QColor& c );
495 
500  Q_DECL_DEPRECATED QColor gridFrameFillColor1() const;
501 
506  Q_DECL_DEPRECATED void setGridFrameFillColor2( const QColor& c );
507 
512  Q_DECL_DEPRECATED QColor gridFrameFillColor2() const;
513 
518  Q_DECL_DEPRECATED void setCrossLength( double l );
519 
523  Q_DECL_DEPRECATED double crossLength();
524 
528  Q_DECL_DEPRECATED void setGridLineSymbol( QgsLineSymbolV2* symbol );
529 
533  Q_DECL_DEPRECATED QgsLineSymbolV2* gridLineSymbol();
534 
538  Q_DECL_DEPRECATED QPainter::CompositionMode gridBlendMode() const;
539 
543  Q_DECL_DEPRECATED void setGridBlendMode( QPainter::CompositionMode blendMode );
544 
551  QgsComposerMapGridStack* grids() { return mGridStack; }
552 
558  QgsComposerMapGrid* grid();
559 
566  QgsComposerMapOverviewStack* overviews() { return mOverviewStack; }
567 
573  QgsComposerMapOverview* overview();
574 
577  QRectF boundingRect() const;
578 
579  /* reimplement setFrameOutlineWidth, so that updateBoundingRect() is called after setting the frame width */
580  virtual void setFrameOutlineWidth( const double outlineWidth );
581 
586  Q_DECL_DEPRECATED void setRotation( double r );
587 
591  Q_DECL_DEPRECATED double rotation() const { return mMapRotation;}
592 
596  void setMapRotation( double r );
597 
604  double mapRotation( QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;
605 
606  void updateItem();
607 
609  void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; }
610 
611  void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; }
612  bool drawCanvasItems() const { return mDrawCanvasItems; }
613 
615  double mapUnitsToMM() const;
616 
621  Q_DECL_DEPRECATED void setOverviewFrameMap( int mapId );
622 
627  Q_DECL_DEPRECATED int overviewFrameMapId() const;
628 
632  Q_DECL_DEPRECATED void setOverviewFrameMapSymbol( QgsFillSymbolV2* symbol );
633 
637  Q_DECL_DEPRECATED QgsFillSymbolV2* overviewFrameMapSymbol();
638 
642  Q_DECL_DEPRECATED QPainter::CompositionMode overviewBlendMode() const;
643 
647  Q_DECL_DEPRECATED void setOverviewBlendMode( QPainter::CompositionMode blendMode );
648 
652  Q_DECL_DEPRECATED bool overviewInverted() const;
653 
657  Q_DECL_DEPRECATED void setOverviewInverted( bool inverted );
658 
662  Q_DECL_DEPRECATED bool overviewCentered() const;
663 
667  Q_DECL_DEPRECATED void setOverviewCentered( bool centered );
668 
671  void assignFreeId();
672 
677  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
682  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
687  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
688 
694  bool atlasDriven() const { return mAtlasDriven; }
695 
701  void setAtlasDriven( bool enabled );
702 
706  Q_DECL_DEPRECATED bool atlasFixedScale() const;
707 
711  Q_DECL_DEPRECATED void setAtlasFixedScale( bool fixed );
712 
721  AtlasScalingMode atlasScalingMode() const { return mAtlasScalingMode; }
722 
731  void setAtlasScalingMode( AtlasScalingMode mode ) { mAtlasScalingMode = mode; }
732 
742  double atlasMargin( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue );
743 
750  void setAtlasMargin( double margin ) { mAtlasMargin = margin; }
751 
753  void setUpdatesEnabled( bool enabled ) { mUpdatesEnabled = enabled; }
754 
756  bool updatesEnabled() const { return mUpdatesEnabled; }
757 
763  int numberExportLayers() const;
764 
771  QPolygonF visibleExtentPolygon() const;
772 
773  //overriden to show "Map 1" type names
774  virtual QString displayName() const;
775 
777  QPolygonF transformedMapPolygon() const;
778 
780  QPointF mapToItemCoords( const QPointF& mapCoords ) const;
781 
782  Q_DECL_DEPRECATED void connectMapOverviewSignals();
783 
786  void requestedExtent( QgsRectangle& extent ) const;
787 
788  signals:
789  void extentChanged();
790 
792  void mapRotationChanged( double newRotation );
793 
795  void preparedForAtlas();
796 
797  public slots:
798 
800  void updateCachedImage( );
802  void renderModeUpdateCachedImage();
803 
806  void updateBoundingRect();
807 
810 
812 
813  private:
814 
816  int mId;
817 
818  QgsComposerMapGridStack* mGridStack;
819 
820  QgsComposerMapOverviewStack* mOverviewStack;
821 
822  // Map region in map units realy used for rendering
823  // It can be the same as mUserExtent, but it can be bigger in on dimension if mCalculate==Scale,
824  // so that full rectangle in paper is used.
825  QgsRectangle mExtent;
826 
827  // Current temporary map region in map units. This is overwritten when atlas feature changes. It's also
828  // used when the user changes the map extent and an atlas preview is enabled. This allows the user
829  // to manually tweak each atlas preview page without affecting the actual original map extent.
830  QgsRectangle mAtlasFeatureExtent;
831 
832  // Cache used in composer preview
833  QImage mCacheImage;
834 
835  // Is cache up to date
836  bool mCacheUpdated;
837 
839  PreviewMode mPreviewMode;
840 
842  int mNumCachedLayers;
843 
845  bool mDrawing;
846 
848  double mXOffset;
850  double mYOffset;
851 
853  double mMapRotation;
856  double mEvaluatedMapRotation;
857 
859  bool mKeepLayerSet;
860 
862  QStringList mLayerSet;
863 
865  bool mUpdatesEnabled;
866 
868  void connectUpdateSlot();
869 
871  void syncLayerSet();
872 
874  const QgsComposerMapGrid* constFirstMapGrid() const;
875 
877  const QgsComposerMapOverview* constFirstMapOverview() const;
878 
880  QRectF mCurrentRectangle;
881  QGraphicsView* mMapCanvas;
883  bool mDrawCanvasItems;
884 
887  void adjustExtentToItemShape( double itemWidth, double itemHeight, QgsRectangle& extent ) const;
888 
890  bool mAtlasDriven;
892  AtlasScalingMode mAtlasScalingMode;
894  double mAtlasMargin;
895 
896  void init();
897 
899  QStringList layersToRender() const;
900 
902  QgsRectangle transformedExtent() const;
903 
905  void mapPolygon( const QgsRectangle& extent, QPolygonF& poly ) const;
906 
910  void transformShift( double& xShift, double& yShift ) const;
911 
912  void drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
913  void drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
914  QPointF composerMapPosForItem( const QGraphicsItem* item ) const;
915 
916  enum PartType
917  {
918  Background,
919  Layer,
920  Grid,
921  OverviewMapExtent,
922  Frame,
923  SelectionBoxes
924  };
925 
927  bool shouldDrawPart( PartType part ) const;
928 
932  void refreshMapExtents();
933 
934  friend class QgsComposerMapOverview; //to access mXOffset, mYOffset
935 };
936 
937 #endif
938 
GridStyle
Definition: qgscomposermap.h:70
AtlasScalingMode
Scaling modes used for the serial rendering (atlas)
Definition: qgscomposermap.h:126
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...
Definition: qgscomposeritem.cpp:1087
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.
Definition: qgscomposerobject.cpp:61
bool updatesEnabled() const
Returns whether updates to the composer map are enabled.
Definition: qgscomposermap.h:756
void overviewExtentChanged()
Definition: qgscomposermap.h:809
QgsComposerMapOverviewStack * overviews()
Returns the map item's overview stack, which is used to control how overviews are drawn over the map'...
Definition: qgscomposermap.h:566
Definition: qgscomposeritem.h:53
virtual void setRotation(double r)
Sets the item rotation.
Definition: qgscomposeritem.cpp:1012
Definition: qgscomposermap.h:73
A collection of grids which is drawn above the map content in a QgsComposerMap.
Definition: qgscomposermapgrid.h:45
Definition: qgscomposermap.h:108
QStringList layerSet() const
Getter for stored layer set that is used if mKeepLayerSet is true.
Definition: qgscomposermap.h:234
Definition: qgscomposermap.h:120
A item that forms part of a map composition.
Definition: qgscomposeritem.h:38
GridAnnotationFormat
Definition: qgscomposermap.h:93
Border
Enum for different frame borders.
Definition: qgscomposermap.h:116
Definition: qgscomposermap.h:99
Definition: qgscomposermap.h:118
void setMapCanvas(QGraphicsView *canvas)
Sets canvas pointer (necessary to query and draw map canvas items)
Definition: qgscomposermap.h:609
Definition: qgscomposermap.h:128
A non GUI class for rendering a map layer set onto a QPainter.
Definition: qgsmaprenderer.h:133
Definition: qgssymbolv2.h:277
DataDefinedProperty
Data defined properties for different item types.
Definition: qgscomposerobject.h:40
bool isDrawing() const
True if a draw is already in progress.
Definition: qgscomposermap.h:162
The QgsMapSettings class contains configuration for rendering of the map.
Definition: qgsmapsettings.h:52
void setAtlasMargin(double margin)
Sets the margin size (percentage) used when the map is in atlas mode.
Definition: qgscomposermap.h:750
virtual int type() const
return correct graphics item type.
Definition: qgscomposermap.h:58
Definition: qgscomposermap.h:101
Definition: qgscomposermap.h:88
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
virtual void moveContent(double dx, double dy)
Move Content of item.
Definition: qgscomposeritem.h:139
void setAtlasScalingMode(AtlasScalingMode mode)
Sets the current atlas scaling mode.
Definition: qgscomposermap.h:731
Definition: qgscomposermap.h:98
An individual overview which is drawn above the map content in a QgsComposerMap, and shows the extent...
Definition: qgscomposermapoverview.h:135
Definition: qgscomposermap.h:110
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...
Definition: qgscomposeritem.cpp:1308
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses.
Definition: qgscomposeritem.h:460
Definition: qgssymbolv2.h:256
bool drawCanvasItems() const
Definition: qgscomposermap.h:612
Definition: qgscomposermap.h:96
virtual int numberExportLayers() const
Get the number of layers that this item requires for exporting as layers.
Definition: qgscomposeritem.h:539
An individual grid which is drawn above the map content in a QgsComposerMap.
Definition: qgscomposermapgrid.h:151
PropertyValueType
Specifies whether the value returned by a function should be the original, user set value...
Definition: qgscomposerobject.h:79
PreviewMode
Preview style.
Definition: qgscomposermap.h:61
GridAnnotationPosition
Definition: qgscomposermap.h:78
Graphics scene for map printing.
Definition: qgscomposition.h:72
Object representing map window.
Definition: qgscomposermap.h:46
Definition: qgscomposermap.h:89
Definition: qgscomposerobject.h:81
void setUpdatesEnabled(bool enabled)
Sets whether updates to the composer map are enabled.
Definition: qgscomposermap.h:753
PreviewMode previewMode() const
Definition: qgscomposermap.h:222
Definition: qgscomposermap.h:109
GridAnnotationDirection
Definition: qgscomposermap.h:85
virtual QString displayName() const
Get item display name.
Definition: qgscomposeritem.cpp:1370
Definition: qgscomposermap.h:111
virtual void zoomContent(int delta, double x, double y)
Zoom content of item.
Definition: qgscomposeritem.h:145
GridFrameStyle
Definition: qgscomposermap.h:105
virtual void setFrameOutlineWidth(const double outlineWidth)
Sets frame outline width.
Definition: qgscomposeritem.cpp:440
int id() const
Get identification number.
Definition: qgscomposermap.h:159
Definition: qgscomposermap.h:119
Definition: qgscomposermap.h:64
Definition: qgscomposermap.h:100
Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect(double &x, double &y, double width, double height, double rotation) const
Calculates corner point after rotation and scaling.
Definition: qgscomposeritem.cpp:1166
Q_DECL_DEPRECATED double rotation() const
Returns the rotation used for drawing the map within the composer item.
Definition: qgscomposermap.h:591
QgsRectangle extent() const
Definition: qgscomposermap.h:244
Definition: qgscomposermap.h:129
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)
Sets item state from DOM element.
Definition: qgscomposerobject.cpp:74
void setLayerSet(const QStringList &layerSet)
Setter for stored layer set that is used if mKeepLayerSet is true.
Definition: qgscomposermap.h:237
QgsComposerMapGridStack * grids()
Returns the map item's grid stack, which is used to control how grids are drawn over the map's conten...
Definition: qgscomposermap.h:551
Definition: qgscomposermap.h:97
AtlasScalingMode atlasScalingMode() const
Returns the current atlas scaling mode.
Definition: qgscomposermap.h:721
void setDrawCanvasItems(bool b)
Definition: qgscomposermap.h:611
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...
Definition: qgscomposeritem.cpp:686
Definition: qgscomposermap.h:81
void setKeepLayerSet(bool enabled)
Setter for flag that determines if the stored layer set should be used or the current layer set of th...
Definition: qgscomposermap.h:230
bool atlasDriven() const
Returns whether the map extent is set to follow the current atlas feature.
Definition: qgscomposermap.h:694
bool keepLayerSet() const
Getter for flag that determines if the stored layer set should be used or the current layer set of th...
Definition: qgscomposermap.h:227
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:470
double size
Definition: qgssvgcache.cpp:77
Definition: qgscomposermap.h:74
Q_DECL_DEPRECATED void sizeChangedByRotation(double &width, double &height, double rotation)
Calculates width / height of the bounding box of a rotated rectangle.
Definition: qgscomposeritem.cpp:1211
Definition: qgscomposerobject.h:43
A collection of overviews which are drawn above the map content in a QgsComposerMap.
Definition: qgscomposermapoverview.h:39