QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsplotcanvas.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsplotcanvas.h
3  ---------------
4  begin : March 2022
5  copyright : (C) 2022 by Nyall Dawson
6  email : nyall dot dawson at gmail dot 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 QGSPLOTCANVAS_H
19 #define QGSPLOTCANVAS_H
20 
21 #include "qgsconfig.h"
22 #include "qgis_sip.h"
23 #include "qgis_gui.h"
24 
25 #include <QGraphicsView>
26 #include <QPointer>
27 
28 class QgsPlotMouseEvent;
29 class QgsPlotTool;
31 class QgsPoint;
32 class QgsPointXY;
36 
37 class QMenu;
38 
39 
40 #ifdef SIP_RUN
41 % ModuleHeaderCode
42 #include "qgsplotcanvas.h"
44 % End
45 #endif
46 
53 class GUI_EXPORT QgsPlotCanvas : public QGraphicsView
54 {
55 
56 #ifdef SIP_RUN
58  if ( qobject_cast<QgsElevationProfileCanvas *>( sipCpp ) != nullptr )
59  sipType = sipType_QgsElevationProfileCanvas;
60  else if ( qobject_cast<QgsPlotCanvas *>( sipCpp ) != nullptr )
61  sipType = sipType_QgsPlotCanvas;
62  else
63  sipType = nullptr;
64  SIP_END
65 #endif
66 
67  Q_OBJECT
68 
69  public:
70 
74  QgsPlotCanvas( QWidget *parent SIP_TRANSFERTHIS = nullptr );
75 
76  ~QgsPlotCanvas() override;
77 
82  virtual void cancelJobs() SIP_SKIP;
83 
87  void setTool( QgsPlotTool *tool );
88 
97  void unsetTool( QgsPlotTool *tool );
98 
102  QgsPlotTool *tool();
103 
109  virtual QgsCoordinateReferenceSystem crs() const;
110 
116  virtual QgsPoint toMapCoordinates( const QgsPointXY &point ) const;
117 
123  virtual QgsPointXY toCanvasCoordinates( const QgsPoint &point ) const;
124 
130  virtual void panContentsBy( double dx, double dy );
131 
137  virtual void centerPlotOn( double x, double y );
138 
144  virtual void scalePlot( double factor );
145 
151  virtual void zoomToRect( const QRectF &rect );
152 
160  virtual QgsPointXY snapToPlot( QPoint point );
161 
162  public slots:
163 
167  virtual void refresh();
168 
169  signals:
170 
174  void toolChanged( QgsPlotTool *newTool );
175 
179  void plotAreaChanged();
180 
185  void contextMenuAboutToShow( QMenu *menu, QgsPlotMouseEvent *event );
186 
191  void willBeDeleted();
192 
193  protected:
194 
195  bool event( QEvent *e ) override;
196  void keyPressEvent( QKeyEvent *e ) override;
197  void keyReleaseEvent( QKeyEvent *e ) override;
198  void mouseDoubleClickEvent( QMouseEvent *e ) override;
199  void mouseMoveEvent( QMouseEvent *e ) override;
200  void mousePressEvent( QMouseEvent *e ) override;
201  void mouseReleaseEvent( QMouseEvent *e ) override;
202  void wheelEvent( QWheelEvent *e ) override;
203  void resizeEvent( QResizeEvent *e ) override;
204  bool viewportEvent( QEvent *event ) override;
205 
211  virtual void wheelZoom( QWheelEvent *event );
212 
213  private:
214 
216  QGraphicsScene *mScene = nullptr;
217 
219  QPointer< QgsPlotTool > mTool;
220 
221  QgsPlotToolTemporaryKeyPan *mSpacePanTool = nullptr;
222  QgsPlotToolTemporaryMousePan *mMidMouseButtonPanTool = nullptr;
223  QgsPlotToolTemporaryKeyZoom *mSpaceZoomTool = nullptr;
224 
225  void showContextMenu( QgsPlotMouseEvent *event );
226 
227 };
228 
229 #endif // QGSPLOTCANVAS_H
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
qgsplotcanvas.h
QgsPlotToolTemporaryKeyZoom
Plot tool for temporarily zooming a plot while a key is depressed.
Definition: qgsplottransienttools.h:88
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
QgsPlotToolTemporaryKeyPan
Plot tool for temporarily panning a plot while a key is depressed.
Definition: qgsplottransienttools.h:32
qgis_sip.h
QgsPlotTool
Abstract base class for all interactive plot tools.
Definition: qgsplottool.h:57
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsPlotCanvas
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition: qgsplotcanvas.h:53
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
qgselevationprofilecanvas.h
QgsPlotMouseEvent
A QgsPlotMouseEvent is the result of a user interaction with the mouse on a QgsPlotCanvas.
Definition: qgsplotmouseevent.h:39
QgsPlotToolTemporaryMousePan
Plot tool for temporarily panning a plot while a mouse button is depressed.
Definition: qgsplottransienttools.h:60
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53