QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgis.h"
23 #include "qgis_gui.h"
24 #include "qgis_sip.h"
25 
26 #include <QPointer>
27 #include <QCursor>
28 
29 class QgsPlotCanvas;
30 class QgsPlotMouseEvent;
31 class QgsPoint;
32 class QgsPointXY;
33 
34 class QWheelEvent;
35 class QKeyEvent;
36 class QGestureEvent;
37 class QHelpEvent;
38 class QMenu;
39 class QAction;
40 
41 #ifdef SIP_RUN
42 % ModuleHeaderCode
43 #include "qgsplottool.h"
44 #include "qgsplottoolpan.h"
45 #include "qgsplottoolzoom.h"
46 % End
47 #endif
48 
49 
57 class GUI_EXPORT QgsPlotTool : public QObject
58 {
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;
70  SIP_END
71 #endif
72 
73  Q_OBJECT
74 
75  public:
76 
77  ~QgsPlotTool() override;
78 
82  virtual Qgis::PlotToolFlags flags() const;
83 
87  QString toolName() const { return mToolName; }
88 
96  virtual void plotMoveEvent( QgsPlotMouseEvent *event );
97 
105  virtual void plotDoubleClickEvent( QgsPlotMouseEvent *event );
106 
114  virtual void plotPressEvent( QgsPlotMouseEvent *event );
115 
123  virtual void plotReleaseEvent( QgsPlotMouseEvent *event );
124 
132  virtual void wheelEvent( QWheelEvent *event );
133 
141  virtual void keyPressEvent( QKeyEvent *event );
142 
150  virtual void keyReleaseEvent( QKeyEvent *event );
151 
157  virtual bool gestureEvent( QGestureEvent *event );
158 
164  virtual bool canvasToolTipEvent( QHelpEvent *event );
165 
169  bool isActive() const;
170 
174  virtual void activate();
175 
179  virtual void deactivate();
180 
184  QgsPlotCanvas *canvas() const;
185 
194  void setAction( QAction *action );
195 
201  QAction *action();
202 
206  void setCursor( const QCursor &cursor );
207 
224  virtual bool populateContextMenuWithEvent( QMenu *menu, QgsPlotMouseEvent *event );
225 
226  signals:
227 
229  void activated();
230 
232  void deactivated();
233 
234  protected:
235 
237  QgsPlotTool( QgsPlotCanvas *canvas SIP_TRANSFERTHIS, const QString &name );
238 
244  QgsPoint toMapCoordinates( const QgsPointXY &point ) const;
245 
251  QgsPointXY toCanvasCoordinates( const QgsPoint &point ) const;
252 
259  bool isClickAndDrag( QPoint startViewPoint, QPoint endViewPoint ) const;
260 
264  static QPointF constrainPointToRect( QPointF point, const QRectF &rect );
265 
267  QgsPlotCanvas *mCanvas = nullptr;
268 
270  QString mToolName;
271 
273  QPointer< QAction > mAction;
274 
276  QCursor mCursor = Qt::ArrowCursor;
277 };
278 
279 #endif // QGSPLOTTOOL_H
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
qgis.h
qgsplottoolpan.h
qgsplottoolzoom.h
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
QgsPlotTool::mToolName
QString mToolName
Translated name of the map tool.
Definition: qgsplottool.h:270
qgis_sip.h
QgsPlotTool
Abstract base class for all interactive plot tools.
Definition: qgsplottool.h:57
qgsplottool.h
QgsPlotCanvas
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition: qgsplotcanvas.h:53
QgsPlotTool::mAction
QPointer< QAction > mAction
Optional action associated with tool.
Definition: qgsplottool.h:273
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsPlotTool::toolName
QString toolName() const
Returns a user-visible, translated name for the tool.
Definition: qgsplottool.h:87
QgsPlotMouseEvent
A QgsPlotMouseEvent is the result of a user interaction with the mouse on a QgsPlotCanvas.
Definition: qgsplotmouseevent.h:39
SIP_END
#define SIP_END
Definition: qgis_sip.h:203
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53