QGIS API Documentation  2.0.1-Dufour
 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;
27 class QgsMapRenderer;
28 class QgsMapToPixel;
29 class QDomNode;
30 class QDomDocument;
31 class QGraphicsView;
32 class QPainter;
33 class QgsFillSymbolV2;
34 class QgsLineSymbolV2;
35 class QgsVectorLayer;
36 
41 // NOTE: QgsComposerMapBase must be first, otherwise does not compile
42 class CORE_EXPORT QgsComposerMap : public QgsComposerItem
43 {
44  Q_OBJECT
45 
46  public:
48  QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height );
50  QgsComposerMap( QgsComposition *composition );
51  virtual ~QgsComposerMap();
52 
54  virtual int type() const { return ComposerMap; }
55 
58  {
59  Cache = 0, // Use raster cache
60  Render, // Render the map
61  Rectangle // Display only rectangle
62  };
63 
64  enum GridStyle
65  {
66  Solid = 0, //solid lines
67  Cross //only draw line crossings
68  };
69 
71  {
72  InsideMapFrame = 0,
74  Disabled
75  };
76 
78  {
79  Horizontal = 0,
82  BoundaryDirection
83  };
84 
86  {
87  Decimal = 0,
89  DegreeMinuteSecond
90  };
91 
93  {
94  NoGridFrame = 0,
95  Zebra //black / white pattern
96  };
97 
99  enum Border
100  {
104  Top
105  };
106 
114  void draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi, double* forceWidthScale = 0 );
115 
117  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
118 
120  void cache();
121 
123  int id() const {return mId;}
124 
126  bool isDrawing() const {return mDrawing;}
127 
129  void resize( double dx, double dy );
130 
134  void moveContent( double dx, double dy );
135 
140  void zoomContent( int delta, double x, double y );
141 
143  void setSceneRect( const QRectF& rectangle );
144 
146  double scale() const;
147 
149  void setNewScale( double scaleDenominator );
150 
152  void setNewExtent( const QgsRectangle& extent );
153 
154  PreviewMode previewMode() const {return mPreviewMode;}
155  void setPreviewMode( PreviewMode m );
156 
159  bool keepLayerSet() const {return mKeepLayerSet;}
162  void setKeepLayerSet( bool enabled ) {mKeepLayerSet = enabled;}
163 
166  QStringList layerSet() const {return mLayerSet;}
169  void setLayerSet( const QStringList& layerSet ) {mLayerSet = layerSet;}
171  void storeCurrentLayerSet();
172 
173  // Set cache outdated
174  void setCacheUpdated( bool u = false );
175 
176  QgsRectangle extent() const {return mExtent;}
177 
178  const QgsMapRenderer* mapRenderer() const {return mMapRenderer;}
179 
181  void setOffset( double xOffset, double yOffset );
182 
184  bool containsWMSLayer() const;
185 
187  bool containsAdvancedEffects() const;
188 
193  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
194 
199  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
200 
203  void setGridEnabled( bool enabled ) {mGridEnabled = enabled;}
204  bool gridEnabled() const { return mGridEnabled; }
205 
208  void setGridStyle( GridStyle style ) {mGridStyle = style;}
209  GridStyle gridStyle() const { return mGridStyle; }
210 
213  void setGridIntervalX( double interval ) { mGridIntervalX = interval;}
214  double gridIntervalX() const { return mGridIntervalX; }
215 
218  void setGridIntervalY( double interval ) { mGridIntervalY = interval;}
219  double gridIntervalY() const { return mGridIntervalY; }
220 
223  void setGridOffsetX( double offset ) { mGridOffsetX = offset; }
224  double gridOffsetX() const { return mGridOffsetX; }
225 
228  void setGridOffsetY( double offset ) { mGridOffsetY = offset; }
229  double gridOffsetY() const { return mGridOffsetY; }
230 
233  void setGridPen( const QPen& p );
234  QPen gridPen() const;
235 
238  void setGridPenWidth( double w );
239 
242  void setGridPenColor( const QColor& c );
243 
246  void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; }
247  QFont gridAnnotationFont() const { return mGridAnnotationFont; }
248 
251  void setAnnotationFontColor( const QColor& c ) {mGridAnnotationFontColor = c;}
254  QColor annotationFontColor() const {return mGridAnnotationFontColor;}
255 
258  void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;}
259  int gridAnnotationPrecision() const {return mGridAnnotationPrecision;}
260 
263  void setShowGridAnnotation( bool show ) {mShowGridAnnotation = show;}
264  bool showGridAnnotation() const {return mShowGridAnnotation;}
265 
266  void setGridAnnotationPosition( GridAnnotationPosition p, QgsComposerMap::Border border );
267  GridAnnotationPosition gridAnnotationPosition( QgsComposerMap::Border border ) const;
268 
271  void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;}
272  double annotationFrameDistance() const {return mAnnotationFrameDistance;}
273 
274  void setGridAnnotationDirection( GridAnnotationDirection d, QgsComposerMap::Border border );
275  GridAnnotationDirection gridAnnotationDirection( QgsComposerMap::Border border ) const;
276 
277  void setGridAnnotationFormat( GridAnnotationFormat f ) { mGridAnnotationFormat = f; }
278  GridAnnotationFormat gridAnnotationFormat() const { return mGridAnnotationFormat; }
279 
282  void setGridFrameStyle( GridFrameStyle style ) { mGridFrameStyle = style; }
283  GridFrameStyle gridFrameStyle() const { return mGridFrameStyle; }
284 
287  void setGridFrameWidth( double w ) { mGridFrameWidth = w; }
288  double gridFrameWidth() const { return mGridFrameWidth; }
289 
292  QRectF boundingRect() const;
295  void updateBoundingRect();
296 
299  void setCrossLength( double l ) {mCrossLength = l;}
300  double crossLength() {return mCrossLength;}
301 
302  void setMapRotation( double r );
303 
304  void updateItem();
305 
307  void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; }
308 
309  void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; }
310  bool drawCanvasItems() const { return mDrawCanvasItems; }
311 
313  double mapUnitsToMM() const;
314 
317  void setOverviewFrameMap( int mapId );
320  int overviewFrameMapId() const { return mOverviewFrameMapId; }
321 
322  void setOverviewFrameMapSymbol( QgsFillSymbolV2* symbol );
323  QgsFillSymbolV2* overviewFrameMapSymbol() { return mOverviewFrameMapSymbol; }
324 
326  QPainter::CompositionMode overviewBlendMode() const {return mOverviewBlendMode;}
328  void setOverviewBlendMode( QPainter::CompositionMode blendMode );
329 
331  bool overviewInverted() const {return mOverviewInverted;}
333  void setOverviewInverted( bool inverted );
334 
335  void setGridLineSymbol( QgsLineSymbolV2* symbol );
336  QgsLineSymbolV2* gridLineSymbol() { return mGridLineSymbol; }
337 
339  QPainter::CompositionMode gridBlendMode() const {return mGridBlendMode;}
341  void setGridBlendMode( QPainter::CompositionMode blendMode );
342 
345  void assignFreeId();
346 
347  signals:
348  void extentChanged();
349 
350  public slots:
351 
353  void updateCachedImage( );
355  void renderModeUpdateCachedImage();
356 
357  private:
358 
360  {
361  Longitude = 0,
362  Latitude
363  };
364 
365  // Pointer to map renderer of the QGIS main map. Note that QgsComposerMap uses a different map renderer,
366  //it just copies some properties from the main map renderer.
368 
370  int mId;
371 
372  // Map region in map units realy used for rendering
373  // It can be the same as mUserExtent, but it can be bigger in on dimension if mCalculate==Scale,
374  // so that full rectangle in paper is used.
376 
377  // Cache used in composer preview
378  QImage mCacheImage;
379 
380  // Is cache up to date
382 
385 
388 
390  bool mDrawing;
391 
393  double mXOffset;
395  double mYOffset;
396 
399 
401  QStringList mLayerSet;
402 
409  QPainter::CompositionMode mOverviewBlendMode;
411 
413  void connectUpdateSlot();
414 
416  void syncLayerSet();
417 
427  double mGridOffsetX;
429  double mGridOffsetY;
439  QPainter::CompositionMode mGridBlendMode;
440 
449 
452 
461 
463 
466 
470  double mCrossLength;
471  QGraphicsView* mMapCanvas;
474 
476  void drawGrid( QPainter* p );
477  void drawGridFrame( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines );
482  void drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines );
483  void drawCoordinateAnnotation( QPainter* p, const QPointF& pos, QString annotationString );
489  void drawAnnotation( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText );
490  QString gridAnnotationString( double value, AnnotationCoordinate coord ) const;
493  int xGridLines( QList< QPair< double, QLineF > >& lines ) const;
496  int yGridLines( QList< QPair< double, QLineF > >& lines ) const;
498  QgsRectangle transformedExtent() const;
500  QPolygonF transformedMapPolygon() const;
501  double maxExtension() const;
505  void mapPolygon( QPolygonF& poly ) const;
507  void requestedExtent( QgsRectangle& extent ) const;
511  void transformShift( double& xShift, double& yShift ) const;
513  QPointF mapToItemCoords( const QPointF& mapCoords ) const;
515  Border borderForLineCoord( const QPointF& p ) const;
516 
517  void drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
518  void drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
519  QPointF composerMapPosForItem( const QGraphicsItem* item ) const;
520  void sortGridLinesOnBorders( const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines, QMap< double, double >& leftFrameEntries,
521  QMap< double, double >& rightFrameEntries, QMap< double, double >& topFrameEntries, QMap< double, double >& bottomFrameEntries ) const;
522  void drawGridFrameBorder( QPainter* p, const QMap< double, double >& borderPos, Border border );
523  void drawGridLine( const QLineF& line, QPainter* p );
524  void drawOverviewMapExtent( QPainter* p );
525  void createDefaultOverviewFrameSymbol();
526  void createDefaultGridLineSymbol();
527  void initGridAnnotationFormatFromProject();
528 };
529 
530 #endif
void setGridFrameWidth(double w)
Set grid frame width.
int mOverviewFrameMapId
Id of map which displays its extent rectangle into this composer map (overview map functionality)...
double mGridFrameWidth
double mXOffset
Offset in x direction for showing map cache image.
bool mGridEnabled
True if coordinate grid has to be displayed.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
bool mDrawing
set to true if in state of drawing.
double mGridIntervalY
Grid line interval in y-direction (map units)
virtual bool readXML(const QDomElement &itemElem, const QDomDocument &doc)=0
sets state from Dom document
void setGridIntervalY(double interval)
Sets coordinate interval in y-direction for composergrid.
QgsLineSymbolV2 * gridLineSymbol()
void setGridAnnotationFormat(GridAnnotationFormat f)
double gridIntervalX() const
void setGridEnabled(bool enabled)
Enables a coordinate grid that is shown on top of this composermap.
QStringList mLayerSet
Stored layer list (used if layer live-link mKeepLayerSet is disabled)
QFont mGridAnnotationFont
Font for grid line annotation.
bool mDrawCanvasItems
True if annotation items, rubber band, etc.
QStringList layerSet() const
Getter for stored layer set that is used if mKeepLayerSet is true.
void setAnnotationFontColor(const QColor &c)
Sets font color for grid annotations.
bool showGridAnnotation() const
void setGridStyle(GridStyle style)
Sets coordinate grid style to solid or cross.
A item that forms part of a map composition.
Border
Enum for different frame borders.
QPainter::CompositionMode mOverviewBlendMode
Blend mode for overview.
QGraphicsView * mMapCanvas
void setMapCanvas(QGraphicsView *canvas)
Sets canvas pointer (necessary to query and draw map canvas items)
double annotationFrameDistance() const
A non GUI class for rendering a map layer set onto a QPainter.
bool mShowGridAnnotation
True if coordinate values should be drawn.
double gridOffsetX() const
GridFrameStyle mGridFrameStyle
void setGridAnnotationPrecision(int p)
Sets coordinate precision for grid annotations.
bool isDrawing() const
True if a draw is already in progress.
int mGridAnnotationPrecision
Digits after the dot.
QFont gridAnnotationFont() const
bool overviewInverted() const
Returns true if the overview frame is inverted.
virtual int type() const
return correct graphics item type.
QPainter::CompositionMode gridBlendMode() const
Returns the grid's blending mode.
QgsRectangle mExtent
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
QgsLineSymbolV2 * mGridLineSymbol
GridAnnotationDirection mLeftGridAnnotationDirection
Annotation direction on left side ( horizontal or vertical )
virtual void moveContent(double dx, double dy)
Move Content of item.
double mAnnotationFrameDistance
Distance between map frame and annotation.
int overviewFrameMapId() const
Returns id of overview frame (or -1 if no overfiew frame)
double gridFrameWidth() const
GridAnnotationDirection mRightGridAnnotationDirection
Annotation direction on right side ( horizontal or vertical )
QRectF mCurrentRectangle
Current bounding rectangle.
double mCrossLength
The length of the cross sides for mGridStyle Cross.
void setGridAnnotationFont(const QFont &f)
Sets font for grid annotations.
double mGridOffsetY
Grid line offset in y-direction.
QColor annotationFontColor() const
Get font color for grid annotations.
virtual void updateItem()
Updates item, with the possibility to do custom update for subclasses.
QPainter::CompositionMode overviewBlendMode() const
Returns the overview's blending mode.
bool drawCanvasItems() const
void setAnnotationFrameDistance(double d)
Sets distance between map frame and annotations.
const QgsMapRenderer * mapRenderer() const
double mYOffset
Offset in y direction for showing map cache image.
void setGridIntervalX(double interval)
Sets coordinate interval in x-direction for composergrid.
GridFrameStyle gridFrameStyle() const
double mGridIntervalX
Grid line interval in x-direction (map units)
GridAnnotationPosition mTopGridAnnotationPosition
Annotation position for top map side (inside / outside / not shown)
PreviewMode
Preview style.
GridAnnotationPosition mLeftGridAnnotationPosition
Annotation position for left map side (inside / outside / not shown)
GridAnnotationFormat mGridAnnotationFormat
Graphics scene for map printing.
GridAnnotationFormat gridAnnotationFormat() const
Object representing map window.
GridStyle mGridStyle
Solid or crosses.
GridStyle gridStyle() const
QgsFillSymbolV2 * mOverviewFrameMapSymbol
Drawing style for overview farme.
GridAnnotationPosition mRightGridAnnotationPosition
Annotation position for right map side (inside / outside / not shown)
GridAnnotationDirection mTopGridAnnotationDirection
Annotation direction on top side ( horizontal or vertical )
PreviewMode previewMode() const
int gridAnnotationPrecision() const
void setCrossLength(double l)
Sets length of the cros segments (if grid style is cross)
bool gridEnabled() const
virtual void zoomContent(int delta, double x, double y)
Zoom content of item.
int id() const
Get identification number.
bool mKeepLayerSet
Flag if layers to be displayed should be read from qgis canvas (true) or from stored list in mLayerSe...
double mGridOffsetX
Grid line offset in x-direction.
QgsFillSymbolV2 * overviewFrameMapSymbol()
QgsMapRenderer * mMapRenderer
QgsRectangle extent() const
GridAnnotationDirection mBottomGridAnnotationDirection
Annotation direction on bottom side ( horizontal or vertical )
int mId
Unique identifier.
void setLayerSet(const QStringList &layerSet)
Setter for stored layer set that is used if mKeepLayerSet is true.
void setShowGridAnnotation(bool show)
Sets flag if grid annotation should be shown.
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...
double gridIntervalY() const
void setKeepLayerSet(bool enabled)
Setter for flag that determines if the stored layer set should be used or the current layer set of th...
double crossLength()
double gridOffsetY() const
void setGridOffsetX(double offset)
Sets x-coordinate offset for composer grid.
GridAnnotationPosition mBottomGridAnnotationPosition
Annotation position for bottom map side (inside / outside / not shown)
QColor mGridAnnotationFontColor
Font color for grid line annotation.
void setGridOffsetY(double offset)
Sets y-coordinate offset for composer grid.
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:75
void setGridFrameStyle(GridFrameStyle style)
Set grid frame style (NoGridFrame or Zebra)
PreviewMode mPreviewMode
Preview style.
virtual bool writeXML(QDomElement &elem, QDomDocument &doc) const =0
stores state in Dom element
QPainter::CompositionMode mGridBlendMode
Blend mode for grid.
int mNumCachedLayers
Number of layers when cache was created.