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 );
56 mMapPoint = mSnapMatch.
point();
57 mPixelPoint = mapToPixelCoordinates( mMapPoint );
61 mMapPoint = mOriginalMapPoint;
71 mPixelPoint = mapToPixelCoordinates( point );
86 pt.setY( std::round( pt.y() /
precision ) * precision );
98 QPoint QgsMapMouseEvent::mapToPixelCoordinates(
const QgsPointXY &point )
100 double x = point.
x(), y = point.
y();
104 return QPoint( std::round( x ), std::round( y ) );
QgsPointXY point() const
for vertex / edge match coords depending on what class returns it (geom.cache: layer coords...
A class to represent a 2D point.
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
const QgsMapToPixel & mapToPixel() const
QgsMapMouseEvent(QgsMapCanvas *mapCanvas, QMouseEvent *event)
Creates a new QgsMapMouseEvent.
const QgsCoordinateReferenceSystem & crs
void setMapPoint(const QgsPointXY &point)
Set the (snapped) point this event points to in map coordinates.
Map canvas is a class for displaying all GIS data types on a canvas.
QgsCoordinateTransformContext transformContext() const
Returns the coordinate transform context, which stores various information regarding which datum tran...
QgsCoordinateReferenceSystem destinationCrs() const
returns CRS of destination coordinate reference system
void transformInPlace(double &x, double &y) const
Transform device coordinates to map coordinates.
QgsSnappingUtils * snappingUtils() const
Returns snapping utility class that is associated with map canvas.
void setX(double x)
Sets the x value of the point.
This class represents a coordinate reference system (CRS).
This class has all the configuration of snapping and can return answers to snapping queries...
void snapToGrid(double precision, const QgsCoordinateReferenceSystem &crs)
Snaps the mapPoint to a grid with the given precision.
Custom exception class for Coordinate Reference System related exceptions.
QgsPointLocator::Match snapToMap(QPoint point, QgsPointLocator::MatchFilter *filter=nullptr)
Snap to map according to the current configuration. Optional filter allows discarding unwanted matche...
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration