Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 <QGraphicsRectItem>
24 
25 class QgsComposition;
26 class QgsMapRenderer;
27 class QgsMapToPixel;
28 class QDomNode;
29 class QDomDocument;
30 class QGraphicsView;
31 class QPainter;
32 
37 // NOTE: QgsComposerMapBase must be first, otherwise does not compile
38 class CORE_EXPORT QgsComposerMap : public QgsComposerItem
39 {
40  Q_OBJECT
41 
42  public:
44  QgsComposerMap( QgsComposition *composition, int x, int y, int width, int height );
46  QgsComposerMap( QgsComposition *composition );
47  ~QgsComposerMap();
48 
50  virtual int type() const { return ComposerMap; }
51 
54  {
55  Cache = 0, // Use raster cache
56  Render, // Render the map
57  Rectangle // Display only rectangle
58  };
59 
60  enum GridStyle
61  {
62  Solid = 0, //solid lines
63  Cross //only draw line crossings
64  };
65 
67  {
68  InsideMapFrame = 0,
69  OutsideMapFrame
70  };
71 
73  {
74  Horizontal = 0,
77  BoundaryDirection
78  };
79 
81  void draw( QPainter *painter, const QgsRectangle& extent, const QSize& size, int dpi );
82 
88  void draw( QPainter *painter, const QgsRectangle& extent, const QSizeF& size, double dpi );
89 
91  void paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget );
92 
94  void cache( void );
95 
97  int id() const {return mId;}
98 
100  bool isDrawing() const {return mDrawing;}
101 
103  void resize( double dx, double dy );
104 
108  void moveContent( double dx, double dy );
109 
114  void zoomContent( int delta, double x, double y );
115 
117  void setSceneRect( const QRectF& rectangle );
118 
120  double scale( void ) const;
121 
123  void setNewScale( double scaleDenominator );
124 
126  void setNewExtent( const QgsRectangle& extent );
127 
128  PreviewMode previewMode() {return mPreviewMode;}
129  void setPreviewMode( PreviewMode m ) {mPreviewMode = m;}
130 
133  bool keepLayerSet() const {return mKeepLayerSet;}
136  void setKeepLayerSet( bool enabled ) {mKeepLayerSet = enabled;}
137 
140  QStringList layerSet() const {return mLayerSet;}
143  void setLayerSet( const QStringList& layerSet ) {mLayerSet = layerSet;}
145  void storeCurrentLayerSet();
146 
147  // Set cache outdated
148  void setCacheUpdated( bool u = false );
149 
150  QgsRectangle extent() const {return mExtent;}
151 
152  const QgsMapRenderer* mapRenderer() const {return mMapRenderer;}
153 
155  void setOffset( double xOffset, double yOffset );
156 
158  bool containsWMSLayer() const;
159 
164  bool writeXML( QDomElement& elem, QDomDocument & doc ) const;
165 
170  bool readXML( const QDomElement& itemElem, const QDomDocument& doc );
171 
174  void setGridEnabled( bool enabled ) {mGridEnabled = enabled;}
175  bool gridEnabled() const { return mGridEnabled; }
176 
179  void setGridStyle( GridStyle style ) {mGridStyle = style;}
180  GridStyle gridStyle() const { return mGridStyle; }
181 
184  void setGridIntervalX( double interval ) { mGridIntervalX = interval;}
185  double gridIntervalX() const { return mGridIntervalX; }
186 
189  void setGridIntervalY( double interval ) { mGridIntervalY = interval;}
190  double gridIntervalY() const { return mGridIntervalY; }
191 
194  void setGridOffsetX( double offset ) { mGridOffsetX = offset; }
195  double gridOffsetX() const { return mGridOffsetX; }
196 
199  void setGridOffsetY( double offset ) { mGridOffsetY = offset; }
200  double gridOffsetY() const { return mGridOffsetY; }
201 
204  void setGridPen( const QPen& p ) { mGridPen = p; }
205  QPen gridPen() const { return mGridPen; }
208  void setGridPenWidth( double w );
211  void setGridPenColor( const QColor& c );
212 
215  void setGridAnnotationFont( const QFont& f ) { mGridAnnotationFont = f; }
216  QFont gridAnnotationFont() const { return mGridAnnotationFont; }
217 
220  void setGridAnnotationPrecision( int p ) {mGridAnnotationPrecision = p;}
221  int gridAnnotationPrecision() const {return mGridAnnotationPrecision;}
222 
225  void setShowGridAnnotation( bool show ) {mShowGridAnnotation = show;}
226  bool showGridAnnotation() const {return mShowGridAnnotation;}
227 
230  void setGridAnnotationPosition( GridAnnotationPosition p ) {mGridAnnotationPosition = p;}
231  GridAnnotationPosition gridAnnotationPosition() const {return mGridAnnotationPosition;}
232 
235  void setAnnotationFrameDistance( double d ) {mAnnotationFrameDistance = d;}
236  double annotationFrameDistance() const {return mAnnotationFrameDistance;}
237 
240  void setGridAnnotationDirection( GridAnnotationDirection d ) {mGridAnnotationDirection = d;}
241  GridAnnotationDirection gridAnnotationDirection() const {return mGridAnnotationDirection;}
242 
245  QRectF boundingRect() const;
248  void updateBoundingRect();
249 
252  void setCrossLength( double l ) {mCrossLength = l;}
253  double crossLength() {return mCrossLength;}
254 
255  void setMapRotation( double r );
256 
258  void setMapCanvas( QGraphicsView* canvas ) { mMapCanvas = canvas; }
259 
260  void setDrawCanvasItems( bool b ) { mDrawCanvasItems = b; }
261  bool drawCanvasItems() const { return mDrawCanvasItems; }
262 
264  double mapUnitsToMM() const;
265 
266  signals:
267  void extentChanged();
268 
269  public slots:
270 
272  void updateCachedImage( );
274  void renderModeUpdateCachedImage();
275 
276  private:
277 
279  enum Border
280  {
284  Top
285  };
286 
287  // Pointer to map renderer of the QGIS main map. Note that QgsComposerMap uses a different map renderer,
288  //it just copies some properties from the main map renderer.
290 
292  int mId;
293 
294  // Map region in map units realy used for rendering
295  // It can be the same as mUserExtent, but it can be bigger in on dimension if mCalculate==Scale,
296  // so that full rectangle in paper is used.
298 
299  // Cache used in composer preview
300  QImage mCacheImage;
301 
302  // Is cache up to date
304 
307 
310 
312  bool mDrawing;
313 
315  double mXOffset;
317  double mYOffset;
318 
321 
323  QStringList mLayerSet;
324 
326  void connectUpdateSlot();
327 
329  void syncLayerSet();
330 
340  double mGridOffsetX;
342  double mGridOffsetY;
344  QPen mGridPen;
360  double mCrossLength;
361  QGraphicsView* mMapCanvas;
364 
366  void drawGrid( QPainter* p );
371  void drawCoordinateAnnotations( QPainter* p, const QList< QPair< double, QLineF > >& hLines, const QList< QPair< double, QLineF > >& vLines );
372  void drawCoordinateAnnotation( QPainter* p, const QPointF& pos, QString annotationString );
378  void drawAnnotation( QPainter* p, const QPointF& pos, int rotation, const QString& annotationText );
381  int xGridLines( QList< QPair< double, QLineF > >& lines ) const;
384  int yGridLines( QList< QPair< double, QLineF > >& lines ) const;
386  QgsRectangle transformedExtent() const;
388  QPolygonF transformedMapPolygon() const;
389  double maxExtension() const;
393  void mapPolygon( QPolygonF& poly ) const;
395  void requestedExtent( QgsRectangle& extent ) const;
399  void transformShift( double& xShift, double& yShift ) const;
401  QPointF mapToItemCoords( const QPointF& mapCoords ) const;
403  Border borderForLineCoord( const QPointF& p ) const;
404 
405  void drawCanvasItems( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
406  void drawCanvasItem( QGraphicsItem* item, QPainter* painter, const QStyleOptionGraphicsItem* itemStyle );
407  QPointF composerMapPosForItem( const QGraphicsItem* item ) const;
408 };
409 
410 #endif