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 );
54 if ( mSnapMatch.isValid() )
56 mMapPoint = mSnapMatch.point();
57 mPixelPoint = mapToPixelCoordinates( mMapPoint );
61 mMapPoint = mOriginalMapPoint;
71 mPixelPoint = mapToPixelCoordinates( point );
81 const QgsCoordinateTransform ct( mMapCanvas->mapSettings().destinationCrs(), crs, mMapCanvas->mapSettings().transformContext() );
85 pt.
setX( std::round( pt.
x() / precision ) * precision );
86 pt.
setY( std::round( pt.
y() / precision ) * precision );
98QPoint QgsMapMouseEvent::mapToPixelCoordinates(
const QgsPointXY &point )
100 double x = point.
x(), y = point.
y();
104 return QPoint( std::round( x ), std::round( y ) );
@ Reverse
Reverse/inverse transform (from destination to source).
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.
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
void transformInPlace(double &x, double &y) const
Transforms map coordinates to device coordinates.
void setY(double y)
Sets the y value of the point.
void setX(double x)
Sets the x value of the point.
Contains 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.