QGIS API Documentation 3.41.0-Master (cea29feecf2)
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#include "qgis.h"
23#include "qgis_gui.h"
24#include "qgis_sip.h"
25
26#include <QPointer>
27#include <QCursor>
28
29class QgsPlotCanvas;
31class QgsPoint;
32class QgsPointXY;
33
34class QWheelEvent;
35class QKeyEvent;
36class QGestureEvent;
37class QHelpEvent;
38class QMenu;
39class 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
57class GUI_EXPORT QgsPlotTool : public QObject
58{
59#ifdef SIP_RUN
61 if ( qobject_cast<QgsPlotToolPan *>( sipCpp ) != nullptr )
62 sipType = sipType_QgsPlotToolPan;
63 else if ( qobject_cast<QgsPlotToolZoom *>( sipCpp ) != nullptr )
64 sipType = sipType_QgsPlotToolZoom;
65 else if ( qobject_cast<QgsPlotTool *>( sipCpp ) != nullptr )
66 sipType = sipType_QgsPlotTool;
67 else
68 sipType = nullptr;
70#endif
71
72 Q_OBJECT
73
74 public:
75 ~QgsPlotTool() override;
76
80 virtual Qgis::PlotToolFlags flags() const;
81
85 QString toolName() const { return mToolName; }
86
94 virtual void plotMoveEvent( QgsPlotMouseEvent *event );
95
103 virtual void plotDoubleClickEvent( QgsPlotMouseEvent *event );
104
112 virtual void plotPressEvent( QgsPlotMouseEvent *event );
113
121 virtual void plotReleaseEvent( QgsPlotMouseEvent *event );
122
130 virtual void wheelEvent( QWheelEvent *event );
131
139 virtual void keyPressEvent( QKeyEvent *event );
140
148 virtual void keyReleaseEvent( QKeyEvent *event );
149
155 virtual bool gestureEvent( QGestureEvent *event );
156
162 virtual bool canvasToolTipEvent( QHelpEvent *event );
163
167 bool isActive() const;
168
172 virtual void activate();
173
177 virtual void deactivate();
178
182 QgsPlotCanvas *canvas() const;
183
192 void setAction( QAction *action );
193
199 QAction *action();
200
204 void setCursor( const QCursor &cursor );
205
222 virtual bool populateContextMenuWithEvent( QMenu *menu, QgsPlotMouseEvent *event );
223
224 signals:
225
227 void activated();
228
231
232 protected:
234 QgsPlotTool( QgsPlotCanvas *canvas SIP_TRANSFERTHIS, const QString &name );
235
241 QgsPoint toMapCoordinates( const QgsPointXY &point ) const;
242
248 QgsPointXY toCanvasCoordinates( const QgsPoint &point ) const;
249
256 bool isClickAndDrag( QPoint startViewPoint, QPoint endViewPoint ) const;
257
261 static QPointF constrainPointToRect( QPointF point, const QRectF &rect );
262
264 QgsPlotCanvas *mCanvas = nullptr;
265
267 QString mToolName;
268
270 QPointer<QAction> mAction;
271
273 QCursor mCursor = Qt::ArrowCursor;
274};
275
276#endif // QGSPLOTTOOL_H
QFlags< PlotToolFlag > PlotToolFlags
Definition qgis.h:3874
Plot canvas is a class for displaying interactive 2d charts and plots.
A QgsPlotMouseEvent is the result of a user interaction with the mouse on a QgsPlotCanvas.
Abstract base class for all interactive plot tools.
Definition qgsplottool.h:58
void activated()
Emitted when the tool is activated.
void deactivated()
Emitted when the tool is deactivated.
QPointer< QAction > mAction
Optional action associated with tool.
QString mToolName
Translated name of the map tool.
QString toolName() const
Returns a user-visible, translated name for the tool.
Definition qgsplottool.h:85
A class to represent 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:191
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53
#define SIP_END
Definition qgis_sip.h:208