QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
25 QgsPlotMouseEvent::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 
56 void QgsPlotMouseEvent::snapPoint()
57 {
58  mHasCachedSnapResult = true;
59 
60  const QgsPointXY result = mCanvas->snapToPlot( pos() );
61  mIsSnapped = !result.isEmpty();
62  mSnappedPoint = !mIsSnapped ? pos() : result;
63 }
qgsplotmouseevent.h
QgsPlotMouseEvent::isSnapped
bool isSnapped()
Returns true if the point can be snapped to the plot.
Definition: qgsplotmouseevent.cpp:47
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
qgsplotcanvas.h
QgsPlotMouseEvent::QgsPlotMouseEvent
QgsPlotMouseEvent(QgsPlotCanvas *canvas, QMouseEvent *event)
Creates a new QgsPlotMouseEvent.
Definition: qgsplotmouseevent.cpp:20
QgsPointXY::isEmpty
bool isEmpty() const SIP_HOLDGIL
Returns true if the geometry is empty.
Definition: qgspointxy.h:249
QgsPlotCanvas
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition: qgsplotcanvas.h:53
QgsPlotMouseEvent::snappedPoint
QgsPointXY snappedPoint()
Returns the point snapped to the plot, if possible.
Definition: qgsplotmouseevent.cpp:38
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:58
QgsPlotCanvas::snapToPlot
virtual QgsPointXY snapToPlot(QPoint point)
Snap a canvas point to the plot.
Definition: qgsplotcanvas.cpp:297
QgsPlotMouseEvent
A QgsPlotMouseEvent is the result of a user interaction with the mouse on a QgsPlotCanvas.
Definition: qgsplotmouseevent.h:39
QgsPlotMouseEvent::mapPoint
QgsPoint mapPoint() const
Returns the point in map coordinates corresponding to the event.
Definition: qgsplotmouseevent.cpp:33