QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsmapcanvas.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmapcanvas.h - description
3  -------------------
4  begin : Sun Jun 30 2002
5  copyright : (C) 2002 by Gary E.Sherman
6  email : sherman at mrcc.com
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 
18 #ifndef QGSMAPCANVAS_H
19 #define QGSMAPCANVAS_H
20 
21 #include "qgsconfig.h"
22 
23 #include <list>
24 #include <memory>
25 #include <deque>
26 
27 #include "qgsrectangle.h"
28 #include "qgspoint.h"
29 #include "qgis.h"
30 
31 #include <QDomDocument>
32 #include <QGraphicsView>
33 #include <QtCore>
34 
35 #ifdef HAVE_TOUCH
36 #include <QGestureEvent>
37 #endif
38 
39 class QWheelEvent;
40 class QPixmap;
41 class QPaintEvent;
42 class QKeyEvent;
43 class ResizeEvent;
44 
45 class QColor;
46 class QDomDocument;
47 class QPaintDevice;
48 class QMouseEvent;
49 class QRubberBand;
50 class QGraphicsScene;
51 
52 class QgsMapToPixel;
53 class QgsMapLayer;
54 class QgsLegend;
55 class QgsLegendView;
56 class QgsHighlight;
57 class QgsVectorLayer;
58 
59 class QgsMapRenderer;
60 class QgsMapCanvasMap;
62 class QgsMapTool;
63 
69 class GUI_EXPORT QgsMapCanvasLayer
70 {
71  public:
72  QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = true, bool isInOverview = false )
73  : mLayer( layer ), mVisible( visible ), mInOverview( isInOverview ) {}
74 
75  void setVisible( bool visible ) { mVisible = visible; }
76  void setInOverview( bool isInOverview ) { mInOverview = isInOverview; }
77 
78  bool isVisible() const { return mVisible; }
79  bool isInOverview() const { return mInOverview; }
80 
81  QgsMapLayer* layer() { return mLayer; }
82  const QgsMapLayer* layer() const { return mLayer; }
83 
84  private:
86 
88  bool mVisible;
89 
92 };
93 
94 
99 class GUI_EXPORT QgsMapCanvas : public QGraphicsView
100 {
101  Q_OBJECT
102 
103  public:
104 
105  enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
106 
108  QgsMapCanvas( QWidget * parent = 0, const char *name = 0 );
109 
111  ~QgsMapCanvas();
112 
113  void setLayerSet( QList<QgsMapCanvasLayer>& layers );
114 
115  void setCurrentLayer( QgsMapLayer* layer );
116 
117  void updateOverview();
118 
119  void enableOverviewMode( QgsMapOverviewCanvas* overview );
120 
121  QgsMapCanvasMap* map();
122 
123  QgsMapRenderer* mapRenderer();
124 
126  QPaintDevice &canvasPaintDevice();
127 
129  double scale();
130 
132  void clear();
133 
135  double mapUnitsPerPixel() const;
136 
138  QgsRectangle extent() const;
140  QgsRectangle fullExtent() const;
141 
143  void setExtent( const QgsRectangle &r );
144 
146  void zoomToFullExtent();
147 
149  void zoomToPreviousExtent();
150 
152  void zoomToNextExtent();
153 
154  // ! Clears the list of extents and sets current extent as first item
155  void clearExtentHistory();
156 
159  void zoomToSelected( QgsVectorLayer* layer = NULL );
160 
163  void panToSelected( QgsVectorLayer* layer = NULL );
164 
166  void setMapTool( QgsMapTool* mapTool );
167 
174  void unsetMapTool( QgsMapTool* mapTool );
175 
177  QgsMapTool* mapTool();
178 
180  virtual void setCanvasColor( const QColor & _newVal );
182  virtual QColor canvasColor() const;
183 
185  void updateScale();
186 
188  void updateFullExtent();
189 
191  QgsMapLayer *layer( int index );
192 
194  int layerCount() const;
195 
197  QList<QgsMapLayer*> layers() const;
198 
204  void freeze( bool frz = true );
205 
207  bool isFrozen();
208 
210  void setDirty( bool _dirty );
211 
213  bool isDirty() const;
214 
216  void setMapUnits( QGis::UnitType mapUnits );
218 
219  QGis::UnitType mapUnits() const;
220 
222  const QgsMapToPixel* getCoordinateTransform();
223 
225  bool isDrawing();
226 
228  QgsMapLayer* currentLayer();
229 
231  void setWheelAction( WheelAction action, double factor = 2 );
232 
234  void zoomIn( );
235 
237  void zoomOut( );
238 
240  // added in 1.5
241  void zoomScale( double scale );
242 
244  void zoomByFactor( double scaleFactor );
245 
247  void zoomWithCenter( int x, int y, bool zoomIn );
248 
250  void enableAntiAliasing( bool theFlag );
251 
253  bool antiAliasingEnabled() const { return mAntiAliasing; }
254 
256  void useImageToRender( bool theFlag );
257 
258  // following 2 methods should be moved elsewhere or changed to private
259  // currently used by pan map tool
261  void panActionEnd( QPoint releasePoint );
262 
264  void panAction( QMouseEvent * event );
265 
267  QPoint mouseLastXY();
268 
269  public slots:
270 
272  void refresh();
273 
275  void selectionChangedSlot();
276 
278  void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" );
279 
281  void layerStateChange();
282 
284  void setRenderFlag( bool theFlag );
286  bool renderFlag() {return mRenderFlag;};
287 
289  bool hasCrsTransformEnabled();
290 
292  void mapUnitsChanged();
293 
295  void updateMap();
296 
298  void showError( QgsMapLayer * mapLayer );
299 
301  void readProject( const QDomDocument & );
302 
304  void writeProject( QDomDocument & );
305 
306  private slots:
308  void mapToolDestroyed();
309 
310  signals:
312  void setProgress( int, int );
313 
316  void xyCoordinates( const QgsPoint &p );
317 
319  void scaleChanged( double );
320 
322  void extentsChanged();
323 
332  void renderComplete( QPainter * );
333 
336  void mapCanvasRefreshed();
337 
340  void renderStarting();
341 
343  void layersChanged();
344 
346  void keyPressed( QKeyEvent * e );
347 
349  void keyReleased( QKeyEvent * e );
350 
352  void mapToolSet( QgsMapTool *tool );
353 
355  void selectionChanged( QgsMapLayer * layer );
356 
359  void zoomLastStatusChanged( bool );
360 
363  void zoomNextStatusChanged( bool );
364 
365  protected:
366 #ifdef HAVE_TOUCH
367 
368  bool event( QEvent * e );
369 #endif
370 
372  void keyPressEvent( QKeyEvent * e );
373 
375  void keyReleaseEvent( QKeyEvent * e );
376 
378  void mouseDoubleClickEvent( QMouseEvent * e );
379 
381  void mouseMoveEvent( QMouseEvent * e );
382 
384  void mousePressEvent( QMouseEvent * e );
385 
387  void mouseReleaseEvent( QMouseEvent * e );
388 
390  void wheelEvent( QWheelEvent * e );
391 
393  void resizeEvent( QResizeEvent * e );
394 
396  void paintEvent( QPaintEvent * e );
397 
399  void dragEnterEvent( QDragEnterEvent * e );
400 
402  void moveCanvasContents( bool reset = false );
403 
405  void updateCanvasItemPositions();
406 
409 
411  std::auto_ptr<CanvasProperties> mCanvasProperties;
412 
416  void connectNotify( const char * signal );
417 
418  private slots:
419  void crsTransformEnabled( bool );
420 
421  private:
423 
429  QgsMapCanvas( QgsMapCanvas const & );
430 
433 
436 
439 
443  bool mDrawing;
444 
446  bool mFrozen;
447 
457  bool mDirty;
458 
461 
465  QList< QPair<int, int> > mResizeQueue;
466 
469 
471  QGraphicsScene* mScene;
472 
475 
478 
480  QList <QgsRectangle> mLastExtent;
482 
485 
488 
490  QSize mNewSize;
491 
493  bool mPainting;
494 
497 }; // class QgsMapCanvas
498 
499 
500 #endif