QGIS API Documentation  2.3.0-Master
 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 #include "qgsmapsettings.h" // TEMPORARY
36 
37 #ifdef HAVE_TOUCH
38 #include <QGestureEvent>
39 #endif
40 
41 class QWheelEvent;
42 class QPixmap;
43 class QPaintEvent;
44 class QKeyEvent;
45 class ResizeEvent;
46 
47 class QColor;
48 class QDomDocument;
49 class QPaintDevice;
50 class QMouseEvent;
51 class QRubberBand;
52 class QGraphicsScene;
53 
54 class QgsMapToPixel;
55 class QgsMapLayer;
56 class QgsLegend;
57 class QgsLegendView;
58 class QgsHighlight;
59 class QgsVectorLayer;
60 
61 class QgsLabelingResults;
62 class QgsMapRenderer;
65 class QgsMapSettings;
66 class QgsMapCanvasMap;
68 class QgsMapTool;
69 
75 class GUI_EXPORT QgsMapCanvasLayer
76 {
77  public:
78  QgsMapCanvasLayer( QgsMapLayer* layer, bool visible = true, bool isInOverview = false )
79  : mLayer( layer ), mVisible( visible ), mInOverview( isInOverview ) {}
80 
81  void setVisible( bool visible ) { mVisible = visible; }
82  void setInOverview( bool isInOverview ) { mInOverview = isInOverview; }
83 
84  bool isVisible() const { return mVisible; }
85  bool isInOverview() const { return mInOverview; }
86 
87  QgsMapLayer* layer() { return mLayer; }
88  const QgsMapLayer* layer() const { return mLayer; }
89 
90  private:
92 
94  bool mVisible;
95 
98 };
99 
100 
105 class GUI_EXPORT QgsMapCanvas : public QGraphicsView
106 {
107  Q_OBJECT
108 
109  public:
110 
111  enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelZoomToMouseCursor, WheelNothing };
112 
114  QgsMapCanvas( QWidget * parent = 0, const char *name = 0 );
115 
117  ~QgsMapCanvas();
118 
119  void setLayerSet( QList<QgsMapCanvasLayer>& layers );
120 
121  void setCurrentLayer( QgsMapLayer* layer );
122 
123  // ### QGIS 3: make QgsMapCanvas independent from overview
124  void updateOverview();
125 
126  // ### QGIS 3: make QgsMapCanvas independent from overview
127  void enableOverviewMode( QgsMapOverviewCanvas* overview );
128 
131  const QgsMapSettings& mapSettings() const;
132 
135  void setCrsTransformEnabled( bool enabled );
136 
139  void setDestinationCrs( const QgsCoordinateReferenceSystem& crs );
140 
143  const QgsLabelingResults* labelingResults() const;
144 
147  void setCachingEnabled( bool enabled );
148 
151  bool isCachingEnabled() const;
152 
155  void clearCache();
156 
159  void setParallelRenderingEnabled( bool enabled );
160 
163  bool isParallelRenderingEnabled() const;
164 
167  void setMapUpdateInterval( int timeMiliseconds );
168 
171  int mapUpdateInterval() const;
172 
174  QgsMapCanvasMap* map();
175 
177  Q_DECL_DEPRECATED QgsMapRenderer* mapRenderer();
178 
181  Q_DECL_DEPRECATED QPaintDevice &canvasPaintDevice();
182 
184  double scale();
185 
188  Q_DECL_DEPRECATED void clear();
189 
191  double mapUnitsPerPixel() const;
192 
194  QgsRectangle extent() const;
196  QgsRectangle fullExtent() const;
197 
199  void setExtent( const QgsRectangle &r );
200 
202  void zoomToFullExtent();
203 
205  void zoomToPreviousExtent();
206 
208  void zoomToNextExtent();
209 
210  // ! Clears the list of extents and sets current extent as first item
211  void clearExtentHistory();
212 
215  void zoomToSelected( QgsVectorLayer* layer = NULL );
216 
219  void panToSelected( QgsVectorLayer* layer = NULL );
220 
222  void setMapTool( QgsMapTool* mapTool );
223 
230  void unsetMapTool( QgsMapTool* mapTool );
231 
233  QgsMapTool* mapTool();
234 
236  virtual void setCanvasColor( const QColor & _newVal );
238  virtual QColor canvasColor() const;
239 
241  void setSelectionColor( const QColor& color );
243 
245  void updateScale();
246 
248  Q_DECL_DEPRECATED void updateFullExtent() {}
250 
252  QgsMapLayer *layer( int index );
253 
255  int layerCount() const;
256 
258  QList<QgsMapLayer*> layers() const;
259 
265  void freeze( bool frz = true );
266 
268  bool isFrozen();
269 
272  Q_DECL_DEPRECATED void setDirty( bool _dirty );
273 
276  Q_DECL_DEPRECATED bool isDirty() const;
277 
279  void setMapUnits( QGis::UnitType mapUnits );
281 
282  QGis::UnitType mapUnits() const;
283 
285  const QgsMapToPixel* getCoordinateTransform();
286 
288  bool isDrawing();
289 
291  QgsMapLayer* currentLayer();
292 
294  void setWheelAction( WheelAction action, double factor = 2 );
295 
297  void zoomIn( );
298 
300  void zoomOut( );
301 
303  // added in 1.5
304  void zoomScale( double scale );
305 
307  void zoomByFactor( double scaleFactor );
308 
310  void zoomWithCenter( int x, int y, bool zoomIn );
311 
313  void enableAntiAliasing( bool theFlag );
314 
316  bool antiAliasingEnabled() const { return mSettings.testFlag( QgsMapSettings::Antialiasing ); }
317 
320  Q_DECL_DEPRECATED void useImageToRender( bool theFlag );
321 
322  // following 2 methods should be moved elsewhere or changed to private
323  // currently used by pan map tool
325  void panActionEnd( QPoint releasePoint );
326 
328  void panAction( QMouseEvent * event );
329 
331  QPoint mouseLastXY();
332 
333  public slots:
334 
336  void refresh();
337 
339  void selectionChangedSlot();
340 
342  void saveAsImage( QString theFileName, QPixmap * QPixmap = 0, QString = "PNG" );
343 
345  void layerStateChange();
346 
348  void setRenderFlag( bool theFlag );
350  bool renderFlag() {return mRenderFlag;};
351 
353  bool hasCrsTransformEnabled();
354 
356  Q_DECL_DEPRECATED void updateMap();
357 
360  void stopRendering();
361 
363  Q_DECL_DEPRECATED void showError( QgsMapLayer * mapLayer );
364 
366  void readProject( const QDomDocument & );
367 
369  void writeProject( QDomDocument & );
370 
372  void getDatumTransformInfo( const QgsMapLayer* ml, const QString& srcAuthId, const QString& destAuthId );
373 
374  private slots:
376  void mapToolDestroyed();
377 
379  void rendererJobFinished();
380 
381  void mapUpdateTimeout();
382 
383  void refreshMap();
384 
385  signals:
387  Q_DECL_DEPRECATED void setProgress( int, int );
389 
392  void xyCoordinates( const QgsPoint &p );
393 
395  void scaleChanged( double );
396 
398  void extentsChanged();
399 
408  void renderComplete( QPainter * );
412 
415  Q_DECL_DEPRECATED void mapCanvasRefreshed();
417 
420  Q_DECL_DEPRECATED void renderStarting();
422 
424  void layersChanged();
425 
427  void keyPressed( QKeyEvent * e );
428 
430  void keyReleased( QKeyEvent * e );
431 
433  void mapToolSet( QgsMapTool *tool );
434 
438  void mapToolSet( QgsMapTool *newTool, QgsMapTool* oldTool );
439 
440  // ### QGIS 3: remove the signal
442  void selectionChanged( QgsMapLayer * layer );
443 
446  void zoomLastStatusChanged( bool );
447 
450  void zoomNextStatusChanged( bool );
451 
454  void hasCrsTransformEnabledChanged( bool flag );
455 
458  void destinationCrsChanged();
459 
462  void mapUnitsChanged();
463 
464  protected:
465 #ifdef HAVE_TOUCH
466  bool event( QEvent * e );
468 #endif
469 
471  void keyPressEvent( QKeyEvent * e );
472 
474  void keyReleaseEvent( QKeyEvent * e );
475 
477  void mouseDoubleClickEvent( QMouseEvent * e );
478 
480  void mouseMoveEvent( QMouseEvent * e );
481 
483  void mousePressEvent( QMouseEvent * e );
484 
486  void mouseReleaseEvent( QMouseEvent * e );
487 
489  void wheelEvent( QWheelEvent * e );
490 
492  void resizeEvent( QResizeEvent * e );
493 
495  void paintEvent( QPaintEvent * e );
496 
498  void dragEnterEvent( QDragEnterEvent * e );
499 
501  void moveCanvasContents( bool reset = false );
502 
504  void updateCanvasItemPositions();
505 
508 
510  std::auto_ptr<CanvasProperties> mCanvasProperties;
511 
515  void connectNotify( const char * signal );
516 
517  private:
519 
525  QgsMapCanvas( QgsMapCanvas const & );
526 
529 
532 
535 
538 
540  bool mFrozen;
541 
544 
547 
550 
552  QGraphicsScene* mScene;
553 
556 
559 
561  QList <QgsRectangle> mLastExtent;
563 
566 
569 
572 
575 
578 
581 
584 
587 
590 
591 
592  QTimer *mResizeTimer;
593 }; // class QgsMapCanvas
594 
595 
596 
597 
605 class QgsMapCanvasRendererSync : public QObject
606 {
607  Q_OBJECT
608  public:
610 
611  protected slots:
612  void onExtentC2R();
613  void onExtentR2C();
614 
615  void onMapUnitsC2R();
616  void onMapUnitsR2C();
617 
618  void onCrsTransformC2R();
619  void onCrsTransformR2C();
620 
621  void onDestCrsC2R();
622  void onDestCrsR2C();
623 
624  void onLayersC2R();
625 
626  protected:
629 };
630 
631 
632 #endif
QgsMapCanvasMap * mMap
owns pixmap with rendered map and controls rendering
Definition: qgsmapcanvas.h:534
QgsMapSettings mSettings
encompases all map settings necessary for map rendering
Definition: qgsmapcanvas.h:528
bool mDrawRenderingStats
Whether to add rendering stats to the rendered image.
Definition: qgsmapcanvas.h:586
static unsigned index
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for all map layer types.
Definition: qgsmaplayer.h:47
void setInOverview(bool isInOverview)
Definition: qgsmapcanvas.h:82
QGraphicsScene * mScene
graphics scene manages canvas items
Definition: qgsmapcanvas.h:552
QTimer * mResizeTimer
Definition: qgsmapcanvas.h:592
bool mUseParallelRendering
Whether layers are rendered sequentially or in parallel.
Definition: qgsmapcanvas.h:583
A widget that displays an overview map.
QgsMapRenderer * mMapRenderer
all map rendering is done in this class
Definition: qgsmapcanvas.h:531
bool mRefreshScheduled
Flag that allows squashing multiple refresh() calls into just one delayed rendering job...
Definition: qgsmapcanvas.h:543
A class that stores visibility and presence in overview flags together with pointer to the layer...
Definition: qgsmapcanvas.h:75
WheelAction mWheelAction
Mouse wheel action.
Definition: qgsmapcanvas.h:568
bool isVisible() const
Definition: qgsmapcanvas.h:84
QgsMapOverviewCanvas * mMapOverview
map overview widget - it's controlled by QgsMapCanvas
Definition: qgsmapcanvas.h:537
QgsMapLayer * mLayer
Definition: qgsmapcanvas.h:91
A non GUI class for rendering a map layer set onto a QPainter.
bool antiAliasingEnabled() const
true if antialising is enabled
Definition: qgsmapcanvas.h:316
QgsMapTool * mMapTool
pointer to current map tool
Definition: qgsmapcanvas.h:555
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:105
void setVisible(bool visible)
Definition: qgsmapcanvas.h:81
bool renderFlag()
State of render suppression flag.
Definition: qgsmapcanvas.h:350
QgsMapLayer * mCurrentLayer
current layer in legend
Definition: qgsmapcanvas.h:549
QgsMapRenderer * mRenderer
Definition: qgsmapcanvas.h:628
Perform transforms between map coordinates and device coordinates.
Definition: qgsmaptopixel.h:33
A rectangular graphics item representing the map on the canvas.
int mLastExtentIndex
Definition: qgsmapcanvas.h:562
QgsMapTool * mLastNonZoomMapTool
previous tool if current is for zooming/panning
Definition: qgsmapcanvas.h:558
QgsMapCanvas * mCanvas
Definition: qgsmapcanvas.h:627
A class for highlight features on the map.
Definition: qgshighlight.h:36
const QgsMapLayer * layer() const
Definition: qgsmapcanvas.h:88
bool mInOverview
Flag whether layer is shown in overview.
Definition: qgsmapcanvas.h:97
A class to represent a point geometry.
Definition: qgspoint.h:63
QgsMapRendererQImageJob * mJob
Job that takes care of map rendering in background.
Definition: qgsmapcanvas.h:574
bool mVisible
Flag whether layer is visible.
Definition: qgsmapcanvas.h:94
QgsLabelingResults * mLabelingResults
Labeling results from the recently rendered map.
Definition: qgsmapcanvas.h:580
Abstract base class for all map tools.
Definition: qgsmaptool.h:48
QTimer mMapUpdateTimer
Timer that periodically fires while map rendering is in progress to update the visible map...
Definition: qgsmapcanvas.h:571
double mWheelZoomFactor
Scale factor multiple for default zoom in/out.
Definition: qgsmapcanvas.h:565
bool mFrozen
Flag indicating if the map canvas is frozen.
Definition: qgsmapcanvas.h:540
bool isInOverview() const
Definition: qgsmapcanvas.h:85
QgsMapRendererCache * mCache
Optionally use cache with rendered map layers for the current map settings.
Definition: qgsmapcanvas.h:589
Intermediate base class adding functionality that allows client to query the rendered image...
bool mRenderFlag
determines whether user has requested to suppress rendering
Definition: qgsmapcanvas.h:546
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:78
UnitType
Map units that qgis supports.
Definition: qgis.h:229
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:605
Represents a vector layer which manages a vector based data sets.
QList< QgsRectangle > mLastExtent
recently used extent
Definition: qgsmapcanvas.h:561
QgsMapLayer * layer()
Definition: qgsmapcanvas.h:87
std::auto_ptr< CanvasProperties > mCanvasProperties
Handle pattern for implementation object.
Definition: qgsmapcanvas.h:507
bool mJobCancelled
Flag determining whether the active job has been cancelled.
Definition: qgsmapcanvas.h:577