QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsplotmouseevent.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsplotmouseevent.cpp
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#include "qgsplotmouseevent.h"
18#include "qgsplotcanvas.h"
19
21 : QgsPlotMouseEvent( canvas, event->type(), event->pos(), event->button(), event->buttons(), event->modifiers() )
22{
23}
24
25QgsPlotMouseEvent::QgsPlotMouseEvent( QgsPlotCanvas *canvas, QEvent::Type type, QPoint pos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers )
26 : QMouseEvent( type, pos, button, buttons, modifiers )
27 , mCanvas( canvas )
28 , mMapPoint( mCanvas->toMapCoordinates( pos ) )
29{
30
31}
32
34{
35 return mMapPoint;
36}
37
39{
40 if ( mHasCachedSnapResult )
41 return mSnappedPoint;
42
43 snapPoint();
44 return mSnappedPoint;
45}
46
48{
49 if ( mHasCachedSnapResult )
50 return mIsSnapped;
51
52 snapPoint();
53 return mIsSnapped;
54}
55
56void QgsPlotMouseEvent::snapPoint()
57{
58 mHasCachedSnapResult = true;
59
60 const QgsPointXY result = mCanvas->snapToPlot( pos() );
61 mIsSnapped = !result.isEmpty();
62 mSnappedPoint = !mIsSnapped ? pos() : result;
63}
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition: qgsplotcanvas.h:54
virtual QgsPointXY snapToPlot(QPoint point)
Snap a canvas point to the plot.
A QgsPlotMouseEvent is the result of a user interaction with the mouse on a QgsPlotCanvas.
QgsPointXY snappedPoint()
Returns the point snapped to the plot, if possible.
QgsPoint mapPoint() const
Returns the point in map coordinates corresponding to the event.
bool isSnapped()
Returns true if the point can be snapped to the plot.
QgsPlotMouseEvent(QgsPlotCanvas *canvas, QMouseEvent *event)
Creates a new QgsPlotMouseEvent.
A class to represent a 2D point.
Definition: qgspointxy.h:59
bool isEmpty() const SIP_HOLDGIL
Returns true if the geometry is empty.
Definition: qgspointxy.h:249
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49