QGIS API Documentation 3.41.0-Master (3440c17df1d)
Loading...
Searching...
No Matches
Public Member Functions | List of all members
QgsMapMouseEvent Class Reference

A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas. More...

#include <qgsmapmouseevent.h>

Inheritance diagram for QgsMapMouseEvent:
Inheritance graph
[legend]

Public Member Functions

 QgsMapMouseEvent (QgsMapCanvas *mapCanvas, QEvent::Type type, QPoint pos, Qt::MouseButton button=Qt::NoButton, Qt::MouseButtons buttons=Qt::NoButton, Qt::KeyboardModifiers modifiers=Qt::NoModifier)
 Creates a new QgsMapMouseEvent.
 
 QgsMapMouseEvent (QgsMapCanvas *mapCanvas, QMouseEvent *event)
 Creates a new QgsMapMouseEvent.
 
bool isSnapped () const
 Returns true if there is a snapped point cached.
 
QgsPointXY mapPoint () const
 mapPoint returns the point in coordinates
 
QgsPointLocator::Match mapPointMatch () const
 Returns the matching data from the most recently snapped point.
 
QgsPointXY originalMapPoint () const
 Returns the original, unmodified map point of the mouse cursor.
 
QPoint originalPixelPoint () const
 The unsnapped, real mouse cursor position in pixel coordinates.
 
QPoint pixelPoint () const
 The snapped mouse cursor in pixel coordinates.
 
void setMapPoint (const QgsPointXY &point)
 Set the (snapped) point this event points to in map coordinates.
 
QgsPointXY snapPoint ()
 snapPoint will snap the points using the map canvas snapping utils configuration
 
void snapToGrid (double precision, const QgsCoordinateReferenceSystem &crs)
 Snaps the mapPoint to a grid with the given precision.
 

Detailed Description

A QgsMapMouseEvent is the result of a user interaction with the mouse on a QgsMapCanvas.

It is sent whenever the user moves, clicks, releases or double clicks the mouse. In addition to the coordinates in pixel space it also knows the coordinates in the mapcanvas' CRS as well as it knows the concept of snapping.

Definition at line 35 of file qgsmapmouseevent.h.

Constructor & Destructor Documentation

◆ QgsMapMouseEvent() [1/2]

QgsMapMouseEvent::QgsMapMouseEvent ( QgsMapCanvas mapCanvas,
QMouseEvent *  event 
)

Creates a new QgsMapMouseEvent.

Should only be required to be called from the QgsMapCanvas.

Parameters
mapCanvasThe map canvas on which the event occurred
eventThe original mouse event

Definition at line 23 of file qgsmapmouseevent.cpp.

◆ QgsMapMouseEvent() [2/2]

QgsMapMouseEvent::QgsMapMouseEvent ( QgsMapCanvas mapCanvas,
QEvent::Type  type,
QPoint  pos,
Qt::MouseButton  button = Qt::NoButton,
Qt::MouseButtons  buttons = Qt::NoButton,
Qt::KeyboardModifiers  modifiers = Qt::NoModifier 
)

Creates a new QgsMapMouseEvent.

Should only be required to be called from the QgsMapCanvas.

Parameters
mapCanvasThe map canvas on which the event occurred
typeThe type of the event
posThe pixel position of the mouse
buttonThe pressed button
buttonsFurther buttons that are pressed
modifiersKeyboard modifiers

Definition at line 33 of file qgsmapmouseevent.cpp.

Member Function Documentation

◆ isSnapped()

bool QgsMapMouseEvent::isSnapped ( ) const
inline

Returns true if there is a snapped point cached.

Will only be useful after snapPoint has previously been called.

Returns
true if there is a snapped point cached.

Definition at line 82 of file qgsmapmouseevent.h.

◆ mapPoint()

QgsPointXY QgsMapMouseEvent::mapPoint ( ) const
inline

mapPoint returns the point in coordinates

Returns
the point in map coordinates, after snapping if requested in the event.

Definition at line 88 of file qgsmapmouseevent.h.

◆ mapPointMatch()

QgsPointLocator::Match QgsMapMouseEvent::mapPointMatch ( ) const
inline

Returns the matching data from the most recently snapped point.

Returns
the snapping data structure
Note
This method returns the most recent snap match. It must follow a call to snapPoint() in order to have a recent snap result available.

Definition at line 96 of file qgsmapmouseevent.h.

◆ originalMapPoint()

QgsPointXY QgsMapMouseEvent::originalMapPoint ( ) const
inline

Returns the original, unmodified map point of the mouse cursor.

Returns
The cursor position in map coordinates.

Definition at line 111 of file qgsmapmouseevent.h.

◆ originalPixelPoint()

QPoint QgsMapMouseEvent::originalPixelPoint ( ) const
inline

The unsnapped, real mouse cursor position in pixel coordinates.

Alias to pos()

Returns
Mouse position in pixel coordinates

Definition at line 126 of file qgsmapmouseevent.h.

◆ pixelPoint()

QPoint QgsMapMouseEvent::pixelPoint ( ) const
inline

The snapped mouse cursor in pixel coordinates.

Returns
The snapped mouse cursor position in pixel coordinates.

Definition at line 118 of file qgsmapmouseevent.h.

◆ setMapPoint()

void QgsMapMouseEvent::setMapPoint ( const QgsPointXY point)

Set the (snapped) point this event points to in map coordinates.

The point in pixel coordinates will be calculated accordingly.

Parameters
pointThe point in map coordinates

Definition at line 68 of file qgsmapmouseevent.cpp.

◆ snapPoint()

QgsPointXY QgsMapMouseEvent::snapPoint ( )

snapPoint will snap the points using the map canvas snapping utils configuration

Note
if snapping did not succeeded, the map point will be reset to its original position

Definition at line 43 of file qgsmapmouseevent.cpp.

◆ snapToGrid()

void QgsMapMouseEvent::snapToGrid ( double  precision,
const QgsCoordinateReferenceSystem crs 
)

Snaps the mapPoint to a grid with the given precision.

The snapping will be done in the specified crs. If this crs is different from the mapCanvas crs, it will be reprojected on the fly.

Since
QGIS 3.4

Definition at line 74 of file qgsmapmouseevent.cpp.


The documentation for this class was generated from the following files: