QGIS API Documentation  2.7.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 #include "qgsmapsettings.h" // TEMPORARY
36 #include "qgsprevieweffect.h" //for QgsPreviewEffect::PreviewMode
37 
38 #ifdef HAVE_TOUCH
39 #include <QGestureEvent>
40 #endif
41 
42 class QWheelEvent;
43 class QPixmap;
44 class QPaintEvent;
45 class QKeyEvent;
46 class ResizeEvent;
47 
48 class QColor;
49 class QDomDocument;
50 class QPaintDevice;
51 class QMouseEvent;
52 class QRubberBand;
53 class QGraphicsScene;
54 
55 class QgsMapToPixel;
56 class QgsMapLayer;
57 class QgsHighlight;
58 class QgsVectorLayer;
59 
60 class QgsLabelingResults;
61 class QgsMapRenderer;
64 class QgsMapSettings;
65 class QgsMapCanvasMap;
67 class QgsMapTool;
68 
74 class GUI_EXPORT QgsMapCanvasLayer
75 {
76  public:
77  QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = true, bool isInOverview = false )
78  : mLayer( layer ), mVisible( visible ), mInOverview( isInOverview ) {}
79 
80  void setVisible( bool visible ) { mVisible = visible; }
81  void setInOverview( bool isInOverview ) { mInOverview = isInOverview; }
82 
83  bool isVisible() const { return mVisible; }
84  bool isInOverview() const { return mInOverview; }
85 
86  QgsMapLayer* layer() { return mLayer; }
87  const QgsMapLayer* layer() const { return mLayer; }
88 
89  private:
90  QgsMapLayer* mLayer;
91 
93  bool mVisible;
94 
96  bool mInOverview;
97 };
98 
99 
104 class GUI_EXPORT QgsMapCanvas : public QGraphicsView
105 {
106  Q_OBJECT
107 
108  public:
109 
110  enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
111 
113  QgsMapCanvas( QWidget * parent = 0, const char *name = 0 );
114 
116  ~QgsMapCanvas();
117 
118  void setLayerSet( QList<QgsMapCanvasLayer>& layers );
119 
120  void setCurrentLayer( QgsMapLayer* layer );
121 
122  // ### QGIS 3: make QgsMapCanvas independent from overview
123  void updateOverview();
124 
125  // ### QGIS 3: make QgsMapCanvas independent from overview
126  void enableOverviewMode( QgsMapOverviewCanvas* overview );
127 
130  const QgsMapSettings& mapSettings() const;
131 
134  void setCrsTransformEnabled( bool enabled );
135 
138  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
139 
142  const QgsLabelingResults* labelingResults() const;
143 
146  void setCachingEnabled( bool enabled );
147 
150  bool isCachingEnabled() const;
151 
154  void clearCache();
155 
158  void setParallelRenderingEnabled( bool enabled );
159 
162  bool isParallelRenderingEnabled() const;
163 
166  void setMapUpdateInterval( int timeMiliseconds );
167 
170  int mapUpdateInterval() const;
171 
173  QgsMapCanvasMap* map();
174 
180  Q_DECL_DEPRECATED QgsMapRenderer* mapRenderer();
181 
184  Q_DECL_DEPRECATED QPaintDevice &canvasPaintDevice();
185 
187  double scale();
188 
191  Q_DECL_DEPRECATED void clear();
192 
194  double mapUnitsPerPixel() const;
195 
197  QgsRectangle extent() const;
199  QgsRectangle fullExtent() const;
200 
202  void setExtent( const QgsRectangle &r );
203 
206  double rotation() const;
207 
210  void setRotation( double degrees );
211 
214  void setCenter( const QgsPoint& center );
215 
218  QgsPoint center() const;
219 
221  void zoomToFullExtent();
222 
224  void zoomToPreviousExtent();
225 
227  void zoomToNextExtent();
228 
229  // ! Clears the list of extents and sets current extent as first item
230  void clearExtentHistory();
231 
234  void zoomToSelected( QgsVectorLayer* layer = NULL );
235 
237  void panToSelected( QgsVectorLayer* layer = NULL );
238 
240  void setMapTool( QgsMapTool* mapTool );
241 
248  void unsetMapTool( QgsMapTool* mapTool );
249 
251  QgsMapTool* mapTool();
252 
254  virtual void setCanvasColor( const QColor & _newVal );
256  virtual QColor canvasColor() const;
257 
259  void setSelectionColor( const QColor& color );
261 
263  void updateScale();
264 
266  Q_DECL_DEPRECATED void updateFullExtent() {}
268 
270  QgsMapLayer *layer( int index );
271 
273  int layerCount() const;
274 
276  QList<QgsMapLayer*> layers() const;
277 
283  void freeze( bool frz = true );
284 
286  bool isFrozen();
287 
290  Q_DECL_DEPRECATED void setDirty( bool _dirty );
291 
294  Q_DECL_DEPRECATED bool isDirty() const;
295 
297  void setMapUnits( QGis::UnitType mapUnits );
299 
300  QGis::UnitType mapUnits() const;
301 
303  const QgsMapToPixel* getCoordinateTransform();
304 
306  bool isDrawing();
307 
309  QgsMapLayer* currentLayer();
310 
312  void setWheelAction( WheelAction action, double factor = 2 );
313 
315  void zoomIn();
316 
318  void zoomOut();
319 
321  void zoomScale( double scale );
322 
325  void zoomByFactor( double scaleFactor, const QgsPoint *center = 0 );
326 
328  void zoomWithCenter( int x, int y, bool zoomIn );
329 
331  void enableAntiAliasing( bool theFlag );
332 
334  bool antiAliasingEnabled() const { return mSettings.testFlag( QgsMapSettings::Antialiasing ); }
335 
338  Q_DECL_DEPRECATED void useImageToRender( bool theFlag );
339 
340  // following 2 methods should be moved elsewhere or changed to private
341  // currently used by pan map tool
343  void panActionEnd( QPoint releasePoint );
344 
346  void panAction( QMouseEvent * event );
347 
349  QPoint mouseLastXY();
350 
355  void setPreviewModeEnabled( bool previewEnabled );
356 
362  bool previewModeEnabled() const;
363 
371  void setPreviewMode( QgsPreviewEffect::PreviewMode mode );
372 
379  QgsPreviewEffect::PreviewMode previewMode() const;
380 
381  public slots:
382 
384  void refresh();
385 
387  void selectionChangedSlot();
388 
390  void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" );
391 
393  void layerStateChange();
394 
396  void setRenderFlag( bool theFlag );
398  bool renderFlag() {return mRenderFlag;};
399 
401  bool hasCrsTransformEnabled();
402 
404  Q_DECL_DEPRECATED void updateMap();
405 
408  void stopRendering();
409 
411  Q_DECL_DEPRECATED void showError( QgsMapLayer * mapLayer );
412 
414  void readProject( const QDomDocument & );
415 
417  void writeProject( QDomDocument & );
418 
420  void getDatumTransformInfo( const QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId );
421 
422  private slots:
424  void mapToolDestroyed();
425 
427  void rendererJobFinished();
428 
429  void mapUpdateTimeout();
430 
431  void refreshMap();
432 
433  signals:
435  Q_DECL_DEPRECATED void setProgress( int, int );
437 
440  void xyCoordinates( const QgsPoint &p );
441 
443  void scaleChanged( double );
444 
446  void extentsChanged();
447 
450  void rotationChanged( double );
451 
460  void renderComplete( QPainter * );
464 
465  // ### QGIS 3: renamte to mapRefreshFinished()
467  void mapCanvasRefreshed();
468 
469  // ### QGIS 3: rename to mapRefreshStarted()
471  void renderStarting();
472 
474  void layersChanged();
475 
477  void keyPressed( QKeyEvent * e );
478 
480  void keyReleased( QKeyEvent * e );
481 
483  void mapToolSet( QgsMapTool *tool );
484 
488  void mapToolSet( QgsMapTool *newTool, QgsMapTool* oldTool );
489 
490  // ### QGIS 3: remove the signal
492  void selectionChanged( QgsMapLayer * layer );
493 
495  void zoomLastStatusChanged( bool );
496 
498  void zoomNextStatusChanged( bool );
499 
502  void hasCrsTransformEnabledChanged( bool flag );
503 
506  void destinationCrsChanged();
507 
510  void mapUnitsChanged();
511 
512  protected:
513 #ifdef HAVE_TOUCH
514  bool event( QEvent * e );
516 #endif
517 
519  void keyPressEvent( QKeyEvent * e );
520 
522  void keyReleaseEvent( QKeyEvent * e );
523 
525  void mouseDoubleClickEvent( QMouseEvent * e );
526 
528  void mouseMoveEvent( QMouseEvent * e );
529 
531  void mousePressEvent( QMouseEvent * e );
532 
534  void mouseReleaseEvent( QMouseEvent * e );
535 
537  void wheelEvent( QWheelEvent * e );
538 
540  void resizeEvent( QResizeEvent * e );
541 
543  void paintEvent( QPaintEvent * e );
544 
546  void dragEnterEvent( QDragEnterEvent * e );
547 
549  void moveCanvasContents( bool reset = false );
550 
552  void updateCanvasItemPositions();
553 
556 
558  std::auto_ptr<CanvasProperties> mCanvasProperties;
559 
563  void connectNotify( const char * signal );
564 
566  void updateDatumTransformEntries();
567 
568  private:
570 
576  QgsMapCanvas( QgsMapCanvas const & );
577 
579  QgsMapSettings mSettings;
580 
582  QgsMapRenderer* mMapRenderer;
583 
585  QgsMapCanvasMap* mMap;
586 
588  QgsMapOverviewCanvas* mMapOverview;
589 
591  bool mFrozen;
592 
594  bool mRefreshScheduled;
595 
597  bool mRenderFlag;
598 
600  QgsMapLayer* mCurrentLayer;
601 
603  QGraphicsScene* mScene;
604 
606  QgsMapTool* mMapTool;
607 
609  QgsMapTool* mLastNonZoomMapTool;
610 
612  QList <QgsRectangle> mLastExtent;
613  int mLastExtentIndex;
614 
616  double mWheelZoomFactor;
617 
619  WheelAction mWheelAction;
620 
622  QTimer mMapUpdateTimer;
623 
626 
628  bool mJobCancelled;
629 
631  QgsLabelingResults* mLabelingResults;
632 
634  bool mUseParallelRendering;
635 
637  bool mDrawRenderingStats;
638 
640  QgsMapRendererCache* mCache;
641 
642  QTimer *mResizeTimer;
643 
644  QgsPreviewEffect* mPreviewEffect;
645 
646 }; // class QgsMapCanvas
647 
648 
649 
650 
658 class QgsMapCanvasRendererSync : public QObject
659 {
660  Q_OBJECT
661  public:
663 
664  protected slots:
665  void onExtentC2R();
666  void onExtentR2C();
667 
668  void onMapUnitsC2R();
669  void onMapUnitsR2C();
670 
672  void onMapRotationC2R();
674  void onMapRotationR2C();
675 
676  void onCrsTransformC2R();
677  void onCrsTransformR2C();
678 
679  void onDestCrsC2R();
680  void onDestCrsR2C();
681 
682  void onLayersC2R();
683 
684  protected:
687 
689 };
690 
691 
692 #endif
static unsigned index
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:48
void setInOverview(bool isInOverview)
Definition: qgsmapcanvas.h:81
A widget that displays an overview map.
UnitType
Map units that qgis supports.
Definition: qgis.h:229
A class that stores visibility and presence in overview flags together with pointer to the layer...
Definition: qgsmapcanvas.h:74
bool isVisible() const
Definition: qgsmapcanvas.h:83
A non GUI class for rendering a map layer set onto a QPainter.
bool antiAliasingEnabled() const
true if antialising is enabled
Definition: qgsmapcanvas.h:334
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:104
void setVisible(bool visible)
Definition: qgsmapcanvas.h:80
A graphics effect which can be applied to a widget to simulate various printing and color blindness m...
bool renderFlag()
State of render suppression flag.
Definition: qgsmapcanvas.h:398
The QgsMapSettings class contains configuration for rendering of the map.
QgsMapRenderer * mRenderer
Definition: qgsmapcanvas.h:686
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:34
A rectangular graphics item representing the map on the canvas.
QgsMapCanvas * mCanvas
Definition: qgsmapcanvas.h:685
Enable anti-aliasin for map rendering.
A class for highlight features on the map.
Definition: qgshighlight.h:36
const QgsMapLayer * layer() const
Definition: qgsmapcanvas.h:87
A class to represent a point.
Definition: qgspoint.h:63
Abstract base class for all map tools.
Definition: qgsmaptool.h:48
bool isInOverview() const
Definition: qgsmapcanvas.h:84
Intermediate base class adding functionality that allows client to query the rendered image...
Class for storing a coordinate reference system (CRS)
QgsMapCanvasRendererSync(QgsMapCanvas *canvas, QgsMapRenderer *renderer)
QgsMapCanvasLayer(QgsMapLayer *layer, bool visible=true, bool isInOverview=false)
Definition: qgsmapcanvas.h:77
Class that stores computed placement from labeling engine.
This class is responsible for keeping cache of rendered images of individual layers.
Class that does synchronization between QgsMapCanvas and its associated QgsMapRenderer: ...
Definition: qgsmapcanvas.h:658
Represents a vector layer which manages a vector based data sets.
QgsMapLayer * layer()
Definition: qgsmapcanvas.h:86
std::auto_ptr< CanvasProperties > mCanvasProperties
Handle pattern for implementation object.
Definition: qgsmapcanvas.h:555