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 );
74 QPoint QgsMapMouseEvent::mapToPixelCoordinates(
const QgsPointXY &point )
76 double x = point.
x(), y = point.
y();
80 return QPoint( std::round( x ), std::round( y ) );
A class to represent a 2D point.
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.
Map canvas is a class for displaying all GIS data types on a canvas.
void transformInPlace(double &x, double &y) const
Transform device coordinates to map coordinates.
const QgsMapToPixel & mapToPixel() const
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsPointXY point() const
for vertex / edge match coords depending on what class returns it (geom.cache: layer coords...
This class has all the configuration of snapping and can return answers to snapping queries...
QgsPointLocator::Match snapToMap(QPoint point, QgsPointLocator::MatchFilter *filter=nullptr)
Snap to map according to the current configuration. Optional filter allows discarding unwanted matche...
QgsSnappingUtils * snappingUtils() const
Returns snapping utility class that is associated with map canvas.
QgsPointXY snapPoint()
snapPoint will snap the points using the map canvas snapping utils configuration