QGIS API Documentation  2.2.0-Valmiera
 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 
307  void getDatumTransformInfo( const QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId );
308 
309  private slots:
311  void mapToolDestroyed();
312 
313  signals:
315  void setProgress( int, int );
316 
319  void xyCoordinates( const QgsPoint &p );
320 
322  void scaleChanged( double );
323 
325  void extentsChanged();
326 
335  void renderComplete( QPainter * );
336 
339  void mapCanvasRefreshed();
340 
343  void renderStarting();
344 
346  void layersChanged();
347 
349  void keyPressed( QKeyEvent * e );
350 
352  void keyReleased( QKeyEvent * e );
353 
355  void mapToolSet( QgsMapTool *tool );
356 
358  void selectionChanged( QgsMapLayer * layer );
359 
362  void zoomLastStatusChanged( bool );
363 
366  void zoomNextStatusChanged( bool );
367 
368  protected:
369 #ifdef HAVE_TOUCH
370 
371  bool event( QEvent * e );
372 #endif
373 
375  void keyPressEvent( QKeyEvent * e );
376 
378  void keyReleaseEvent( QKeyEvent * e );
379 
381  void mouseDoubleClickEvent( QMouseEvent * e );
382 
384  void mouseMoveEvent( QMouseEvent * e );
385 
387  void mousePressEvent( QMouseEvent * e );
388 
390  void mouseReleaseEvent( QMouseEvent * e );
391 
393  void wheelEvent( QWheelEvent * e );
394 
396  void resizeEvent( QResizeEvent * e );
397 
399  void paintEvent( QPaintEvent * e );
400 
402  void dragEnterEvent( QDragEnterEvent * e );
403 
405  void moveCanvasContents( bool reset = false );
406 
408  void updateCanvasItemPositions();
409 
412 
414  std::auto_ptr<CanvasProperties> mCanvasProperties;
415 
419  void connectNotify( const char * signal );
420 
421  private slots:
422  void crsTransformEnabled( bool );
423 
424  private:
426 
432  QgsMapCanvas( QgsMapCanvas const & );
433 
436 
439 
442 
446  bool mDrawing;
447 
449  bool mFrozen;
450 
460  bool mDirty;
461 
464 
468  QList< QPair<int, int> > mResizeQueue;
469 
472 
474  QGraphicsScene* mScene;
475 
478 
481 
483  QList <QgsRectangle> mLastExtent;
485 
488 
491 
493  QSize mNewSize;
494 
496  bool mPainting;
497 
500 
501  QTimer *mResizeTimer;
502 }; // class QgsMapCanvas
503 
504 
505 #endif