QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
qgsplottool.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsplottool.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 QGSPLOTTOOL_H
19#define QGSPLOTTOOL_H
20
21#include "qgsconfig.h"
22
23#include "qgis.h"
24#include "qgis_gui.h"
25#include "qgis_sip.h"
26
27#include <QCursor>
28#include <QPointer>
29
30class QgsPlotCanvas;
32class QgsPoint;
33class QgsPointXY;
34
35class QWheelEvent;
36class QKeyEvent;
37class QGestureEvent;
38class QHelpEvent;
39class QMenu;
40class QAction;
41
42#ifdef SIP_RUN
43//%ModuleHeaderCode
44#include "qgsplottool.h"
45#include "qgsplottoolpan.h"
46#include "qgsplottoolzoom.h"
47//%End
48#endif
49
50
58class GUI_EXPORT QgsPlotTool : public QObject
59{
60#ifdef SIP_RUN
62 if ( qobject_cast<QgsPlotToolPan *>( sipCpp ) != nullptr )
63 sipType = sipType_QgsPlotToolPan;
64 else if ( qobject_cast<QgsPlotToolZoom *>( sipCpp ) != nullptr )
65 sipType = sipType_QgsPlotToolZoom;
66 else if ( qobject_cast<QgsPlotTool *>( sipCpp ) != nullptr )
67 sipType = sipType_QgsPlotTool;
68 else
69 sipType = nullptr;
71#endif
72
73 Q_OBJECT
74
75 public:
76 ~QgsPlotTool() override;
77
81 virtual Qgis::PlotToolFlags flags() const;
82
86 QString toolName() const { return mToolName; }
87
95 virtual void plotMoveEvent( QgsPlotMouseEvent *event );
96
104 virtual void plotDoubleClickEvent( QgsPlotMouseEvent *event );
105
113 virtual void plotPressEvent( QgsPlotMouseEvent *event );
114
122 virtual void plotReleaseEvent( QgsPlotMouseEvent *event );
123
131 virtual void wheelEvent( QWheelEvent *event );
132
140 virtual void keyPressEvent( QKeyEvent *event );
141
149 virtual void keyReleaseEvent( QKeyEvent *event );
150
156 virtual bool gestureEvent( QGestureEvent *event );
157
163 virtual bool canvasToolTipEvent( QHelpEvent *event );
164
168 bool isActive() const;
169
173 virtual void activate();
174
178 virtual void deactivate();
179
183 QgsPlotCanvas *canvas() const;
184
193 void setAction( QAction *action );
194
200 QAction *action();
201
205 void setCursor( const QCursor &cursor );
206
223 virtual bool populateContextMenuWithEvent( QMenu *menu, QgsPlotMouseEvent *event );
224
225 signals:
226
228 void activated();
229
232
233 protected:
235 QgsPlotTool( QgsPlotCanvas *canvas SIP_TRANSFERTHIS, const QString &name );
236
242 QgsPoint toMapCoordinates( const QgsPointXY &point ) const;
243
249 QgsPointXY toCanvasCoordinates( const QgsPoint &point ) const;
250
257 bool isClickAndDrag( QPoint startViewPoint, QPoint endViewPoint ) const;
258
262 static QPointF constrainPointToRect( QPointF point, const QRectF &rect );
263
266
268 QString mToolName;
269
271 QPointer<QAction> mAction;
272
274 QCursor mCursor = Qt::ArrowCursor;
275};
276
277#endif // QGSPLOTTOOL_H
QFlags< PlotToolFlag > PlotToolFlags
Definition qgis.h:4112
Plot canvas is a class for displaying interactive 2d charts and plots.
A mouse event which is the result of a user interaction with a QgsPlotCanvas.
QgsPointXY toCanvasCoordinates(const QgsPoint &point) const
Converts a point in map coordinates to the associated canvas point.
QCursor mCursor
Cursor used by tool.
QgsPlotCanvas * canvas() const
Returns the tool's plot canvas.
QgsPlotCanvas * mCanvas
The pointer to the canvas.
QgsPlotTool(QgsPlotCanvas *canvas, const QString &name)
Constructor takes a plot canvas as a parameter.
void activated()
Emitted when the tool is activated.
bool isClickAndDrag(QPoint startViewPoint, QPoint endViewPoint) const
Returns true if a mouse press/release operation which started at startViewPoint and ended at endViewP...
QgsPoint toMapCoordinates(const QgsPointXY &point) const
Converts a point on the canvas to the associated map coordinate.
void deactivated()
Emitted when the tool is deactivated.
QPointer< QAction > mAction
Optional action associated with tool.
QString mToolName
Translated name of the map tool.
static QPointF constrainPointToRect(QPointF point, const QRectF &rect)
Constrains a point to force it to fall within the specified rectangle.
virtual Qgis::PlotToolFlags flags() const
Returns the flags for the plot tool.
QString toolName() const
Returns a user-visible, translated name for the tool.
Definition qgsplottool.h:86
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_END
Definition qgis_sip.h:216