QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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
23#include "qgis_gui.h"
24#include "qgis_sip.h"
25
26#include <QGraphicsView>
27#include <QPointer>
28
30class QgsPlotTool;
32class QgsPoint;
33class QgsPointXY;
37
38class QMenu;
39
40
41#ifdef SIP_RUN
42//%ModuleHeaderCode
43#include "qgsplotcanvas.h"
45//%End
46#endif
47
54class GUI_EXPORT QgsPlotCanvas : public QGraphicsView
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;
65#endif
66
67 Q_OBJECT
68
69 public:
73 QgsPlotCanvas( QWidget *parent SIP_TRANSFERTHIS = nullptr );
74
75 ~QgsPlotCanvas() override;
76
81 virtual void cancelJobs() SIP_SKIP;
82
86 void setTool( QgsPlotTool *tool );
87
96 void unsetTool( QgsPlotTool *tool );
97
101 QgsPlotTool *tool();
102
108 virtual QgsCoordinateReferenceSystem crs() const;
109
115 virtual QgsPoint toMapCoordinates( const QgsPointXY &point ) const;
116
122 virtual QgsPointXY toCanvasCoordinates( const QgsPoint &point ) const;
123
129 virtual void panContentsBy( double dx, double dy );
130
136 virtual void centerPlotOn( double x, double y );
137
143 virtual void scalePlot( double factor );
144
150 virtual void zoomToRect( const QRectF &rect );
151
159 virtual QgsPointXY snapToPlot( QPoint point );
160
161 public slots:
162
166 virtual void refresh();
167
168 signals:
169
173 void toolChanged( QgsPlotTool *newTool );
174
179
185
191
192 protected:
193 bool event( QEvent *e ) override;
194 void keyPressEvent( QKeyEvent *e ) override;
195 void keyReleaseEvent( QKeyEvent *e ) override;
196 void mouseDoubleClickEvent( QMouseEvent *e ) override;
197 void mouseMoveEvent( QMouseEvent *e ) override;
198 void mousePressEvent( QMouseEvent *e ) override;
199 void mouseReleaseEvent( QMouseEvent *e ) override;
200 void wheelEvent( QWheelEvent *e ) override;
201 void resizeEvent( QResizeEvent *e ) override;
202 bool viewportEvent( QEvent *event ) override;
203
209 virtual void wheelZoom( QWheelEvent *event );
210
211 private:
213 QGraphicsScene *mScene = nullptr;
214
216 QPointer<QgsPlotTool> mTool;
217
218 QgsPlotToolTemporaryKeyPan *mSpacePanTool = nullptr;
219 QgsPlotToolTemporaryMousePan *mMidMouseButtonPanTool = nullptr;
220 QgsPlotToolTemporaryKeyZoom *mSpaceZoomTool = nullptr;
221
222 void showContextMenu( QgsPlotMouseEvent *event );
223};
224
225#endif // QGSPLOTCANVAS_H
Represents a coordinate reference system (CRS).
bool event(QEvent *e) override
void setTool(QgsPlotTool *tool)
Sets the interactive tool currently being used on the canvas.
virtual void cancelJobs()
Cancel any rendering job, in a blocking way.
QgsPlotCanvas(QWidget *parent=nullptr)
Constructor for QgsPlotCanvas, with the specified parent widget.
virtual void refresh()
Updates and redraws the plot.
virtual void zoomToRect(const QRectF &rect)
Zooms the plot to the specified rect in canvas units.
void keyPressEvent(QKeyEvent *e) override
void plotAreaChanged()
Emitted whenever the visible area of the plot is changed.
virtual void panContentsBy(double dx, double dy)
Pans the plot contents by dx, dy in canvas units.
void mousePressEvent(QMouseEvent *e) override
void toolChanged(QgsPlotTool *newTool)
Emitted when the plot tool is changed.
virtual QgsPointXY toCanvasCoordinates(const QgsPoint &point) const
Converts a point in map coordinates to the associated canvas point.
void keyReleaseEvent(QKeyEvent *e) override
QgsPlotTool * tool()
Returns the currently active tool.
void mouseDoubleClickEvent(QMouseEvent *e) override
void contextMenuAboutToShow(QMenu *menu, QgsPlotMouseEvent *event)
Emitted before the canvas context menu will be shown.
void mouseReleaseEvent(QMouseEvent *e) override
void unsetTool(QgsPlotTool *tool)
Unset the current tool.
void wheelEvent(QWheelEvent *e) override
void mouseMoveEvent(QMouseEvent *e) override
void resizeEvent(QResizeEvent *e) override
void willBeDeleted()
Emitted in the destructor when the canvas is about to be deleted, but is still in a perfectly valid s...
virtual void scalePlot(double factor)
Scales the plot by a specified scale factor.
virtual QgsCoordinateReferenceSystem crs() const
Returns the coordinate reference system (CRS) for map coordinates used by the canvas.
virtual void wheelZoom(QWheelEvent *event)
Zoom plot from a mouse wheel event.
virtual QgsPoint toMapCoordinates(const QgsPointXY &point) const
Converts a point on the canvas to the associated map coordinate.
bool viewportEvent(QEvent *event) override
virtual QgsPointXY snapToPlot(QPoint point)
Snap a canvas point to the plot.
virtual void centerPlotOn(double x, double y)
Centers the plot on the plot point corresponding to x, y in canvas units.
A mouse event which is the result of a user interaction with a QgsPlotCanvas.
Plot tool for temporarily panning a plot while a key is depressed.
Plot tool for temporarily zooming a plot while a key is depressed.
Plot tool for temporarily panning a plot while a mouse button is depressed.
Abstract base class for all interactive plot tools.
Definition qgsplottool.h:59
Represents a 2D point.
Definition qgspointxy.h:60
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:199
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_END
Definition qgis_sip.h:216