Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 /* $Id: qgsmapcanvas.h 5341 2006-04-22 12:11:36Z wonder $ */
18 
19 #ifndef QGSMAPCANVAS_H
20 #define QGSMAPCANVAS_H
21 
22 #include <list>
23 #include <memory>
24 #include <deque>
25 
26 #include "qgsrectangle.h"
27 #include "qgspoint.h"
28 #include "qgis.h"
29 
30 #include <QDomDocument>
31 #include <QGraphicsView>
32 #include <QtCore>
33 
34 class QWheelEvent;
35 class QPixmap;
36 class QPaintEvent;
37 class QKeyEvent;
38 class ResizeEvent;
39 
40 class QColor;
41 class QDomDocument;
42 class QPaintDevice;
43 class QMouseEvent;
44 class QRubberBand;
45 class QGraphicsScene;
46 
47 class QgsMapToPixel;
48 class QgsMapLayer;
49 class QgsLegend;
50 class QgsLegendView;
51 class QgsHighlight;
52 class QgsVectorLayer;
53 
54 class QgsMapRenderer;
55 class QgsMapCanvasMap;
57 class QgsMapTool;
58 
64 class GUI_EXPORT QgsMapCanvasLayer
65 {
66  public:
67  QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = true, bool isInOverview = false )
68  : mLayer( layer ), mVisible( visible ), mInOverview( isInOverview ) {}
69 
70  void setVisible( bool visible ) { mVisible = visible; }
71  void setInOverview( bool isInOverview ) { mInOverview = isInOverview; }
72 
73  bool isVisible() const { return mVisible; }
74  bool isInOverview() const { return mInOverview; }
75 
76  QgsMapLayer* layer() { return mLayer; }
77  const QgsMapLayer* layer() const { return mLayer; }
78 
79  private:
81 
83  bool mVisible;
84 
87 };
88 
89 
94 class GUI_EXPORT QgsMapCanvas : public QGraphicsView
95 {
96  Q_OBJECT
97 
98  public:
99 
100  enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
101 
103  QgsMapCanvas( QWidget * parent = 0, const char *name = 0 );
104 
106  ~QgsMapCanvas();
107 
108  void setLayerSet( QList<QgsMapCanvasLayer>& layers );
109 
110  void setCurrentLayer( QgsMapLayer* layer );
111 
112  void updateOverview();
113 
114  void enableOverviewMode( QgsMapOverviewCanvas* overview );
115 
116  QgsMapCanvasMap* map();
117 
118  QgsMapRenderer* mapRenderer();
119 
122  Q_DECL_DEPRECATED QPixmap& canvasPixmap();
123 
125  QPaintDevice &canvasPaintDevice();
126 
128  double scale();
129 
131  void clear();
132 
134  double mapUnitsPerPixel() const;
135 
137  QgsRectangle extent() const;
139  QgsRectangle fullExtent() const;
140 
142  void setExtent( QgsRectangle const & r );
143 
145  void zoomToFullExtent();
146 
148  void zoomToPreviousExtent();
149 
151  void zoomToNextExtent();
152 
153  // ! Clears the list of extents and sets current extent as first item
154  void clearExtentHistory();
155 
158  void zoomToSelected( QgsVectorLayer* layer = NULL );
159 
161  void setMapTool( QgsMapTool* mapTool );
162 
169  void unsetMapTool( QgsMapTool* mapTool );
170 
172  QgsMapTool* mapTool();
173 
175  virtual void setCanvasColor( const QColor & _newVal );
177  virtual QColor canvasColor() const;
178 
180  void updateScale();
181 
183  void updateFullExtent();
184 
186  QgsMapLayer *layer( int index );
187 
189  int layerCount() const;
190 
192  QList<QgsMapLayer*> layers() const;
193 
199  void freeze( bool frz = true );
200 
202  bool isFrozen();
203 
205  void setDirty( bool _dirty );
206 
208  bool isDirty() const;
209 
211  void setMapUnits( QGis::UnitType mapUnits );
213 
214  QGis::UnitType mapUnits() const;
215 
217  const QgsMapToPixel* getCoordinateTransform();
218 
220  bool isDrawing();
221 
223  QgsMapLayer* currentLayer();
224 
226  void setWheelAction( WheelAction action, double factor = 2 );
227 
229  void zoomIn( );
230 
232  void zoomOut( );
233 
235  // added in 1.5
236  void zoomScale( double scale );
237 
239  void zoomByFactor( double scaleFactor );
240 
242  void zoomWithCenter( int x, int y, bool zoomIn );
243 
245  void enableAntiAliasing( bool theFlag );
246 
248  bool antiAliasingEnabled() const { return mAntiAliasing; }
249 
251  void useImageToRender( bool theFlag );
252 
253  // following 2 methods should be moved elsewhere or changed to private
254  // currently used by pan map tool
256  void panActionEnd( QPoint releasePoint );
257 
259  void panAction( QMouseEvent * event );
260 
262  QPoint mouseLastXY();
263 
264  public slots:
265 
267  void refresh();
268 
270  void selectionChangedSlot();
271 
273  void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" );
274 
276  void layerStateChange();
277 
279  void setRenderFlag( bool theFlag );
281  bool renderFlag() {return mRenderFlag;};
282 
284  bool hasCrsTransformEnabled();
285 
287  void mapUnitsChanged();
288 
290  void updateMap();
291 
293  void showError( QgsMapLayer * mapLayer );
294 
296  void readProject( const QDomDocument & );
297 
299  void writeProject( QDomDocument & );
300 
301  signals:
303  void setProgress( int, int );
304 
307  void xyCoordinates( const QgsPoint & p );
308 
310  void scaleChanged( double );
311 
313  void extentsChanged();
314 
323  void renderComplete( QPainter * );
324 
327  void renderStarting();
328 
330  void layersChanged();
331 
333  void keyPressed( QKeyEvent * e );
334 
336  void keyReleased( QKeyEvent * e );
337 
339  void mapToolSet( QgsMapTool * tool );
340 
342  void selectionChanged( QgsMapLayer * layer );
343 
346  void zoomLastStatusChanged( bool );
347 
350  void zoomNextStatusChanged( bool );
351 
352  protected:
354  void keyPressEvent( QKeyEvent * e );
355 
357  void keyReleaseEvent( QKeyEvent * e );
358 
360  void mouseDoubleClickEvent( QMouseEvent * e );
361 
363  void mouseMoveEvent( QMouseEvent * e );
364 
366  void mousePressEvent( QMouseEvent * e );
367 
369  void mouseReleaseEvent( QMouseEvent * e );
370 
372  void wheelEvent( QWheelEvent * e );
373 
375  void resizeEvent( QResizeEvent * e );
376 
378  void paintEvent( QPaintEvent * e );
379 
381  void moveCanvasContents( bool reset = false );
382 
384  void updateCanvasItemPositions();
385 
388 
390  std::auto_ptr<CanvasProperties> mCanvasProperties;
391 
395  void connectNotify( const char * signal );
396 
397  private:
399 
405  QgsMapCanvas( QgsMapCanvas const & );
406 
409 
412 
415 
417  bool mDrawing;
418 
420  bool mFrozen;
421 
431  bool mDirty;
432 
435 
439  QList< QPair<int, int> > mResizeQueue;
440 
443 
445  QGraphicsScene* mScene;
446 
449 
452 
454  QList <QgsRectangle> mLastExtent;
456 
459 
462 
464  QSize mNewSize;
465 
467  bool mPainting;
468 
471 }; // class QgsMapCanvas
472 
473 
474 #endif