QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
gui
plot
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
19
#include "
qgsplotcanvas.h
"
20
21
QgsPlotMouseEvent::QgsPlotMouseEvent
(
QgsPlotCanvas
*canvas, QMouseEvent *event )
22
:
QgsPlotMouseEvent
( canvas, event->type(), event->pos(), event->button(), event->buttons(), event->modifiers() )
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
QgsPoint
QgsPlotMouseEvent::mapPoint
()
const
32
{
33
return
mMapPoint;
34
}
35
36
QgsPointXY
QgsPlotMouseEvent::snappedPoint
()
37
{
38
if
( mHasCachedSnapResult )
39
return
mSnappedPoint;
40
41
snapPoint();
42
return
mSnappedPoint;
43
}
44
45
bool
QgsPlotMouseEvent::isSnapped
()
46
{
47
if
( mHasCachedSnapResult )
48
return
mIsSnapped;
49
50
snapPoint();
51
return
mIsSnapped;
52
}
53
54
void
QgsPlotMouseEvent::snapPoint()
55
{
56
mHasCachedSnapResult =
true
;
57
58
const
QgsPointXY
result = mCanvas->
snapToPlot
( pos() );
59
mIsSnapped = !result.
isEmpty
();
60
mSnappedPoint = !mIsSnapped ? pos() : result;
61
}
QgsPlotCanvas
Plot canvas is a class for displaying interactive 2d charts and plots.
Definition
qgsplotcanvas.h:55
QgsPlotCanvas::snapToPlot
virtual QgsPointXY snapToPlot(QPoint point)
Snap a canvas point to the plot.
Definition
qgsplotcanvas.cpp:291
QgsPlotMouseEvent::snappedPoint
QgsPointXY snappedPoint()
Returns the point snapped to the plot, if possible.
Definition
qgsplotmouseevent.cpp:36
QgsPlotMouseEvent::mapPoint
QgsPoint mapPoint() const
Returns the point in map coordinates corresponding to the event.
Definition
qgsplotmouseevent.cpp:31
QgsPlotMouseEvent::isSnapped
bool isSnapped()
Returns true if the point can be snapped to the plot.
Definition
qgsplotmouseevent.cpp:45
QgsPlotMouseEvent::QgsPlotMouseEvent
QgsPlotMouseEvent(QgsPlotCanvas *canvas, QMouseEvent *event)
Creates a new QgsPlotMouseEvent.
Definition
qgsplotmouseevent.cpp:21
QgsPointXY
Represents a 2D point.
Definition
qgspointxy.h:62
QgsPointXY::isEmpty
bool isEmpty() const
Returns true if the geometry is empty.
Definition
qgspointxy.h:245
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition
qgspoint.h:53
qgsplotcanvas.h
qgsplotmouseevent.h
Generated on
for QGIS API Documentation by
1.17.0