QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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
33{
34 return mMapPoint;
35}
36
38{
39 if ( mHasCachedSnapResult )
40 return mSnappedPoint;
41
42 snapPoint();
43 return mSnappedPoint;
44}
45
47{
48 if ( mHasCachedSnapResult )
49 return mIsSnapped;
50
51 snapPoint();
52 return mIsSnapped;
53}
54
55void QgsPlotMouseEvent::snapPoint()
56{
57 mHasCachedSnapResult = true;
58
59 const QgsPointXY result = mCanvas->snapToPlot( pos() );
60 mIsSnapped = !result.isEmpty();
61 mSnappedPoint = !mIsSnapped ? pos() : result;
62}
Plot canvas is a class for displaying interactive 2d charts and plots.
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:60
bool isEmpty() const
Returns true if the geometry is empty.
Definition qgspointxy.h:242
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49