QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsmapmouseevent.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmapmouseevent.h - mouse event in map coordinates and ability to snap
3  ----------------------
4  begin : October 2014
5  copyright : (C) Denis Rouzaud
6  email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPMOUSEEVENT_H
17 #define QGSMAPMOUSEEVENT_H
18 
19 #include <QMouseEvent>
20 
21 #include "qgspointxy.h"
22 #include "qgspointlocator.h"
23 #include "qgis_gui.h"
24 
25 class QgsMapCanvas;
27 
35 class GUI_EXPORT QgsMapMouseEvent : public QMouseEvent
36 {
37 
38 #ifdef SIP_RUN
40  if ( dynamic_cast<QgsMapMouseEvent *>( sipCpp ) )
41  sipType = sipType_QgsMapMouseEvent;
42  else
43  sipType = 0;
44  SIP_END
45 #endif
46 
47  public:
48 
55  QgsMapMouseEvent( QgsMapCanvas *mapCanvas, QMouseEvent *event );
56 
67  QgsMapMouseEvent( QgsMapCanvas *mapCanvas, QEvent::Type type, QPoint pos, Qt::MouseButton button = Qt::NoButton,
68  Qt::MouseButtons buttons = Qt::NoButton, Qt::KeyboardModifiers modifiers = Qt::NoModifier );
69 
74  QgsPointXY snapPoint();
75 
82  bool isSnapped() const { return mSnapMatch.isValid(); }
83 
88  inline QgsPointXY mapPoint() const { return mMapPoint; }
89 
97  QgsPointLocator::Match mapPointMatch() const { return mSnapMatch; }
98 
105  void setMapPoint( const QgsPointXY &point );
106 
112  QgsPointXY originalMapPoint() const { return mMapPoint; }
113 
119  QPoint pixelPoint() const { return mPixelPoint; }
120 
127  QPoint originalPixelPoint() const { return pos(); }
128 
136  void snapToGrid( double precision, const QgsCoordinateReferenceSystem &crs );
137 
138  private:
139 
140  QPoint mapToPixelCoordinates( const QgsPointXY &point );
141 
143  bool mHasCachedSnapResult;
144 
146  QgsPointXY mOriginalMapPoint;
147 
149  QgsPointXY mMapPoint;
150 
155  QPoint mPixelPoint;
156 
158  QgsMapCanvas *mMapCanvas = nullptr;
159 
160  QgsPointLocator::Match mSnapMatch;
161 };
162 
163 #endif // QGSMAPMOUSEEVENT_H
QgsMapMouseEvent::mapPoint
QgsPointXY mapPoint() const
mapPoint returns the point in coordinates
Definition: qgsmapmouseevent.h:88
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsMapCanvas
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:85
QgsMapMouseEvent::pixelPoint
QPoint pixelPoint() const
The snapped mouse cursor in pixel coordinates.
Definition: qgsmapmouseevent.h:119
SIP_CONVERT_TO_SUBCLASS_CODE
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:177
precision
int precision
Definition: qgswfsgetfeature.cpp:49
QgsMapMouseEvent::mapPointMatch
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
Definition: qgsmapmouseevent.h:97
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsPointLocator::Match
Definition: qgspointlocator.h:185
QgsPointXY
A class to represent a 2D point.
Definition: qgspointxy.h:44
QgsMapMouseEvent
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
Definition: qgsmapmouseevent.h:36
qgspointlocator.h
QgsMapToolAdvancedDigitizing
The QgsMapToolAdvancedDigitizing class is a QgsMapTool which gives event directly in map coordinates ...
Definition: qgsmaptooladvanceddigitizing.h:37
SIP_END
#define SIP_END
Definition: qgis_sip.h:194
QgsMapMouseEvent::originalMapPoint
QgsPointXY originalMapPoint() const
Returns the original, unmodified map point of the mouse cursor.
Definition: qgsmapmouseevent.h:112
qgspointxy.h
QgsMapMouseEvent::isSnapped
bool isSnapped() const
Returns true if there is a snapped point cached.
Definition: qgsmapmouseevent.h:82
QgsMapMouseEvent::originalPixelPoint
QPoint originalPixelPoint() const
The unsnapped, real mouse cursor position in pixel coordinates.
Definition: qgsmapmouseevent.h:127