QGIS API Documentation  2.6.0-Brighton
 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 
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 
240  bool keepLayerSet() const {return mKeepLayerSet;}
243  void setKeepLayerSet( bool enabled ) {mKeepLayerSet = enabled;}
244 
247  QStringList layerSet() const {return mLayerSet;}
250  void setLayerSet( const QStringList& layerSet ) {mLayerSet = layerSet;}
252  void storeCurrentLayerSet();
253 
254  // Set cache outdated
255  void setCacheUpdated( bool u = false );
256 
257  QgsRectangle extent() const {return mExtent;}
258 
260  Q_DECL_DEPRECATED const QgsMapRenderer* mapRenderer() const;
261 
263  void setOffset( double xOffset, double yOffset );
264 
266  bool containsWMSLayer() const;
267 
269  bool containsAdvancedEffects() const;
270 
275  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
276 
281  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
282 
287  Q_DECL_DEPRECATED void setGridEnabled( bool enabled );
288 
292  Q_DECL_DEPRECATED bool gridEnabled() const;
293 
298  Q_DECL_DEPRECATED void setGridStyle( GridStyle style );
299 
303  Q_DECL_DEPRECATED GridStyle gridStyle() const;
304 
309  Q_DECL_DEPRECATED void setGridIntervalX( double interval );
310 
314  Q_DECL_DEPRECATED double gridIntervalX() const;
315 
320  Q_DECL_DEPRECATED void setGridIntervalY( double interval );
321 
325  Q_DECL_DEPRECATED double gridIntervalY() const;
326 
331  Q_DECL_DEPRECATED void setGridOffsetX( double offset );
332 
336  Q_DECL_DEPRECATED double gridOffsetX() const;
337 
342  Q_DECL_DEPRECATED void setGridOffsetY( double offset );
343 
347  Q_DECL_DEPRECATED double gridOffsetY() const;
348 
353  Q_DECL_DEPRECATED void setGridPen( const QPen& p );
354 
358  Q_DECL_DEPRECATED QPen gridPen() const;
359 
364  Q_DECL_DEPRECATED void setGridPenWidth( double w );
365 
370  Q_DECL_DEPRECATED void setGridPenColor( const QColor& c );
371 
376  Q_DECL_DEPRECATED void setGridAnnotationFont( const QFont& f );
377 
381  Q_DECL_DEPRECATED QFont gridAnnotationFont() const;
382 
386  Q_DECL_DEPRECATED void setAnnotationFontColor( const QColor& c );
387 
391  Q_DECL_DEPRECATED QColor annotationFontColor() const;
392 
397  Q_DECL_DEPRECATED void setGridAnnotationPrecision( int p );
398 
402  Q_DECL_DEPRECATED int gridAnnotationPrecision() const;
403 
408  Q_DECL_DEPRECATED void setShowGridAnnotation( bool show );
409 
413  Q_DECL_DEPRECATED bool showGridAnnotation() const;
414 
418  Q_DECL_DEPRECATED void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border );
419 
423  Q_DECL_DEPRECATED GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;
424 
429  Q_DECL_DEPRECATED void setAnnotationFrameDistance( double d );
430 
434  Q_DECL_DEPRECATED double annotationFrameDistance() const;
435 
439  Q_DECL_DEPRECATED void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border );
440 
444  Q_DECL_DEPRECATED GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;
445 
449  Q_DECL_DEPRECATED void setGridAnnotationFormat( GridAnnotationFormat f );
450 
454  Q_DECL_DEPRECATED GridAnnotationFormat gridAnnotationFormat() const;
455 
459  Q_DECL_DEPRECATED void setGridFrameStyle( GridFrameStyle style );
460 
464  Q_DECL_DEPRECATED GridFrameStyle gridFrameStyle() const;
465 
469  Q_DECL_DEPRECATED void setGridFrameWidth( double w );
470 
474  Q_DECL_DEPRECATED double gridFrameWidth() const;
475 
480  Q_DECL_DEPRECATED void setGridFramePenSize( double w );
481 
485  Q_DECL_DEPRECATED double gridFramePenSize() const;
486 
491  Q_DECL_DEPRECATED void setGridFramePenColor( const QColor& c );
492 
497  Q_DECL_DEPRECATED QColor gridFramePenColor() const;
498 
503  Q_DECL_DEPRECATED void setGridFrameFillColor1( const QColor& c );
504 
509  Q_DECL_DEPRECATED QColor gridFrameFillColor1() const;
510 
515  Q_DECL_DEPRECATED void setGridFrameFillColor2( const QColor& c );
516 
521  Q_DECL_DEPRECATED QColor gridFrameFillColor2() const;
522 
527  Q_DECL_DEPRECATED void setCrossLength( double l );
528 
532  Q_DECL_DEPRECATED double crossLength();
533 
537  Q_DECL_DEPRECATED void setGridLineSymbol( QgsLineSymbolV2* symbol );
538 
542  Q_DECL_DEPRECATED QgsLineSymbolV2* gridLineSymbol();
543 
547  Q_DECL_DEPRECATED QPainter::CompositionMode gridBlendMode() const;
548 
552  Q_DECL_DEPRECATED void setGridBlendMode( QPainter::CompositionMode blendMode );
553 
560  QgsComposerMapGridStack* grids() { return mGridStack; }
561 
567  QgsComposerMapGrid* grid();
568 
575  QgsComposerMapOverviewStack* overviews() { return mOverviewStack; }
576 
582  QgsComposerMapOverview* overview();
583 
586  QRectF boundingRect() const;
587 
588  /* reimplement setFrameOutlineWidth, so that updateBoundingRect() is called after setting the frame width */
589  virtual void setFrameOutlineWidth( const double outlineWidth );
590 
595  Q_DECL_DEPRECATED void setRotation( double r );
596 
600  Q_DECL_DEPRECATED double rotation() const { return mMapRotation;}
601 
605  void setMapRotation( double r );
606 
613  double mapRotation( QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue ) const;
614 
615  void updateItem();
616 
618  void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; }
619 
620  void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; }
621  bool drawCanvasItems() const { return mDrawCanvasItems; }
622 
624  double mapUnitsToMM() const;
625 
629  Q_DECL_DEPRECATED void setOverviewFrameMap( int mapId );
630 
634  Q_DECL_DEPRECATED int overviewFrameMapId() const;
635 
639  Q_DECL_DEPRECATED void setOverviewFrameMapSymbol( QgsFillSymbolV2* symbol );
640 
644  Q_DECL_DEPRECATED QgsFillSymbolV2* overviewFrameMapSymbol();
645 
649  Q_DECL_DEPRECATED QPainter::CompositionMode overviewBlendMode() const;
650 
654  Q_DECL_DEPRECATED void setOverviewBlendMode( QPainter::CompositionMode blendMode );
655 
659  Q_DECL_DEPRECATED bool overviewInverted() const;
660 
664  Q_DECL_DEPRECATED void setOverviewInverted( bool inverted );
665 
669  Q_DECL_DEPRECATED bool overviewCentered() const;
670 
674  Q_DECL_DEPRECATED void setOverviewCentered( bool centered );
675 
678  void assignFreeId();
679 
684  Q_DECL_DEPRECATED bool imageSizeConsideringRotation( double& width, double& height ) const;
689  Q_DECL_DEPRECATED bool cornerPointOnRotatedAndScaledRect( double& x, double& y, double width, double height ) const;
694  Q_DECL_DEPRECATED void sizeChangedByRotation( double& width, double& height );
695 
701  bool atlasDriven() const { return mAtlasDriven; }
702 
708  void setAtlasDriven( bool enabled );
709 
713  Q_DECL_DEPRECATED bool atlasFixedScale() const;
714 
718  Q_DECL_DEPRECATED void setAtlasFixedScale( bool fixed );
719 
728  AtlasScalingMode atlasScalingMode() const { return mAtlasScalingMode; }
729 
738  void setAtlasScalingMode( AtlasScalingMode mode ) { mAtlasScalingMode = mode; }
739 
749  double atlasMargin( const QgsComposerObject::PropertyValueType valueType = QgsComposerObject::EvaluatedValue );
750 
757  void setAtlasMargin( double margin ) { mAtlasMargin = margin; }
758 
760  void setUpdatesEnabled( bool enabled ) { mUpdatesEnabled = enabled; }
761 
763  bool updatesEnabled() const { return mUpdatesEnabled; }
764 
770  int numberExportLayers() const;
771 
778  QPolygonF visibleExtentPolygon() const;
779 
780  //overriden to show "Map 1" type names
781  virtual QString displayName() const;
782 
784  QPolygonF transformedMapPolygon() const;
785 
787  QPointF mapToItemCoords( const QPointF& mapCoords ) const;
788 
789  Q_DECL_DEPRECATED void connectMapOverviewSignals();
790 
793  void requestedExtent( QgsRectangle& extent ) const;
794 
795  signals:
796  void extentChanged();
797 
799  void mapRotationChanged( double newRotation );
800 
802  void preparedForAtlas();
803 
804  public slots:
805 
807  void updateCachedImage();
809  void renderModeUpdateCachedImage();
810 
813  void updateBoundingRect();
814 
817 
819 
820  private:
821 
823  int mId;
824 
825  QgsComposerMapGridStack* mGridStack;
826 
827  QgsComposerMapOverviewStack* mOverviewStack;
828 
829  // Map region in map units realy used for rendering
830  // It can be the same as mUserExtent, but it can be bigger in on dimension if mCalculate==Scale,
831  // so that full rectangle in paper is used.
832  QgsRectangle mExtent;
833 
834  // Current temporary map region in map units. This is overwritten when atlas feature changes. It's also
835  // used when the user changes the map extent and an atlas preview is enabled. This allows the user
836  // to manually tweak each atlas preview page without affecting the actual original map extent.
837  QgsRectangle mAtlasFeatureExtent;
838 
839  // Cache used in composer preview
840  QImage mCacheImage;
841 
842  // Is cache up to date
843  bool mCacheUpdated;
844 
846  PreviewMode mPreviewMode;
847 
849  int mNumCachedLayers;
850 
852  bool mDrawing;
853 
855  double mXOffset;
857  double mYOffset;
858 
860  double mMapRotation;
863  double mEvaluatedMapRotation;
864 
866  bool mKeepLayerSet;
867 
869  QStringList mLayerSet;
870 
872  bool mUpdatesEnabled;
873 
875  void connectUpdateSlot();
876 
878  void syncLayerSet();
879 
881  const QgsComposerMapGrid* constFirstMapGrid() const;
882 
884  const QgsComposerMapOverview* constFirstMapOverview() const;
885 
887  QRectF mCurrentRectangle;
888  QGraphicsView* mMapCanvas;
890  bool mDrawCanvasItems;
891 
894  void adjustExtentToItemShape( double itemWidth, double itemHeight, QgsRectangle& extent ) const;
895 
897  bool mAtlasDriven;
899  AtlasScalingMode mAtlasScalingMode;
901  double mAtlasMargin;
902 
903  void init();
904 
906  void updateToolTip();
907 
909  QStringList layersToRender() const;
910 
912  QgsRectangle transformedExtent() const;
913 
915  void mapPolygon( const QgsRectangle& extent, QPolygonF& poly ) const;
916 
920  void transformShift( double& xShift, double& yShift ) const;
921 
922  void drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
923  void drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
924  QPointF composerMapPosForItem( const QGraphicsItem* item ) const;
925 
926  enum PartType
927  {
928  Background,
929  Layer,
930  Grid,
931  OverviewMapExtent,
932  Frame,
933  SelectionBoxes
934  };
935 
937  bool shouldDrawPart( PartType part ) const;
938 
942  void refreshMapExtents();
943 
944  friend class QgsComposerMapOverview; //to access mXOffset, mYOffset
945 };
947 
948 #endif
949