QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
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
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
25class QgsMapCanvas;
27
35class GUI_EXPORT QgsMapMouseEvent : public QMouseEvent
36{
37#ifdef SIP_RUN
39 if ( dynamic_cast<QgsMapMouseEvent *>( sipCpp ) )
40 sipType = sipType_QgsMapMouseEvent;
41 else
42 sipType = 0;
44#endif
45
46 public:
53 QgsMapMouseEvent( QgsMapCanvas *mapCanvas, QMouseEvent *event );
54
65 QgsMapMouseEvent( QgsMapCanvas *mapCanvas, QEvent::Type type, QPoint pos, Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = Qt::NoButton, Qt::KeyboardModifiers modifiers = Qt::NoModifier );
66
71 QgsPointXY snapPoint();
72
79 bool isSnapped() const { return mSnapMatch.isValid(); }
80
85 inline QgsPointXY mapPoint() const { return mMapPoint; }
86
93 QgsPointLocator::Match mapPointMatch() const { return mSnapMatch; }
94
101 void setMapPoint( const QgsPointXY &point );
102
108 QgsPointXY originalMapPoint() const { return mMapPoint; }
109
115 QPoint pixelPoint() const { return mPixelPoint; }
116
123 QPoint originalPixelPoint() const { return pos(); }
124
132 void snapToGrid( double precision, const QgsCoordinateReferenceSystem &crs );
133
134 private:
135 QPoint mapToPixelCoordinates( const QgsPointXY &point );
136
138 bool mHasCachedSnapResult;
139
141 QgsPointXY mOriginalMapPoint;
142
144 QgsPointXY mMapPoint;
145
150 QPoint mPixelPoint;
151
153 QgsMapCanvas *mMapCanvas = nullptr;
154
155 QgsPointLocator::Match mSnapMatch;
156};
157
158#endif // QGSMAPMOUSEEVENT_H
This class represents a coordinate reference system (CRS).
Map canvas is a class for displaying all GIS data types on a canvas.
A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.
QPoint originalPixelPoint() const
The unsnapped, real mouse cursor position in pixel coordinates.
QgsPointXY originalMapPoint() const
Returns the original, unmodified map point of the mouse cursor.
bool isSnapped() const
Returns true if there is a snapped point cached.
QgsPointXY mapPoint() const
mapPoint returns the point in coordinates
QPoint pixelPoint() const
The snapped mouse cursor in pixel coordinates.
QgsPointLocator::Match mapPointMatch() const
Returns the matching data from the most recently snapped point.
The QgsMapToolAdvancedDigitizing class is a QgsMapTool which gives event directly in map coordinates ...
A class to represent a 2D point.
Definition qgspointxy.h:60
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:191
#define SIP_END
Definition qgis_sip.h:208
const QgsCoordinateReferenceSystem & crs
int precision