24 : QMouseEvent( event->type(), event->pos(), event->button(), event->buttons(), event->modifiers() )
25 , mHasCachedSnapResult( false )
26 , mOriginalMapPoint( mapCanvas ? mapCanvas->mapSettings().mapToPixel().toMapCoordinates( event->pos() ) :
QgsPointXY() )
27 , mMapPoint( mOriginalMapPoint )
28 , mPixelPoint( event->pos() )
29 , mMapCanvas( mapCanvas )
34 : QMouseEvent( type, pos, button, buttons, modifiers )
35 , mHasCachedSnapResult( false )
36 , mOriginalMapPoint( mapCanvas ? mapCanvas->mapSettings().mapToPixel().toMapCoordinates( pos ) :
QgsPointXY() )
37 , mMapPoint( mOriginalMapPoint )
39 , mMapCanvas( mapCanvas )
46 if ( mHasCachedSnapResult )
49 mHasCachedSnapResult =
true;
52 mSnapMatch = snappingUtils->
snapToMap( mMapPoint,
nullptr,
true );
56 mMapPoint = mSnapMatch.
point();
57 mPixelPoint = mapToPixelCoordinates( mMapPoint );
61 mMapPoint = mOriginalMapPoint;
71 mPixelPoint = mapToPixelCoordinates( point );
88 pt = ct.
transform( pt, Qgis::TransformDirection::Reverse );
98 QPoint QgsMapMouseEvent::mapToPixelCoordinates(
const QgsPointXY &point )
100 double x = point.
x(), y = point.
y();
104 return QPoint( std::round( x ), std::round( y ) );
This class represents a coordinate reference system (CRS).
Custom exception class for Coordinate Reference System related exceptions.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsSnappingUtils * snappingUtils() const
Returns snapping utility class that is associated with map canvas.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsMapMouseEvent(QgsMapCanvas *mapCanvas, QMouseEvent *event)
Creates a new QgsMapMouseEvent.
void setMapPoint(const QgsPointXY &point)
Set the (snapped) point this event points to in map coordinates.
void snapToGrid(double precision, const QgsCoordinateReferenceSystem &crs)
Snaps the mapPoint to a grid with the given precision.
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration
const QgsMapToPixel & mapToPixel() const
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
void transformInPlace(double &x, double &y) const
Transforms device coordinates to map coordinates.
A class to represent a 2D point.
void setX(double x) SIP_HOLDGIL
Sets the x value of the point.
void setY(double y) SIP_HOLDGIL
Sets the y value of the point.
This class has all the configuration of snapping and can return answers to snapping queries.
QgsPointLocator::Match snapToMap(QPoint point, QgsPointLocator::MatchFilter *filter=nullptr, bool relaxed=false)
Snap to map according to the current configuration.
const QgsCoordinateReferenceSystem & crs
QgsPointXY point() const
for vertex / edge match coords depending on what class returns it (geom.cache: layer coords,...